Skip to content

Commit d17939b

Browse files
committed
Update PCAN basic Python file to February 7, 2020
1 parent b27a61d commit d17939b

1 file changed

Lines changed: 52 additions & 4 deletions

File tree

can/interfaces/pcan/basic.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
PCAN-Basic API
33
44
Author: Keneth Wagner
5-
Last change: 13.11.2017 Wagner
5+
Last change: 02.07.2020 Wagner
66
77
Language: Python 2.7, 3.5
88
9-
Copyright (C) 1999-2017 PEAK-System Technik GmbH, Darmstadt, Germany
9+
Copyright (C) 1999-2020 PEAK-System Technik GmbH, Darmstadt, Germany
1010
http://www.peak-system.com
1111
"""
1212

@@ -157,6 +157,9 @@
157157
PCAN_ERROR_ILLPARAMVAL = TPCANStatus(0x08000) # Invalid parameter value
158158
PCAN_ERROR_UNKNOWN = TPCANStatus(0x10000) # Unknown error
159159
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
160163
PCAN_ERROR_CAUTION = TPCANStatus(
161164
0x2000000
162165
) # An operation was successfully carried out, however, irregularities were registered
@@ -183,7 +186,7 @@
183186
PCAN_LAN = TPCANDevice(0x08) # PCAN Gateway devices
184187

185188
# PCAN parameters
186-
PCAN_DEVICE_NUMBER = TPCANParameter(0x01) # PCAN-USB device number parameter
189+
PCAN_DEVICE_ID = TPCANParameter(0x01) # PCAN-USB device identifier parameter
187190
PCAN_5VOLTS_POWER = TPCANParameter(0x02) # PCAN-PC Card 5-Volt power parameter
188191
PCAN_RECEIVE_EVENT = TPCANParameter(0x03) # PCAN receive event handler parameter
189192
PCAN_MESSAGE_FILTER = TPCANParameter(0x04) # PCAN message filter parameter
@@ -263,6 +266,18 @@
263266
) # Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High
264267
PCAN_IO_DIGITAL_CLEAR = TPCANParameter(0x27) # Clear multiple digital I/O pins to 0
265268
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
266281

267282
# PCAN parameter values
268283
PCAN_PARAMETER_OFF = int(0x00) # The PCAN parameter is not set (inactive)
@@ -324,6 +339,14 @@
324339
SERVICE_STATUS_STOPPED = int(0x01) # The service is not running
325340
SERVICE_STATUS_RUNNING = int(0x04) # The service is running
326341

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+
327350
# PCAN message types
328351
PCAN_MESSAGE_STANDARD = TPCANMessageType(
329352
0x00
@@ -524,6 +547,22 @@ class TPCANMsgFDMac(Structure):
524547
] # Data of the message (DATA[0]..DATA[63])
525548

526549

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+
527566
# ///////////////////////////////////////////////////////////
528567
# PCAN-Basic API function declarations
529568
# ///////////////////////////////////////////////////////////
@@ -834,15 +873,24 @@ def GetValue(self, Channel, Parameter):
834873
PCAN_TRACE_LOCATION,
835874
PCAN_BITRATE_INFO_FD,
836875
PCAN_IP_ADDRESS,
876+
PCAN_FIRMWARE_VERSION,
837877
):
838878
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])()
839884
else:
840885
mybuffer = c_int(0)
841886

842887
res = self.__m_dllBasic.CAN_GetValue(
843888
Channel, Parameter, byref(mybuffer), sizeof(mybuffer)
844889
)
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
846894
except:
847895
logger.error("Exception on PCANBasic.GetValue")
848896
raise

0 commit comments

Comments
 (0)