|
2 | 2 | PCAN-Basic API |
3 | 3 |
|
4 | 4 | Author: Keneth Wagner |
5 | | -Last change: 13.11.2017 Wagner |
| 5 | +Last change: 02.07.2020 Wagner |
6 | 6 |
|
7 | 7 | Language: Python 2.7, 3.5 |
8 | 8 |
|
9 | | -Copyright (C) 1999-2017 PEAK-System Technik GmbH, Darmstadt, Germany |
| 9 | +Copyright (C) 1999-2020 PEAK-System Technik GmbH, Darmstadt, Germany |
10 | 10 | http://www.peak-system.com |
11 | 11 | """ |
12 | 12 |
|
|
157 | 157 | PCAN_ERROR_ILLPARAMVAL = TPCANStatus(0x08000) # Invalid parameter value |
158 | 158 | PCAN_ERROR_UNKNOWN = TPCANStatus(0x10000) # Unknown error |
159 | 159 | PCAN_ERROR_ILLDATA = TPCANStatus(0x20000) # Invalid data, function, or action |
| 160 | +PCAN_ERROR_ILLMODE = TPCANStatus( |
| 161 | + 0x80000 |
| 162 | +) # Driver object state is wrong for the attempted operation |
160 | 163 | PCAN_ERROR_CAUTION = TPCANStatus( |
161 | 164 | 0x2000000 |
162 | 165 | ) # An operation was successfully carried out, however, irregularities were registered |
|
183 | 186 | PCAN_LAN = TPCANDevice(0x08) # PCAN Gateway devices |
184 | 187 |
|
185 | 188 | # PCAN parameters |
186 | | -PCAN_DEVICE_NUMBER = TPCANParameter(0x01) # PCAN-USB device number parameter |
| 189 | +PCAN_DEVICE_ID = TPCANParameter(0x01) # PCAN-USB device identifier parameter |
187 | 190 | PCAN_5VOLTS_POWER = TPCANParameter(0x02) # PCAN-PC Card 5-Volt power parameter |
188 | 191 | PCAN_RECEIVE_EVENT = TPCANParameter(0x03) # PCAN receive event handler parameter |
189 | 192 | PCAN_MESSAGE_FILTER = TPCANParameter(0x04) # PCAN message filter parameter |
|
263 | 266 | ) # Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High |
264 | 267 | PCAN_IO_DIGITAL_CLEAR = TPCANParameter(0x27) # Clear multiple digital I/O pins to 0 |
265 | 268 | PCAN_IO_ANALOG_VALUE = TPCANParameter(0x28) # Get value of a single analog input pin |
| 269 | +PCAN_FIRMWARE_VERSION = TPCANParameter( |
| 270 | + 0x29 |
| 271 | +) # Get the version of the firmware used by the device associated with a PCAN-Channel |
| 272 | +PCAN_ATTACHED_CHANNELS_COUNT = TPCANParameter( |
| 273 | + 0x2A |
| 274 | +) # Get the amount of PCAN channels attached to a system |
| 275 | +PCAN_ATTACHED_CHANNELS = TPCANParameter( |
| 276 | + 0x2B |
| 277 | +) # Get information about PCAN channels attached to a system |
| 278 | + |
| 279 | +# DEPRECATED parameters |
| 280 | +PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID # DEPRECATED. Use PCAN_DEVICE_ID instead |
266 | 281 |
|
267 | 282 | # PCAN parameter values |
268 | 283 | PCAN_PARAMETER_OFF = int(0x00) # The PCAN parameter is not set (inactive) |
|
324 | 339 | SERVICE_STATUS_STOPPED = int(0x01) # The service is not running |
325 | 340 | SERVICE_STATUS_RUNNING = int(0x04) # The service is running |
326 | 341 |
|
| 342 | +# Other constants |
| 343 | +MAX_LENGTH_HARDWARE_NAME = int( |
| 344 | + 33 |
| 345 | +) # Maximum length of the name of a device: 32 characters + terminator |
| 346 | +MAX_LENGTH_VERSION_STRING = int( |
| 347 | + 18 |
| 348 | +) # Maximum length of a version string: 17 characters + terminator |
| 349 | + |
327 | 350 | # PCAN message types |
328 | 351 | PCAN_MESSAGE_STANDARD = TPCANMessageType( |
329 | 352 | 0x00 |
@@ -524,6 +547,22 @@ class TPCANMsgFDMac(Structure): |
524 | 547 | ] # Data of the message (DATA[0]..DATA[63]) |
525 | 548 |
|
526 | 549 |
|
| 550 | +class TPCANChannelInformation(Structure): |
| 551 | + """ |
| 552 | + Describes an available PCAN channel |
| 553 | + """ |
| 554 | + |
| 555 | + _fields_ = [ |
| 556 | + ("channel_handle", TPCANHandle), # PCAN channel handle |
| 557 | + ("device_type", TPCANDevice), # Kind of PCAN device |
| 558 | + ("controller_number", c_ubyte), # CAN-Controller number |
| 559 | + ("device_features", c_uint), # Device capabilities flag (see FEATURE_*) |
| 560 | + ("device_name", c_char * MAX_LENGTH_HARDWARE_NAME), # Device name |
| 561 | + ("device_id", c_uint), # Device number |
| 562 | + ("channel_condition", c_uint), |
| 563 | + ] # Availability status of a PCAN-Channel |
| 564 | + |
| 565 | + |
527 | 566 | # /////////////////////////////////////////////////////////// |
528 | 567 | # PCAN-Basic API function declarations |
529 | 568 | # /////////////////////////////////////////////////////////// |
@@ -834,15 +873,24 @@ def GetValue(self, Channel, Parameter): |
834 | 873 | PCAN_TRACE_LOCATION, |
835 | 874 | PCAN_BITRATE_INFO_FD, |
836 | 875 | PCAN_IP_ADDRESS, |
| 876 | + PCAN_FIRMWARE_VERSION, |
837 | 877 | ): |
838 | 878 | mybuffer = create_string_buffer(256) |
| 879 | + elif Parameter == PCAN_ATTACHED_CHANNELS: |
| 880 | + res = self.GetValue(Channel, PCAN_ATTACHED_CHANNELS_COUNT) |
| 881 | + if TPCANStatus(res[0]) != PCAN_ERROR_OK: |
| 882 | + return (TPCANStatus(res[0]),) |
| 883 | + mybuffer = (TPCANChannelInformation * res[1])() |
839 | 884 | else: |
840 | 885 | mybuffer = c_int(0) |
841 | 886 |
|
842 | 887 | res = self.__m_dllBasic.CAN_GetValue( |
843 | 888 | Channel, Parameter, byref(mybuffer), sizeof(mybuffer) |
844 | 889 | ) |
845 | | - return TPCANStatus(res), mybuffer.value |
| 890 | + if Parameter == PCAN_ATTACHED_CHANNELS: |
| 891 | + return TPCANStatus(res), mybuffer |
| 892 | + else: |
| 893 | + return TPCANStatus(res), mybuffer.value |
846 | 894 | except: |
847 | 895 | logger.error("Exception on PCANBasic.GetValue") |
848 | 896 | raise |
|
0 commit comments