Cleanup répertoire
This commit is contained in:
@@ -0,0 +1,543 @@
|
||||
Attribute VB_Name = "PCANBasic"
|
||||
' PCANBasic.bas
|
||||
'
|
||||
' ~~~~~~~~~~~~
|
||||
'
|
||||
' PCAN-Basic API
|
||||
'
|
||||
' ~~~~~~~~~~~~
|
||||
'
|
||||
' ------------------------------------------------------------------
|
||||
' Author : Keneth Wagner
|
||||
' Last change: 2022-07-06
|
||||
'
|
||||
' Language: Visual Basic 6.0
|
||||
' ------------------------------------------------------------------
|
||||
'
|
||||
' Copyright (C) 1999-2022 PEAK-System Technik GmbH, Darmstadt
|
||||
' more Info at http://www.peak-system.com
|
||||
'
|
||||
|
||||
'///////////////////////////////////////////////////////////
|
||||
'/ Value definitions
|
||||
'///////////////////////////////////////////////////////////
|
||||
|
||||
' Currently defined and supported PCAN channels
|
||||
'
|
||||
Public Const PCAN_NONEBUS As Long = &H0 ' Undefined/default value for a PCAN bus
|
||||
|
||||
Public Const PCAN_ISABUS1 As Long = &H21 ' PCAN-ISA interface, channel 1
|
||||
Public Const PCAN_ISABUS2 As Long = &H22 ' PCAN-ISA interface, channel 2
|
||||
Public Const PCAN_ISABUS3 As Long = &H23 ' PCAN-ISA interface, channel 3
|
||||
Public Const PCAN_ISABUS4 As Long = &H24 ' PCAN-ISA interface, channel 4
|
||||
Public Const PCAN_ISABUS5 As Long = &H25 ' PCAN-ISA interface, channel 5
|
||||
Public Const PCAN_ISABUS6 As Long = &H26 ' PCAN-ISA interface, channel 6
|
||||
Public Const PCAN_ISABUS7 As Long = &H27 ' PCAN-ISA interface, channel 7
|
||||
Public Const PCAN_ISABUS8 As Long = &H28 ' PCAN-ISA interface, channel 8
|
||||
|
||||
Public Const PCAN_DNGBUS1 As Long = &H31 ' PCAN-Dongle/LPT interface, channel 1
|
||||
|
||||
Public Const PCAN_PCIBUS1 As Long = &H41 ' PCAN-PCI interface, channel 1
|
||||
Public Const PCAN_PCIBUS2 As Long = &H42 ' PCAN-PCI interface, channel 2
|
||||
Public Const PCAN_PCIBUS3 As Long = &H43 ' PCAN-PCI interface, channel 3
|
||||
Public Const PCAN_PCIBUS4 As Long = &H44 ' PCAN-PCI interface, channel 4
|
||||
Public Const PCAN_PCIBUS5 As Long = &H45 ' PCAN-PCI interface, channel 5
|
||||
Public Const PCAN_PCIBUS6 As Long = &H46 ' PCAN-PCI interface, channel 6
|
||||
Public Const PCAN_PCIBUS7 As Long = &H47 ' PCAN-PCI interface, channel 7
|
||||
Public Const PCAN_PCIBUS8 As Long = &H48 ' PCAN-PCI interface, channel 8
|
||||
Public Const PCAN_PCIBUS9 As Long = &H409 ' PCAN-PCI interface, channel 9
|
||||
Public Const PCAN_PCIBUS10 As Long = &H40A ' PCAN-PCI interface, channel 10
|
||||
Public Const PCAN_PCIBUS11 As Long = &H40B ' PCAN-PCI interface, channel 11
|
||||
Public Const PCAN_PCIBUS12 As Long = &H40C ' PCAN-PCI interface, channel 12
|
||||
Public Const PCAN_PCIBUS13 As Long = &H40D ' PCAN-PCI interface, channel 13
|
||||
Public Const PCAN_PCIBUS14 As Long = &H40E ' PCAN-PCI interface, channel 14
|
||||
Public Const PCAN_PCIBUS15 As Long = &H40F ' PCAN-PCI interface, channel 15
|
||||
Public Const PCAN_PCIBUS16 As Long = &H410 ' PCAN-PCI interface, channel 16
|
||||
|
||||
Public Const PCAN_USBBUS1 As Long = &H51 ' PCAN-USB interface, channel 1
|
||||
Public Const PCAN_USBBUS2 As Long = &H52 ' PCAN-USB interface, channel 2
|
||||
Public Const PCAN_USBBUS3 As Long = &H53 ' PCAN-USB interface, channel 3
|
||||
Public Const PCAN_USBBUS4 As Long = &H54 ' PCAN-USB interface, channel 4
|
||||
Public Const PCAN_USBBUS5 As Long = &H55 ' PCAN-USB interface, channel 5
|
||||
Public Const PCAN_USBBUS6 As Long = &H56 ' PCAN-USB interface, channel 6
|
||||
Public Const PCAN_USBBUS7 As Long = &H57 ' PCAN-USB interface, channel 7
|
||||
Public Const PCAN_USBBUS8 As Long = &H58 ' PCAN-USB interface, channel 8
|
||||
Public Const PCAN_USBBUS9 As Long = &H509 ' PCAN-USB interface, channel 9
|
||||
Public Const PCAN_USBBUS10 As Long = &H50A ' PCAN-USB interface, channel 10
|
||||
Public Const PCAN_USBBUS11 As Long = &H50B ' PCAN-USB interface, channel 11
|
||||
Public Const PCAN_USBBUS12 As Long = &H50C ' PCAN-USB interface, channel 12
|
||||
Public Const PCAN_USBBUS13 As Long = &H50D ' PCAN-USB interface, channel 13
|
||||
Public Const PCAN_USBBUS14 As Long = &H50E ' PCAN-USB interface, channel 14
|
||||
Public Const PCAN_USBBUS15 As Long = &H50F ' PCAN-USB interface, channel 15
|
||||
Public Const PCAN_USBBUS16 As Long = &H510 ' PCAN-USB interface, channel 16
|
||||
|
||||
Public Const PCAN_PCCBUS1 As Long = &H61 ' PCAN-PC Card interface, channel 1
|
||||
Public Const PCAN_PCCBUS2 As Long = &H62 ' PCAN-PC Card interface, channel 2
|
||||
|
||||
Public Const PCAN_LANBUS1 As Long = &H801 ' PCAN-LAN interface, channel 1
|
||||
Public Const PCAN_LANBUS2 As Long = &H802 ' PCAN-LAN interface, channel 2
|
||||
Public Const PCAN_LANBUS3 As Long = &H803 ' PCAN-LAN interface, channel 3
|
||||
Public Const PCAN_LANBUS4 As Long = &H804 ' PCAN-LAN interface, channel 4
|
||||
Public Const PCAN_LANBUS5 As Long = &H805 ' PCAN-LAN interface, channel 5
|
||||
Public Const PCAN_LANBUS6 As Long = &H806 ' PCAN-LAN interface, channel 6
|
||||
Public Const PCAN_LANBUS7 As Long = &H807 ' PCAN-LAN interface, channel 7
|
||||
Public Const PCAN_LANBUS8 As Long = &H808 ' PCAN-LAN interface, channel 8
|
||||
Public Const PCAN_LANBUS9 As Long = &H809 ' PCAN-LAN interface, channel 9
|
||||
Public Const PCAN_LANBUS10 As Long = &H80A ' PCAN-LAN interface, channel 10
|
||||
Public Const PCAN_LANBUS11 As Long = &H80B ' PCAN-LAN interface, channel 11
|
||||
Public Const PCAN_LANBUS12 As Long = &H80C ' PCAN-LAN interface, channel 12
|
||||
Public Const PCAN_LANBUS13 As Long = &H80D ' PCAN-LAN interface, channel 13
|
||||
Public Const PCAN_LANBUS14 As Long = &H80E ' PCAN-LAN interface, channel 14
|
||||
Public Const PCAN_LANBUS15 As Long = &H80F ' PCAN-LAN interface, channel 15
|
||||
Public Const PCAN_LANBUS16 As Long = &H810 ' PCAN-LAN interface, channel 16
|
||||
|
||||
' Represent the PCAN error and status codes
|
||||
'
|
||||
Public Const PCAN_ERROR_OK As Long = &H0 ' No error
|
||||
Public Const PCAN_ERROR_XMTFULL As Long = &H1 ' Transmit buffer in CAN controller is full
|
||||
Public Const PCAN_ERROR_OVERRUN As Long = &H2 ' CAN controller was read too late
|
||||
Public Const PCAN_ERROR_BUSLIGHT As Long = &H4 ' Bus error: an error counter reached the 'light' limit [Not used with the *FD functions]
|
||||
Public Const PCAN_ERROR_BUSHEAVY As Long = &H8 ' Bus error: an error counter reached the 'heavy' limit
|
||||
Public Const PCAN_ERROR_BUSWARNING = PCAN_ERROR_BUSHEAVY ' An error counter reached the 'warning' limit [ONLY used with the *FD functions]
|
||||
Public Const PCAN_ERROR_BUSPASSIVE As Long = &H40000 ' Bus error: the CAN controller is in bus-off state
|
||||
Public Const PCAN_ERROR_BUSOFF As Long = &H10 ' Bus error: the CAN controller is in bus-off state
|
||||
Public Const PCAN_ERROR_ANYBUSERR = (PCAN_ERROR_BUSWARNING Or PCAN_ERROR_BUSLIGHT Or PCAN_ERROR_BUSHEAVY Or PCAN_ERROR_BUSOFF Or PCAN_ERROR_BUSPASSIVE) ' Mask for all bus errors
|
||||
Public Const PCAN_ERROR_QRCVEMPTY As Long = &H20 ' Receive queue is empty
|
||||
Public Const PCAN_ERROR_QOVERRUN As Long = &H40 ' Receive queue was read too late
|
||||
Public Const PCAN_ERROR_QXMTFULL As Long = &H80 ' Transmit queue is full
|
||||
Public Const PCAN_ERROR_REGTEST As Long = &H100 ' Test of the CAN controller hardware registers failed (no hardware found)
|
||||
Public Const PCAN_ERROR_NODRIVER As Long = &H200 ' Driver not loaded
|
||||
Public Const PCAN_ERROR_HWINUSE As Long = &H400 ' Hardware already in use by a Net
|
||||
Public Const PCAN_ERROR_NETINUSE As Long = &H800 ' A Client is already connected to the Net
|
||||
Public Const PCAN_ERROR_ILLHW As Long = &H1400 ' Hardware handle is invalid
|
||||
Public Const PCAN_ERROR_ILLNET As Long = &H1800 ' Net handle is invalid
|
||||
Public Const PCAN_ERROR_ILLCLIENT As Long = &H1C00 ' Client handle is invalid
|
||||
Public Const PCAN_ERROR_ILLHANDLE = (PCAN_ERROR_ILLHW Or PCAN_ERROR_ILLNET Or PCAN_ERROR_ILLCLIENT) ' Mask for all handle errors
|
||||
Public Const PCAN_ERROR_RESOURCE As Long = &H2000 ' Resource (FIFO, Client, timeout) cannot be created
|
||||
Public Const PCAN_ERROR_ILLPARAMTYPE As Long = &H4000 ' Invalid parameter
|
||||
Public Const PCAN_ERROR_ILLPARAMVAL As Long = &H8000 ' Invalid parameter value
|
||||
Public Const PCAN_ERROR_UNKNOWN As Long = &H10000 ' Unknown error
|
||||
Public Const PCAN_ERROR_ILLDATA As Long = &H20000 ' Invalid data, function, or action
|
||||
Public Const PCAN_ERROR_ILLMODE As Long = &H80000 ' Driver object state is wrong for the attempted operation
|
||||
Public Const PCAN_ERROR_CAUTION As Long = &H2000000 ' An operation was successfully carried out, however, irregularities were registered
|
||||
Public Const PCAN_ERROR_INITIALIZE As Long = &H4000000 ' Channel is not initialized [Value was changed from &H40000 to &H4000000]
|
||||
Public Const PCAN_ERROR_ILLOPERATION As Long = &H8000000 ' Invalid operation [Value was changed from &H80000 to &H8000000]
|
||||
|
||||
' PCAN devices
|
||||
'
|
||||
Public Const PCAN_NONE = &H0 ' Undefined, unknown or not selected PCAN device value
|
||||
Public Const PCAN_PEAKCAN = &H1 ' PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API
|
||||
Public Const PCAN_ISA = &H2 ' PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
|
||||
Public Const PCAN_DNG = &H3 ' PCAN-Dongle
|
||||
Public Const PCAN_PCI = &H4 ' PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
|
||||
Public Const PCAN_USB = &H5 ' PCAN-USB and PCAN-USB Pro
|
||||
Public Const PCAN_PCC = &H6 ' PCAN-PC Card
|
||||
Public Const PCAN_VIRTUAL = &H7 ' PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API
|
||||
Public Const PCAN_LAN = &H8 ' PCAN Gateway devices
|
||||
|
||||
' PCAN parameters
|
||||
'
|
||||
Public Const PCAN_DEVICE_ID = &H1 ' Device identifier parameter
|
||||
Public Const PCAN_5VOLTS_POWER = &H2 ' 5-Volt power parameter
|
||||
Public Const PCAN_RECEIVE_EVENT = &H3 ' PCAN receive event handler parameter
|
||||
Public Const PCAN_MESSAGE_FILTER = &H4 ' PCAN message filter parameter
|
||||
Public Const PCAN_API_VERSION = &H5 ' PCAN-Basic API version parameter
|
||||
Public Const PCAN_CHANNEL_VERSION = &H6 ' PCAN device channel version parameter
|
||||
Public Const PCAN_BUSOFF_AUTORESET = &H7 ' PCAN Reset-On-Busoff parameter
|
||||
Public Const PCAN_LISTEN_ONLY = &H8 ' PCAN Listen-Only parameter
|
||||
Public Const PCAN_LOG_LOCATION = &H9 ' Directory path for log files
|
||||
Public Const PCAN_LOG_STATUS = &HA ' Debug-Log activation status
|
||||
Public Const PCAN_LOG_CONFIGURE = &HB ' Configuration of the debugged information (LOG_FUNCTION_***)
|
||||
Public Const PCAN_LOG_TEXT = &HC ' Custom insertion of text into the log file
|
||||
Public Const PCAN_CHANNEL_CONDITION = &HD ' Availability status of a PCAN-Channel
|
||||
Public Const PCAN_HARDWARE_NAME = &HE ' PCAN hardware name parameter
|
||||
Public Const PCAN_RECEIVE_STATUS = &HF ' Message reception status of a PCAN-Channel
|
||||
Public Const PCAN_CONTROLLER_NUMBER = &H10 ' CAN-Controller number of a PCAN-Channel
|
||||
Public Const PCAN_TRACE_LOCATION = &H11 ' Directory path for PCAN trace files
|
||||
Public Const PCAN_TRACE_STATUS = &H12 ' CAN tracing activation status
|
||||
Public Const PCAN_TRACE_SIZE = &H13 ' Configuration of the maximum file size of a CAN trace.
|
||||
Public Const PCAN_TRACE_CONFIGURE = &H14 ' Configuration of the trace file storing mode (TRACE_FILE_***)
|
||||
Public Const PCAN_CHANNEL_IDENTIFYING = &H15 ' Physical identification of a USB based PCAN-Channel by blinking its associated LED
|
||||
Public Const PCAN_CHANNEL_FEATURES = &H16 ' Capabilities of a PCAN device (FEATURE_***)
|
||||
Public Const PCAN_BITRATE_ADAPTING = &H17 ' Using of an existing bit rate (PCAN-View connected to a channel)
|
||||
Public Const PCAN_BITRATE_INFO = &H18 ' Configured bit rate as Btr0Btr1 value
|
||||
Public Const PCAN_BITRATE_INFO_FD = &H19 ' Configured bit rate as TPCANBitrateFD string
|
||||
Public Const PCAN_BUSSPEED_NOMINAL = &H1A ' Configured nominal CAN Bus speed as Bits per seconds
|
||||
Public Const PCAN_BUSSPEED_DATA = &H1B ' Configured CAN data speed as Bits per seconds
|
||||
Public Const PCAN_IP_ADDRESS = &H1C ' Remote address of a LAN channel as string in IPv4 format
|
||||
Public Const PCAN_LAN_SERVICE_STATUS = &H1D ' Status of the Virtual PCAN-Gateway Service
|
||||
Public Const PCAN_ALLOW_STATUS_FRAMES = &H1E ' Status messages reception status within a PCAN-Channel
|
||||
Public Const PCAN_ALLOW_RTR_FRAMES = &H1F ' RTR messages reception status within a PCAN-Channel
|
||||
Public Const PCAN_ALLOW_ERROR_FRAMES = &H20 ' Error messages reception status within a PCAN-Channel
|
||||
Public Const PCAN_INTERFRAME_DELAY = &H21 ' Delay, in microseconds, between sending frames
|
||||
Public Const PCAN_ACCEPTANCE_FILTER_11BIT = &H22 ' Filter over code and mask patterns for 11-Bit messages
|
||||
Public Const PCAN_ACCEPTANCE_FILTER_29BIT = &H23 ' Filter over code and mask patterns for 29-Bit messages
|
||||
Public Const PCAN_IO_DIGITAL_CONFIGURATION = &H24 ' Output mode Of 32 digital I/O pin Of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive
|
||||
Public Const PCAN_IO_DIGITAL_VALUE = &H25 ' Value assigned To a 32 digital I/O pins Of a PCAN-USB Chip
|
||||
Public Const PCAN_IO_DIGITAL_SET = &H26 ' Value assigned To a 32 digital I/O pins Of a PCAN-USB Chip - Multiple digital I/O pins To 1 = High
|
||||
Public Const PCAN_IO_DIGITAL_CLEAR = &H27 ' Clear multiple digital I/O pins To 0
|
||||
Public Const PCAN_IO_ANALOG_VALUE = &H28 ' Get value Of a Single analog input pin
|
||||
Public Const PCAN_FIRMWARE_VERSION = &H29 ' Get the version of the firmware used by the device associated With a PCAN-Channel
|
||||
Public Const PCAN_ATTACHED_CHANNELS_COUNT = &H2A ' Get the amount of PCAN channels attached to a system
|
||||
Public Const PCAN_ATTACHED_CHANNELS = &H2B ' Get information about PCAN channels attached to a system
|
||||
Public Const PCAN_ALLOW_ECHO_FRAMES = &H2C ' Echo messages reception status within a PCAN-Channel
|
||||
Public Const PCAN_DEVICE_PART_NUMBER = &H2D ' Get the part number associated To a device
|
||||
|
||||
' DEPRECATED parameters
|
||||
'
|
||||
Public Const PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID ' Deprecated parameter. Use PCAN_DEVICE_ID instead
|
||||
|
||||
' PCAN parameter values
|
||||
'
|
||||
Public Const PCAN_PARAMETER_OFF = &H0 ' The PCAN parameter is not set (inactive)
|
||||
Public Const PCAN_PARAMETER_ON = &H1 ' The PCAN parameter is set (active)
|
||||
Public Const PCAN_FILTER_CLOSE = &H0 ' The PCAN filter is closed. No messages will be received
|
||||
Public Const PCAN_FILTER_OPEN = &H1 ' The PCAN filter is fully opened. All messages will be received
|
||||
Public Const PCAN_FILTER_CUSTOM = &H2 ' The PCAN filter is custom configured. Only registered messages will be received
|
||||
Public Const PCAN_CHANNEL_UNAVAILABLE = &H0 ' The PCAN-Channel handle is illegal, or its associated hardware is not available
|
||||
Public Const PCAN_CHANNEL_AVAILABLE = &H1 ' The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in)
|
||||
Public Const PCAN_CHANNEL_OCCUPIED = &H2 ' The PCAN-Channel handle is valid, and is already being used
|
||||
Public Const PCAN_CHANNEL_PCANVIEW = (PCAN_CHANNEL_AVAILABLE Or PCAN_CHANNEL_OCCUPIED) ' The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect
|
||||
|
||||
Public Const LOG_FUNCTION_DEFAULT = &H0 ' Logs system exceptions / errors
|
||||
Public Const LOG_FUNCTION_ENTRY = &H1 ' Logs the entries to the PCAN-Basic API functions
|
||||
Public Const LOG_FUNCTION_PARAMETERS = &H2 ' Logs the parameters passed to the PCAN-Basic API functions
|
||||
Public Const LOG_FUNCTION_LEAVE = &H4 ' Logs the exits from the PCAN-Basic API functions
|
||||
Public Const LOG_FUNCTION_WRITE = &H8 ' Logs the CAN messages passed to the CAN_Write function
|
||||
Public Const LOG_FUNCTION_READ = &H10 ' Logs the CAN messages received within the CAN_Read function
|
||||
Public Const LOG_FUNCTION_ALL = &HFFFF ' Logs all possible information within the PCAN-Basic API functions
|
||||
|
||||
Public Const TRACE_FILE_SINGLE = &H0 ' A single file is written until it size reaches PAN_TRACE_SIZE.
|
||||
Public Const TRACE_FILE_SEGMENTED = &H1 ' Traced data is distributed in several files with size PAN_TRACE_SIZE.
|
||||
Public Const TRACE_FILE_DATE = &H2 ' Includes the date into the name of the trace file.
|
||||
Public Const TRACE_FILE_TIME = &H4 ' Includes the start time into the name of the trace file.
|
||||
Public Const TRACE_FILE_OVERWRITE = &H80 ' Causes the overwriting of available traces (same name).
|
||||
|
||||
Public Const FEATURE_FD_CAPABLE = &H1 ' Device supports flexible data-rate (CAN-FD)
|
||||
Public Const FEATURE_DELAY_CAPABLE = &H2 ' Device supports a delay between sending frames (FPGA based USB devices)
|
||||
Public Const FEATURE_IO_CAPABLE = &H4 ' Device supports I/O functionality for electronic circuits (USB-Chip devices)
|
||||
|
||||
Public Const SERVICE_STATUS_STOPPED = &H1 ' The service is not running
|
||||
Public Const SERVICE_STATUS_RUNNING = &H4 ' The service is running
|
||||
|
||||
' Other constants
|
||||
'
|
||||
Public Const MAX_LENGTH_HARDWARE_NAME = 33 ' Maximum length of the name of a device: 32 characters + terminator
|
||||
Public Const MAX_LENGTH_VERSION_STRING = 256 ' Maximum length of a version string: 255 characters + terminator
|
||||
|
||||
' PCAN message types
|
||||
'
|
||||
Public Const PCAN_MESSAGE_STANDARD = &H0 ' The PCAN message is a CAN Standard Frame (11-bit identifier)
|
||||
Public Const PCAN_MESSAGE_RTR = &H1 ' The PCAN message is a CAN Remote-Transfer-Request Frame
|
||||
Public Const PCAN_MESSAGE_EXTENDED = &H2 ' The PCAN message is a CAN Extended Frame (29-bit identifier)
|
||||
Public Const PCAN_MESSAGE_FD = &H4 ' The PCAN message represents a FD frame in terms of CiA Specs
|
||||
Public Const PCAN_MESSAGE_BRS = &H8 ' The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate)
|
||||
Public Const PCAN_MESSAGE_ESI = &H10 ' The PCAN message represents a FD error state indicator(CAN FD transmitter was error active)
|
||||
Public Const PCAN_MESSAGE_ECHO = &H20 ' The PCAN message represents an echo CAN Frame
|
||||
Public Const PCAN_MESSAGE_ERRFRAME = &H40 ' The PCAN message represents an error frame
|
||||
Public Const PCAN_MESSAGE_STATUS = &H80 ' The PCAN message represents a PCAN status message
|
||||
|
||||
' LookUp Parameters
|
||||
'
|
||||
Public Const LOOKUP_DEVICE_TYPE As String = "devicetype" ' Lookup channel by Device type (see PCAN devices e.g. PCAN_USB)
|
||||
Public Const LOOKUP_DEVICE_ID As String = "deviceid" ' Lookup channel by device id
|
||||
Public Const LOOKUP_CONTROLLER_NUMBER As String = "controllernumber" ' Lookup channel by CAN controller 0-based index
|
||||
Public Const LOOKUP_IP_ADDRESS As String = "ipaddress" ' Lookup channel by IP address (LAN channels only)
|
||||
|
||||
' Frame Type / Initialization Mode
|
||||
'
|
||||
Public Const PCAN_MODE_STANDARD = PCAN_MESSAGE_STANDARD
|
||||
Public Const PCAN_MODE_EXTENDED = PCAN_MESSAGE_EXTENDED
|
||||
|
||||
' Baud rate codes = BTR0/BTR1 register values for the CAN controller.
|
||||
' You can define your own Baud rate with the BTROBTR1 register.
|
||||
' Take a look at www.peak-system.com for our free software "BAUDTOOL"
|
||||
' to calculate the BTROBTR1 register for every bit rate and sample point.
|
||||
'
|
||||
Public Const PCAN_BAUD_1M = &H14 ' 1 MBit/s
|
||||
Public Const PCAN_BAUD_800K = &H16 ' 800 kBit/s
|
||||
Public Const PCAN_BAUD_500K = &H1C ' 500 kBit/s
|
||||
Public Const PCAN_BAUD_250K = &H11C ' 250 kBit/s
|
||||
Public Const PCAN_BAUD_125K = &H31C ' 125 kBit/s
|
||||
Public Const PCAN_BAUD_100K = &H432F ' 100 kBit/s
|
||||
Public Const PCAN_BAUD_95K = &HC34E ' 95,238 kBit/s
|
||||
Public Const PCAN_BAUD_83K = &H852B ' 83,333 kBit/s
|
||||
Public Const PCAN_BAUD_50K = &H472F ' 50 kBit/s
|
||||
Public Const PCAN_BAUD_47K = &H1414 ' 47,619 kBit/s
|
||||
Public Const PCAN_BAUD_33K = &H8B2F ' 33,333 kBit/s
|
||||
Public Const PCAN_BAUD_20K = &H532F ' 20 kBit/s
|
||||
Public Const PCAN_BAUD_10K = &H672F ' 10 kBit/s
|
||||
Public Const PCAN_BAUD_5K = &H7F7F ' 5 kBit/s
|
||||
|
||||
' Represents the configuration for a CAN bit rate
|
||||
' Note:
|
||||
' * Each parameter and its value must be separated with a '='.
|
||||
' * Each pair of parameter/value must be separated using ','.
|
||||
'
|
||||
' Example:
|
||||
' f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1
|
||||
'
|
||||
Public Const PCAN_BR_CLOCK As String = "f_clock"
|
||||
Public Const PCAN_BR_CLOCK_MHZ As String = "f_clock_mhz"
|
||||
Public Const PCAN_BR_NOM_BRP As String = "nom_brp"
|
||||
Public Const PCAN_BR_NOM_TSEG1 As String = "nom_tseg1"
|
||||
Public Const PCAN_BR_NOM_TSEG2 As String = "nom_tseg2"
|
||||
Public Const PCAN_BR_NOM_SJW As String = "nom_sjw"
|
||||
Public Const PCAN_BR_NOM_SAMPLE As String = "nom_sam"
|
||||
Public Const PCAN_BR_DATA_BRP As String = "data_brp"
|
||||
Public Const PCAN_BR_DATA_TSEG1 As String = "data_tseg1"
|
||||
Public Const PCAN_BR_DATA_TSEG2 As String = "data_tseg2"
|
||||
Public Const PCAN_BR_DATA_SJW As String = "data_sjw"
|
||||
Public Const PCAN_BR_DATA_SAMPLE As String = "data_ssp_offset"
|
||||
|
||||
' Type of PCAN (Non-PnP) hardware
|
||||
'
|
||||
Public Const PCAN_TYPE_ISA = &H1 ' PCAN-ISA 82C200
|
||||
Public Const PCAN_TYPE_ISA_SJA = &H9 ' PCAN-ISA SJA1000
|
||||
Public Const PCAN_TYPE_ISA_PHYTEC = &H4 ' PHYTEC ISA
|
||||
Public Const PCAN_TYPE_DNG = &H2 ' PCAN-Dongle 82C200
|
||||
Public Const PCAN_TYPE_DNG_EPP = &H3 ' PCAN-Dongle EPP 82C200
|
||||
Public Const PCAN_TYPE_DNG_SJA = &H5 ' PCAN-Dongle SJA1000
|
||||
Public Const PCAN_TYPE_DNG_SJA_EPP = &H6 ' PCAN-Dongle EPP SJA1000
|
||||
|
||||
' Represents a PCAN message
|
||||
'
|
||||
Public Type TPCANMsg
|
||||
ID As Long ' 11/29-bit message identifier
|
||||
MsgType As Byte ' Type of the message
|
||||
LEN As Byte ' Data Length Code of the message (0..8)
|
||||
DATA(7) As Byte ' Data of the message (DATA[0]..DATA[7])
|
||||
End Type
|
||||
|
||||
' Represents a timestamp of a received PCAN message
|
||||
' Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
|
||||
'
|
||||
Public Type TPCANTimestamp
|
||||
millis As Long ' base-value: milliseconds: 0.. 2^32-1
|
||||
millis_overflow As Integer ' roll-arounds of millis
|
||||
micros As Integer ' microseconds: 0..999
|
||||
End Type
|
||||
|
||||
' Represents a PCAN message from a FD capable hardware
|
||||
'
|
||||
Public Type TPCANMsgFD
|
||||
ID As Long ' 11/29-bit message identifier
|
||||
MsgType As Byte ' Type of the message
|
||||
DLC As Byte ' Data Length Code of the message (0..15)
|
||||
DATA(63) As Byte ' Data of the message (DATA[0]..DATA[63])
|
||||
End Type
|
||||
|
||||
' Describes an available PCAN channel
|
||||
'
|
||||
Public Type TPCANChannelInformation
|
||||
channel_handle As Integer ' PCAN channel handle
|
||||
device_type As Byte ' Kind Of PCAN device
|
||||
controller_number As Byte ' CAN-Controller number
|
||||
device_features As Long ' Device capabilities flag (see FEATURE_*)
|
||||
device_name(MAX_LENGTH_HARDWARE_NAME) As Byte ' Device name
|
||||
device_id As Long ' Device number
|
||||
channel_condition As Long ' Availability status of a PCAN-Channel
|
||||
End Type
|
||||
|
||||
''' <summary>
|
||||
''' Initializes a PCAN Channel
|
||||
''' </summary>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <param name="Btr0Btr1">"The speed for the communication (BTR0BTR1 code)"</param>
|
||||
''' <param name="HwType">"Non-PnP: The type of hardware and operation mode"</param>
|
||||
''' <param name="IOPort">"Non-PnP: The I/O address for the parallel port"</param>
|
||||
''' <param name="Interrupt">"Non-PnP: Interrupt number of the parallel port"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_Initialize Lib "PCANBasic.DLL" _
|
||||
(ByVal channel As Integer, _
|
||||
ByVal Btr0Btr1 As Integer, _
|
||||
Optional ByVal HwType As Byte = 0, _
|
||||
Optional ByVal IOPort As Long = 0, _
|
||||
Optional ByVal Interrupt As Integer = 0) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Initializes a FD capable PCAN Channel
|
||||
''' </summary>
|
||||
''' <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
|
||||
''' <param name="BitrateFD">"The speed for the communication (FD bit rate string)"</param>
|
||||
''' <remarks>See PCAN_BR_* values
|
||||
''' * parameter and values ust be separated by '='
|
||||
''' * Couples of Parameter/value must be separated by ','
|
||||
''' * Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2,
|
||||
''' nom_brp, nom_sjw, nom_tseg1, nom_tseg2.
|
||||
''' * Following Parameters are optional (not used yet): data_ssp_offset, nom_sam
|
||||
'''</remarks>
|
||||
''' <example>f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1</example>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_InitializeFD Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer, _
|
||||
ByVal BitrateFD As String) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Uninitializes one or all PCAN Channels initialized by CAN_Initialize
|
||||
''' </summary>
|
||||
''' <remarks>Giving the TPCANHandle value "PCAN_NONEBUS",
|
||||
''' uninitialize all initialized channels</remarks>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_Uninitialize Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Resets the receive and transmit queues of the PCAN Channel
|
||||
''' </summary>
|
||||
''' <remarks>
|
||||
''' A reset of the CAN controller is not performed.
|
||||
''' </remarks>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_Reset Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Gets the current status of a PCAN Channel
|
||||
''' </summary>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_GetStatus Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Reads a CAN message from the receive queue of a PCAN Channel
|
||||
''' </summary>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <param name="MessageBuffer">"A TPCANMsg structure buffer to store the CAN message"</param>
|
||||
''' <param name="TimestampBuffer">"A TPCANTimestamp structure buffer to get
|
||||
''' the reception time of the message. If this value is not desired, this parameter
|
||||
''' should be passed as NULL"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_Read Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer, _
|
||||
ByRef MessageBuffer As TPCANMsg, _
|
||||
ByRef TimestampBuffer As TPCANTimestamp) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Reads a CAN message from the receive queue of a FD capable PCAN Channel
|
||||
''' </summary>
|
||||
''' <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
|
||||
''' <param name="MessageBuffer">"A TPCANMsgFD structure buffer to store the CAN message"</param>
|
||||
''' <param name="TimestampBuffer">"A TPCANTimestampFD buffer to get
|
||||
''' the reception time of the message. If this value is not desired, this parameter
|
||||
''' should be passed as NULL"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_ReadFD Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer,
|
||||
ByRef MessageBuffer As TPCANMsgFD,
|
||||
ByRef TimestampBuffer As Long) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Transmits a CAN message over a FD capable PCAN Channel
|
||||
''' </summary>
|
||||
''' <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
|
||||
''' <param name="MessageBuffer">"A TPCANMsgFD buffer with the message to be sent"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_WriteFD Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer, _
|
||||
ByRef MessageBuffer As TPCANMsgFD) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Transmits a CAN message
|
||||
''' </summary>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <param name="MessageBuffer">"A TPCANMsg buffer with the message to be sent"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_Write Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer, _
|
||||
ByRef MessageBuffer As TPCANMsg) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Configures the reception filter.
|
||||
''' </summary>
|
||||
''' <remarks>The message filter will be expanded with every call to
|
||||
''' this function. If it is desired to reset the filter, please use
|
||||
''' the CAN_SetValue function</remarks>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <param name="FromID">"The lowest CAN ID to be received"</param>
|
||||
''' <param name="ToID">"The highest CAN ID to be received"</param>
|
||||
''' <param name="Mode">"Message type, Standard (11-bit identifier) or
|
||||
''' Extended (29-bit identifier)"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_FilterMessages Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer, _
|
||||
ByVal FromID As Long, _
|
||||
ByVal ToID As Long, _
|
||||
ByVal Mode As Byte) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Retrieves a PCAN Channel value
|
||||
''' </summary>
|
||||
''' <remarks>Parameters can be present or not according with the kind
|
||||
''' of Hardware (PCAN Channel) being used. If a parameter is not available,
|
||||
''' a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <param name="Parameter">"The TPCANParameter parameter to get"</param>
|
||||
''' <param name="Buffer">"Buffer for the parameter value"</param>
|
||||
''' <param name="BufferLength">"Size in bytes of the buffer"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_GetValue Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer, _
|
||||
ByVal Parameter As Byte, _
|
||||
ByRef Buffer As Any, _
|
||||
ByVal BufferLength As Long) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Configures or sets a PCAN Channel value
|
||||
''' </summary>
|
||||
''' <remarks>Parameters can be present or not according with the kind
|
||||
''' of Hardware (PCAN Channel) being used. If a parameter is not available,
|
||||
''' a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
|
||||
''' <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
''' <param name="Parameter">"The TPCANParameter parameter to set"</param>
|
||||
''' <param name="Buffer">"Buffer with the value to be set"</param>
|
||||
''' <param name="BufferLength">"Size in bytes of the buffer"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_SetValue Lib "PCANBasic.DLL" _
|
||||
(ByVal Channel As Integer, _
|
||||
ByVal Parameter As Byte, _
|
||||
ByRef Buffer As Any, _
|
||||
ByVal BufferLength As Long) As Long
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Returns a descriptive text of a given TPCANStatus error
|
||||
''' code, in any desired language
|
||||
''' </summary>
|
||||
''' <remarks>The current languages available for translation are:
|
||||
''' Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
|
||||
''' Italian (0x10) and French (0x0C)</remarks>
|
||||
''' <param name="Error">"A TPCANStatus error code"</param>
|
||||
''' <param name="Language">"Indicates a 'Primary language ID'"</param>
|
||||
''' <param name="Buffer">"Buffer for a null terminated char array"</param>
|
||||
''' <returns>"A TPCANStatus error code"</returns>
|
||||
Public Declare Function CAN_GetErrorText Lib "PCANBasic.DLL" _
|
||||
(ByVal ErrorCode As Long,
|
||||
ByVal Language As Integer,
|
||||
ByVal Buffer As String) As Long
|
||||
|
||||
''' <summary>
|
||||
''' Finds a PCAN-Basic channel that matches with the given parameters
|
||||
''' </summary>
|
||||
''' <param name="Parameters">A comma separated string contained pairs of
|
||||
''' parameter-name/value to be matched within a PCAN-Basic channel</param>
|
||||
''' <param name="FoundChannel">Buffer for returning the PCAN-Basic channel,
|
||||
''' when found</param>
|
||||
''' <returns>A TPCANStatus error code</returns>
|
||||
Public Declare Function CAN_LookUpChannel Lib "PCANBasic.DLL" _
|
||||
(ByVal Parameters As String,
|
||||
ByRef FoundChannel As Integer) As Long
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,585 @@
|
||||
// PCANBasic.h
|
||||
//
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// PCAN-Basic API
|
||||
//
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
// Author : Keneth Wagner
|
||||
// Last change: 2022-07-06
|
||||
//
|
||||
// Language: ANSI-C
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (C) 1999-2022 PEAK-System Technik GmbH, Darmstadt
|
||||
// more Info at http://www.peak-system.com
|
||||
//
|
||||
#ifndef __PCANBASICH__
|
||||
#define __PCANBASICH__
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Value definitions
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// Currently defined and supported PCAN channels
|
||||
//
|
||||
#define PCAN_NONEBUS 0x00U // Undefined/default value for a PCAN bus
|
||||
|
||||
#define PCAN_ISABUS1 0x21U // PCAN-ISA interface, channel 1
|
||||
#define PCAN_ISABUS2 0x22U // PCAN-ISA interface, channel 2
|
||||
#define PCAN_ISABUS3 0x23U // PCAN-ISA interface, channel 3
|
||||
#define PCAN_ISABUS4 0x24U // PCAN-ISA interface, channel 4
|
||||
#define PCAN_ISABUS5 0x25U // PCAN-ISA interface, channel 5
|
||||
#define PCAN_ISABUS6 0x26U // PCAN-ISA interface, channel 6
|
||||
#define PCAN_ISABUS7 0x27U // PCAN-ISA interface, channel 7
|
||||
#define PCAN_ISABUS8 0x28U // PCAN-ISA interface, channel 8
|
||||
|
||||
#define PCAN_DNGBUS1 0x31U // PCAN-Dongle/LPT interface, channel 1
|
||||
|
||||
#define PCAN_PCIBUS1 0x41U // PCAN-PCI interface, channel 1
|
||||
#define PCAN_PCIBUS2 0x42U // PCAN-PCI interface, channel 2
|
||||
#define PCAN_PCIBUS3 0x43U // PCAN-PCI interface, channel 3
|
||||
#define PCAN_PCIBUS4 0x44U // PCAN-PCI interface, channel 4
|
||||
#define PCAN_PCIBUS5 0x45U // PCAN-PCI interface, channel 5
|
||||
#define PCAN_PCIBUS6 0x46U // PCAN-PCI interface, channel 6
|
||||
#define PCAN_PCIBUS7 0x47U // PCAN-PCI interface, channel 7
|
||||
#define PCAN_PCIBUS8 0x48U // PCAN-PCI interface, channel 8
|
||||
#define PCAN_PCIBUS9 0x409U // PCAN-PCI interface, channel 9
|
||||
#define PCAN_PCIBUS10 0x40AU // PCAN-PCI interface, channel 10
|
||||
#define PCAN_PCIBUS11 0x40BU // PCAN-PCI interface, channel 11
|
||||
#define PCAN_PCIBUS12 0x40CU // PCAN-PCI interface, channel 12
|
||||
#define PCAN_PCIBUS13 0x40DU // PCAN-PCI interface, channel 13
|
||||
#define PCAN_PCIBUS14 0x40EU // PCAN-PCI interface, channel 14
|
||||
#define PCAN_PCIBUS15 0x40FU // PCAN-PCI interface, channel 15
|
||||
#define PCAN_PCIBUS16 0x410U // PCAN-PCI interface, channel 16
|
||||
|
||||
#define PCAN_USBBUS1 0x51U // PCAN-USB interface, channel 1
|
||||
#define PCAN_USBBUS2 0x52U // PCAN-USB interface, channel 2
|
||||
#define PCAN_USBBUS3 0x53U // PCAN-USB interface, channel 3
|
||||
#define PCAN_USBBUS4 0x54U // PCAN-USB interface, channel 4
|
||||
#define PCAN_USBBUS5 0x55U // PCAN-USB interface, channel 5
|
||||
#define PCAN_USBBUS6 0x56U // PCAN-USB interface, channel 6
|
||||
#define PCAN_USBBUS7 0x57U // PCAN-USB interface, channel 7
|
||||
#define PCAN_USBBUS8 0x58U // PCAN-USB interface, channel 8
|
||||
#define PCAN_USBBUS9 0x509U // PCAN-USB interface, channel 9
|
||||
#define PCAN_USBBUS10 0x50AU // PCAN-USB interface, channel 10
|
||||
#define PCAN_USBBUS11 0x50BU // PCAN-USB interface, channel 11
|
||||
#define PCAN_USBBUS12 0x50CU // PCAN-USB interface, channel 12
|
||||
#define PCAN_USBBUS13 0x50DU // PCAN-USB interface, channel 13
|
||||
#define PCAN_USBBUS14 0x50EU // PCAN-USB interface, channel 14
|
||||
#define PCAN_USBBUS15 0x50FU // PCAN-USB interface, channel 15
|
||||
#define PCAN_USBBUS16 0x510U // PCAN-USB interface, channel 16
|
||||
|
||||
#define PCAN_PCCBUS1 0x61U // PCAN-PC Card interface, channel 1
|
||||
#define PCAN_PCCBUS2 0x62U // PCAN-PC Card interface, channel 2
|
||||
|
||||
#define PCAN_LANBUS1 0x801U // PCAN-LAN interface, channel 1
|
||||
#define PCAN_LANBUS2 0x802U // PCAN-LAN interface, channel 2
|
||||
#define PCAN_LANBUS3 0x803U // PCAN-LAN interface, channel 3
|
||||
#define PCAN_LANBUS4 0x804U // PCAN-LAN interface, channel 4
|
||||
#define PCAN_LANBUS5 0x805U // PCAN-LAN interface, channel 5
|
||||
#define PCAN_LANBUS6 0x806U // PCAN-LAN interface, channel 6
|
||||
#define PCAN_LANBUS7 0x807U // PCAN-LAN interface, channel 7
|
||||
#define PCAN_LANBUS8 0x808U // PCAN-LAN interface, channel 8
|
||||
#define PCAN_LANBUS9 0x809U // PCAN-LAN interface, channel 9
|
||||
#define PCAN_LANBUS10 0x80AU // PCAN-LAN interface, channel 10
|
||||
#define PCAN_LANBUS11 0x80BU // PCAN-LAN interface, channel 11
|
||||
#define PCAN_LANBUS12 0x80CU // PCAN-LAN interface, channel 12
|
||||
#define PCAN_LANBUS13 0x80DU // PCAN-LAN interface, channel 13
|
||||
#define PCAN_LANBUS14 0x80EU // PCAN-LAN interface, channel 14
|
||||
#define PCAN_LANBUS15 0x80FU // PCAN-LAN interface, channel 15
|
||||
#define PCAN_LANBUS16 0x810U // PCAN-LAN interface, channel 16
|
||||
|
||||
// Represent the PCAN error and status codes
|
||||
//
|
||||
#define PCAN_ERROR_OK 0x00000U // No error
|
||||
#define PCAN_ERROR_XMTFULL 0x00001U // Transmit buffer in CAN controller is full
|
||||
#define PCAN_ERROR_OVERRUN 0x00002U // CAN controller was read too late
|
||||
#define PCAN_ERROR_BUSLIGHT 0x00004U // Bus error: an error counter reached the 'light' limit
|
||||
#define PCAN_ERROR_BUSHEAVY 0x00008U // Bus error: an error counter reached the 'heavy' limit
|
||||
#define PCAN_ERROR_BUSWARNING PCAN_ERROR_BUSHEAVY // Bus error: an error counter reached the 'warning' limit
|
||||
#define PCAN_ERROR_BUSPASSIVE 0x40000U // Bus error: the CAN controller is error passive
|
||||
#define PCAN_ERROR_BUSOFF 0x00010U // Bus error: the CAN controller is in bus-off state
|
||||
#define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE) // Mask for all bus errors
|
||||
#define PCAN_ERROR_QRCVEMPTY 0x00020U // Receive queue is empty
|
||||
#define PCAN_ERROR_QOVERRUN 0x00040U // Receive queue was read too late
|
||||
#define PCAN_ERROR_QXMTFULL 0x00080U // Transmit queue is full
|
||||
#define PCAN_ERROR_REGTEST 0x00100U // Test of the CAN controller hardware registers failed (no hardware found)
|
||||
#define PCAN_ERROR_NODRIVER 0x00200U // Driver not loaded
|
||||
#define PCAN_ERROR_HWINUSE 0x00400U // Hardware already in use by a Net
|
||||
#define PCAN_ERROR_NETINUSE 0x00800U // A Client is already connected to the Net
|
||||
#define PCAN_ERROR_ILLHW 0x01400U // Hardware handle is invalid
|
||||
#define PCAN_ERROR_ILLNET 0x01800U // Net handle is invalid
|
||||
#define PCAN_ERROR_ILLCLIENT 0x01C00U // Client handle is invalid
|
||||
#define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) // Mask for all handle errors
|
||||
#define PCAN_ERROR_RESOURCE 0x02000U // Resource (FIFO, Client, timeout) cannot be created
|
||||
#define PCAN_ERROR_ILLPARAMTYPE 0x04000U // Invalid parameter
|
||||
#define PCAN_ERROR_ILLPARAMVAL 0x08000U // Invalid parameter value
|
||||
#define PCAN_ERROR_UNKNOWN 0x10000U // Unknown error
|
||||
#define PCAN_ERROR_ILLDATA 0x20000U // Invalid data, function, or action
|
||||
#define PCAN_ERROR_ILLMODE 0x80000U // Driver object state is wrong for the attempted operation
|
||||
#define PCAN_ERROR_CAUTION 0x2000000U // An operation was successfully carried out, however, irregularities were registered
|
||||
#define PCAN_ERROR_INITIALIZE 0x4000000U // Channel is not initialized [Value was changed from 0x40000 to 0x4000000]
|
||||
#define PCAN_ERROR_ILLOPERATION 0x8000000U // Invalid operation [Value was changed from 0x80000 to 0x8000000]
|
||||
|
||||
// PCAN devices
|
||||
//
|
||||
#define PCAN_NONE 0x00U // Undefined, unknown or not selected PCAN device value
|
||||
#define PCAN_PEAKCAN 0x01U // PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API
|
||||
#define PCAN_ISA 0x02U // PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
|
||||
#define PCAN_DNG 0x03U // PCAN-Dongle
|
||||
#define PCAN_PCI 0x04U // PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
|
||||
#define PCAN_USB 0x05U // PCAN-USB and PCAN-USB Pro
|
||||
#define PCAN_PCC 0x06U // PCAN-PC Card
|
||||
#define PCAN_VIRTUAL 0x07U // PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API
|
||||
#define PCAN_LAN 0x08U // PCAN Gateway devices
|
||||
|
||||
// PCAN parameters
|
||||
//
|
||||
#define PCAN_DEVICE_ID 0x01U // Device identifier parameter
|
||||
#define PCAN_5VOLTS_POWER 0x02U // 5-Volt power parameter
|
||||
#define PCAN_RECEIVE_EVENT 0x03U // PCAN receive event handler parameter
|
||||
#define PCAN_MESSAGE_FILTER 0x04U // PCAN message filter parameter
|
||||
#define PCAN_API_VERSION 0x05U // PCAN-Basic API version parameter
|
||||
#define PCAN_CHANNEL_VERSION 0x06U // PCAN device channel version parameter
|
||||
#define PCAN_BUSOFF_AUTORESET 0x07U // PCAN Reset-On-Busoff parameter
|
||||
#define PCAN_LISTEN_ONLY 0x08U // PCAN Listen-Only parameter
|
||||
#define PCAN_LOG_LOCATION 0x09U // Directory path for log files
|
||||
#define PCAN_LOG_STATUS 0x0AU // Debug-Log activation status
|
||||
#define PCAN_LOG_CONFIGURE 0x0BU // Configuration of the debugged information (LOG_FUNCTION_***)
|
||||
#define PCAN_LOG_TEXT 0x0CU // Custom insertion of text into the log file
|
||||
#define PCAN_CHANNEL_CONDITION 0x0DU // Availability status of a PCAN-Channel
|
||||
#define PCAN_HARDWARE_NAME 0x0EU // PCAN hardware name parameter
|
||||
#define PCAN_RECEIVE_STATUS 0x0FU // Message reception status of a PCAN-Channel
|
||||
#define PCAN_CONTROLLER_NUMBER 0x10U // CAN-Controller number of a PCAN-Channel
|
||||
#define PCAN_TRACE_LOCATION 0x11U // Directory path for PCAN trace files
|
||||
#define PCAN_TRACE_STATUS 0x12U // CAN tracing activation status
|
||||
#define PCAN_TRACE_SIZE 0x13U // Configuration of the maximum file size of a CAN trace
|
||||
#define PCAN_TRACE_CONFIGURE 0x14U // Configuration of the trace file storing mode (TRACE_FILE_***)
|
||||
#define PCAN_CHANNEL_IDENTIFYING 0x15U // Physical identification of a USB based PCAN-Channel by blinking its associated LED
|
||||
#define PCAN_CHANNEL_FEATURES 0x16U // Capabilities of a PCAN device (FEATURE_***)
|
||||
#define PCAN_BITRATE_ADAPTING 0x17U // Using of an existing bit rate (PCAN-View connected to a channel)
|
||||
#define PCAN_BITRATE_INFO 0x18U // Configured bit rate as Btr0Btr1 value
|
||||
#define PCAN_BITRATE_INFO_FD 0x19U // Configured bit rate as TPCANBitrateFD string
|
||||
#define PCAN_BUSSPEED_NOMINAL 0x1AU // Configured nominal CAN Bus speed as Bits per seconds
|
||||
#define PCAN_BUSSPEED_DATA 0x1BU // Configured CAN data speed as Bits per seconds
|
||||
#define PCAN_IP_ADDRESS 0x1CU // Remote address of a LAN channel as string in IPv4 format
|
||||
#define PCAN_LAN_SERVICE_STATUS 0x1DU // Status of the Virtual PCAN-Gateway Service
|
||||
#define PCAN_ALLOW_STATUS_FRAMES 0x1EU // Status messages reception status within a PCAN-Channel
|
||||
#define PCAN_ALLOW_RTR_FRAMES 0x1FU // RTR messages reception status within a PCAN-Channel
|
||||
#define PCAN_ALLOW_ERROR_FRAMES 0x20U // Error messages reception status within a PCAN-Channel
|
||||
#define PCAN_INTERFRAME_DELAY 0x21U // Delay, in microseconds, between sending frames
|
||||
#define PCAN_ACCEPTANCE_FILTER_11BIT 0x22U // Filter over code and mask patterns for 11-Bit messages
|
||||
#define PCAN_ACCEPTANCE_FILTER_29BIT 0x23U // Filter over code and mask patterns for 29-Bit messages
|
||||
#define PCAN_IO_DIGITAL_CONFIGURATION 0x24U // Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive
|
||||
#define PCAN_IO_DIGITAL_VALUE 0x25U // Value assigned to a 32 digital I/O pins of a PCAN-USB Chip
|
||||
#define PCAN_IO_DIGITAL_SET 0x26U // Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High
|
||||
#define PCAN_IO_DIGITAL_CLEAR 0x27U // Clear multiple digital I/O pins to 0
|
||||
#define PCAN_IO_ANALOG_VALUE 0x28U // Get value of a single analog input pin
|
||||
#define PCAN_FIRMWARE_VERSION 0x29U // Get the version of the firmware used by the device associated with a PCAN-Channel
|
||||
#define PCAN_ATTACHED_CHANNELS_COUNT 0x2AU // Get the amount of PCAN channels attached to a system
|
||||
#define PCAN_ATTACHED_CHANNELS 0x2BU // Get information about PCAN channels attached to a system
|
||||
#define PCAN_ALLOW_ECHO_FRAMES 0x2CU // Echo messages reception status within a PCAN-Channel
|
||||
#define PCAN_DEVICE_PART_NUMBER 0x2DU // Get the part number associated to a device
|
||||
|
||||
// DEPRECATED parameters
|
||||
//
|
||||
#define PCAN_DEVICE_NUMBER PCAN_DEVICE_ID // Deprecated parameter. Use PCAN_DEVICE_ID instead
|
||||
|
||||
// PCAN parameter values
|
||||
//
|
||||
#define PCAN_PARAMETER_OFF 0x00U // The PCAN parameter is not set (inactive)
|
||||
#define PCAN_PARAMETER_ON 0x01U // The PCAN parameter is set (active)
|
||||
#define PCAN_FILTER_CLOSE 0x00U // The PCAN filter is closed. No messages will be received
|
||||
#define PCAN_FILTER_OPEN 0x01U // The PCAN filter is fully opened. All messages will be received
|
||||
#define PCAN_FILTER_CUSTOM 0x02U // The PCAN filter is custom configured. Only registered messages will be received
|
||||
#define PCAN_CHANNEL_UNAVAILABLE 0x00U // The PCAN-Channel handle is illegal, or its associated hardware is not available
|
||||
#define PCAN_CHANNEL_AVAILABLE 0x01U // The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in)
|
||||
#define PCAN_CHANNEL_OCCUPIED 0x02U // The PCAN-Channel handle is valid, and is already being used
|
||||
#define PCAN_CHANNEL_PCANVIEW (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED) // The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect
|
||||
|
||||
#define LOG_FUNCTION_DEFAULT 0x00U // Logs system exceptions / errors
|
||||
#define LOG_FUNCTION_ENTRY 0x01U // Logs the entries to the PCAN-Basic API functions
|
||||
#define LOG_FUNCTION_PARAMETERS 0x02U // Logs the parameters passed to the PCAN-Basic API functions
|
||||
#define LOG_FUNCTION_LEAVE 0x04U // Logs the exits from the PCAN-Basic API functions
|
||||
#define LOG_FUNCTION_WRITE 0x08U // Logs the CAN messages passed to the CAN_Write function
|
||||
#define LOG_FUNCTION_READ 0x10U // Logs the CAN messages received within the CAN_Read function
|
||||
#define LOG_FUNCTION_ALL 0xFFFFU // Logs all possible information within the PCAN-Basic API functions
|
||||
|
||||
#define TRACE_FILE_SINGLE 0x00U // A single file is written until it size reaches PAN_TRACE_SIZE
|
||||
#define TRACE_FILE_SEGMENTED 0x01U // Traced data is distributed in several files with size PAN_TRACE_SIZE
|
||||
#define TRACE_FILE_DATE 0x02U // Includes the date into the name of the trace file
|
||||
#define TRACE_FILE_TIME 0x04U // Includes the start time into the name of the trace file
|
||||
#define TRACE_FILE_OVERWRITE 0x80U // Causes the overwriting of available traces (same name)
|
||||
|
||||
#define FEATURE_FD_CAPABLE 0x01U // Device supports flexible data-rate (CAN-FD)
|
||||
#define FEATURE_DELAY_CAPABLE 0x02U // Device supports a delay between sending frames (FPGA based USB devices)
|
||||
#define FEATURE_IO_CAPABLE 0x04U // Device supports I/O functionality for electronic circuits (USB-Chip devices)
|
||||
|
||||
#define SERVICE_STATUS_STOPPED 0x01U // The service is not running
|
||||
#define SERVICE_STATUS_RUNNING 0x04U // The service is running
|
||||
|
||||
// Other constants
|
||||
//
|
||||
#define MAX_LENGTH_HARDWARE_NAME 33 // Maximum length of the name of a device: 32 characters + terminator
|
||||
#define MAX_LENGTH_VERSION_STRING 256 // Maximum length of a version string: 255 characters + terminator
|
||||
|
||||
// PCAN message types
|
||||
//
|
||||
#define PCAN_MESSAGE_STANDARD 0x00U // The PCAN message is a CAN Standard Frame (11-bit identifier)
|
||||
#define PCAN_MESSAGE_RTR 0x01U // The PCAN message is a CAN Remote-Transfer-Request Frame
|
||||
#define PCAN_MESSAGE_EXTENDED 0x02U // The PCAN message is a CAN Extended Frame (29-bit identifier)
|
||||
#define PCAN_MESSAGE_FD 0x04U // The PCAN message represents a FD frame in terms of CiA Specs
|
||||
#define PCAN_MESSAGE_BRS 0x08U // The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate)
|
||||
#define PCAN_MESSAGE_ESI 0x10U // The PCAN message represents a FD error state indicator(CAN FD transmitter was error active)
|
||||
#define PCAN_MESSAGE_ECHO 0x20U // The PCAN message represents an echo CAN Frame
|
||||
#define PCAN_MESSAGE_ERRFRAME 0x40U // The PCAN message represents an error frame
|
||||
#define PCAN_MESSAGE_STATUS 0x80U // The PCAN message represents a PCAN status message
|
||||
|
||||
// LookUp Parameters
|
||||
//
|
||||
#define LOOKUP_DEVICE_TYPE __T("devicetype") // Lookup channel by Device type (see PCAN devices e.g. PCAN_USB)
|
||||
#define LOOKUP_DEVICE_ID __T("deviceid") // Lookup channel by device id
|
||||
#define LOOKUP_CONTROLLER_NUMBER __T("controllernumber") // Lookup channel by CAN controller 0-based index
|
||||
#define LOOKUP_IP_ADDRESS __T("ipaddress") // Lookup channel by IP address (LAN channels only)
|
||||
|
||||
// Frame Type / Initialization Mode
|
||||
//
|
||||
#define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD
|
||||
#define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED
|
||||
|
||||
// Baud rate codes = BTR0/BTR1 register values for the CAN controller.
|
||||
// You can define your own Baud rate with the BTROBTR1 register.
|
||||
// Take a look at www.peak-system.com for our free software "BAUDTOOL"
|
||||
// to calculate the BTROBTR1 register for every bit rate and sample point.
|
||||
//
|
||||
#define PCAN_BAUD_1M 0x0014U // 1 MBit/s
|
||||
#define PCAN_BAUD_800K 0x0016U // 800 kBit/s
|
||||
#define PCAN_BAUD_500K 0x001CU // 500 kBit/s
|
||||
#define PCAN_BAUD_250K 0x011CU // 250 kBit/s
|
||||
#define PCAN_BAUD_125K 0x031CU // 125 kBit/s
|
||||
#define PCAN_BAUD_100K 0x432FU // 100 kBit/s
|
||||
#define PCAN_BAUD_95K 0xC34EU // 95,238 kBit/s
|
||||
#define PCAN_BAUD_83K 0x852BU // 83,333 kBit/s
|
||||
#define PCAN_BAUD_50K 0x472FU // 50 kBit/s
|
||||
#define PCAN_BAUD_47K 0x1414U // 47,619 kBit/s
|
||||
#define PCAN_BAUD_33K 0x8B2FU // 33,333 kBit/s
|
||||
#define PCAN_BAUD_20K 0x532FU // 20 kBit/s
|
||||
#define PCAN_BAUD_10K 0x672FU // 10 kBit/s
|
||||
#define PCAN_BAUD_5K 0x7F7FU // 5 kBit/s
|
||||
|
||||
// Represents the configuration for a CAN bit rate
|
||||
// Note:
|
||||
// * Each parameter and its value must be separated with a '='.
|
||||
// * Each pair of parameter/value must be separated using ','.
|
||||
//
|
||||
// Example:
|
||||
// f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1
|
||||
//
|
||||
#define PCAN_BR_CLOCK __T("f_clock")
|
||||
#define PCAN_BR_CLOCK_MHZ __T("f_clock_mhz")
|
||||
#define PCAN_BR_NOM_BRP __T("nom_brp")
|
||||
#define PCAN_BR_NOM_TSEG1 __T("nom_tseg1")
|
||||
#define PCAN_BR_NOM_TSEG2 __T("nom_tseg2")
|
||||
#define PCAN_BR_NOM_SJW __T("nom_sjw")
|
||||
#define PCAN_BR_NOM_SAMPLE __T("nom_sam")
|
||||
#define PCAN_BR_DATA_BRP __T("data_brp")
|
||||
#define PCAN_BR_DATA_TSEG1 __T("data_tseg1")
|
||||
#define PCAN_BR_DATA_TSEG2 __T("data_tseg2")
|
||||
#define PCAN_BR_DATA_SJW __T("data_sjw")
|
||||
#define PCAN_BR_DATA_SAMPLE __T("data_ssp_offset")
|
||||
|
||||
// Type of PCAN (Non-PnP) hardware
|
||||
//
|
||||
#define PCAN_TYPE_ISA 0x01U // PCAN-ISA 82C200
|
||||
#define PCAN_TYPE_ISA_SJA 0x09U // PCAN-ISA SJA1000
|
||||
#define PCAN_TYPE_ISA_PHYTEC 0x04U // PHYTEC ISA
|
||||
#define PCAN_TYPE_DNG 0x02U // PCAN-Dongle 82C200
|
||||
#define PCAN_TYPE_DNG_EPP 0x03U // PCAN-Dongle EPP 82C200
|
||||
#define PCAN_TYPE_DNG_SJA 0x05U // PCAN-Dongle SJA1000
|
||||
#define PCAN_TYPE_DNG_SJA_EPP 0x06U // PCAN-Dongle EPP SJA1000
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Type definitions
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#define TPCANHandle WORD // Represents a PCAN hardware channel handle
|
||||
#define TPCANStatus DWORD // Represents a PCAN status/error code
|
||||
#define TPCANParameter BYTE // Represents a PCAN parameter to be read or set
|
||||
#define TPCANDevice BYTE // Represents a PCAN device
|
||||
#define TPCANMessageType BYTE // Represents the type of a PCAN message
|
||||
#define TPCANType BYTE // Represents the type of PCAN hardware to be initialized
|
||||
#define TPCANMode BYTE // Represents a PCAN filter mode
|
||||
#define TPCANBaudrate WORD // Represents a PCAN Baud rate register value
|
||||
#define TPCANBitrateFD LPSTR // Represents a PCAN-FD bit rate string
|
||||
#define TPCANTimestampFD UINT64 // Represents a timestamp of a received PCAN FD message
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Structure definitions
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// Represents a PCAN message
|
||||
//
|
||||
typedef struct tagTPCANMsg
|
||||
{
|
||||
DWORD ID; // 11/29-bit message identifier
|
||||
TPCANMessageType MSGTYPE; // Type of the message
|
||||
BYTE LEN; // Data Length Code of the message (0..8)
|
||||
BYTE DATA[8]; // Data of the message (DATA[0]..DATA[7])
|
||||
} TPCANMsg;
|
||||
|
||||
// Represents a timestamp of a received PCAN message
|
||||
// Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
|
||||
//
|
||||
typedef struct tagTPCANTimestamp
|
||||
{
|
||||
DWORD millis; // Base-value: milliseconds: 0.. 2^32-1
|
||||
WORD millis_overflow; // Roll-arounds of millis
|
||||
WORD micros; // Microseconds: 0..999
|
||||
} TPCANTimestamp;
|
||||
|
||||
// Represents a PCAN message from a FD capable hardware
|
||||
//
|
||||
typedef struct tagTPCANMsgFD
|
||||
{
|
||||
DWORD ID; // 11/29-bit message identifier
|
||||
TPCANMessageType MSGTYPE; // Type of the message
|
||||
BYTE DLC; // Data Length Code of the message (0..15)
|
||||
BYTE DATA[64]; // Data of the message (DATA[0]..DATA[63])
|
||||
} TPCANMsgFD;
|
||||
|
||||
// Describes an available PCAN channel
|
||||
//
|
||||
typedef struct tagTPCANChannelInformation
|
||||
{
|
||||
TPCANHandle channel_handle; // PCAN channel handle
|
||||
TPCANDevice device_type; // Kind of PCAN device
|
||||
BYTE controller_number; // CAN-Controller number
|
||||
DWORD device_features; // Device capabilities flag (see FEATURE_*)
|
||||
char device_name[MAX_LENGTH_HARDWARE_NAME]; // Device name
|
||||
DWORD device_id; // Device number
|
||||
DWORD channel_condition; // Availability status of a PCAN-Channel
|
||||
}TPCANChannelInformation;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#define _DEF_ARG =0
|
||||
#else
|
||||
#define _DEF_ARG
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// PCAN-Basic API function declarations
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a PCAN Channel
|
||||
/// </summary>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <param name="Btr0Btr1">"The speed for the communication (BTR0BTR1 code)"</param>
|
||||
/// <param name="HwType">"Non-PnP: The type of hardware and operation mode"</param>
|
||||
/// <param name="IOPort">"Non-PnP: The I/O address for the parallel port"</param>
|
||||
/// <param name="Interrupt">"Non-PnP: Interrupt number of the parallel port"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_Initialize(
|
||||
TPCANHandle Channel,
|
||||
TPCANBaudrate Btr0Btr1,
|
||||
TPCANType HwType _DEF_ARG,
|
||||
DWORD IOPort _DEF_ARG,
|
||||
WORD Interrupt _DEF_ARG);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a FD capable PCAN Channel
|
||||
/// </summary>
|
||||
/// <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
|
||||
/// <param name="BitrateFD">"The speed for the communication (FD bit rate string)"</param>
|
||||
/// <remarks>See PCAN_BR_* values
|
||||
/// * Parameter and values must be separated by '='
|
||||
/// * Couples of Parameter/value must be separated by ','
|
||||
/// * Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2,
|
||||
/// nom_brp, nom_sjw, nom_tseg1, nom_tseg2.
|
||||
/// * Following Parameters are optional (not used yet): data_ssp_offset, nom_sam
|
||||
///</remarks>
|
||||
/// <example>f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1</example>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_InitializeFD(
|
||||
TPCANHandle Channel,
|
||||
TPCANBitrateFD BitrateFD);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize
|
||||
/// </summary>
|
||||
/// <remarks>Giving the TPCANHandle value "PCAN_NONEBUS",
|
||||
/// uninitialize all initialized channels</remarks>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_Uninitialize(
|
||||
TPCANHandle Channel);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resets the receive and transmit queues of the PCAN Channel
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A reset of the CAN controller is not performed.
|
||||
/// </remarks>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_Reset(
|
||||
TPCANHandle Channel);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current status of a PCAN Channel
|
||||
/// </summary>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_GetStatus(
|
||||
TPCANHandle Channel);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reads a CAN message from the receive queue of a PCAN Channel
|
||||
/// </summary>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <param name="MessageBuffer">"A TPCANMsg structure buffer to store the CAN message"</param>
|
||||
/// <param name="TimestampBuffer">"A TPCANTimestamp structure buffer to get
|
||||
/// the reception time of the message. If this value is not desired, this parameter
|
||||
/// should be passed as NULL"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_Read(
|
||||
TPCANHandle Channel,
|
||||
TPCANMsg* MessageBuffer,
|
||||
TPCANTimestamp* TimestampBuffer);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reads a CAN message from the receive queue of a FD capable PCAN Channel
|
||||
/// </summary>
|
||||
/// <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
|
||||
/// <param name="MessageBuffer">"A TPCANMsgFD structure buffer to store the CAN message"</param>
|
||||
/// <param name="TimestampBuffer">"A TPCANTimestampFD buffer to get
|
||||
/// the reception time of the message. If this value is not desired, this parameter
|
||||
/// should be passed as NULL"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_ReadFD(
|
||||
TPCANHandle Channel,
|
||||
TPCANMsgFD* MessageBuffer,
|
||||
TPCANTimestampFD *TimestampBuffer);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Transmits a CAN message
|
||||
/// </summary>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <param name="MessageBuffer">"A TPCANMsg buffer with the message to be sent"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_Write(
|
||||
TPCANHandle Channel,
|
||||
TPCANMsg* MessageBuffer);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Transmits a CAN message over a FD capable PCAN Channel
|
||||
/// </summary>
|
||||
/// <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
|
||||
/// <param name="MessageBuffer">"A TPCANMsgFD buffer with the message to be sent"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_WriteFD(
|
||||
TPCANHandle Channel,
|
||||
TPCANMsgFD* MessageBuffer);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configures the reception filter.
|
||||
/// </summary>
|
||||
/// <remarks>The message filter will be expanded with every call to
|
||||
/// this function. If it is desired to reset the filter, please use
|
||||
/// the CAN_SetValue function</remarks>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <param name="FromID">"The lowest CAN ID to be received"</param>
|
||||
/// <param name="ToID">"The highest CAN ID to be received"</param>
|
||||
/// <param name="Mode">"Message type, Standard (11-bit identifier) or
|
||||
/// Extended (29-bit identifier)"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_FilterMessages(
|
||||
TPCANHandle Channel,
|
||||
DWORD FromID,
|
||||
DWORD ToID,
|
||||
TPCANMode Mode);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a PCAN Channel value
|
||||
/// </summary>
|
||||
/// <remarks>Parameters can be present or not according with the kind
|
||||
/// of Hardware (PCAN Channel) being used. If a parameter is not available,
|
||||
/// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <param name="Parameter">"The TPCANParameter parameter to get"</param>
|
||||
/// <param name="Buffer">"Buffer for the parameter value"</param>
|
||||
/// <param name="BufferLength">"Size in bytes of the buffer"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_GetValue(
|
||||
TPCANHandle Channel,
|
||||
TPCANParameter Parameter,
|
||||
void* Buffer,
|
||||
DWORD BufferLength);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configures or sets a PCAN Channel value
|
||||
/// </summary>
|
||||
/// <remarks>Parameters can be present or not according with the kind
|
||||
/// of Hardware (PCAN Channel) being used. If a parameter is not available,
|
||||
/// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
|
||||
/// <param name="Channel">"The handle of a PCAN Channel"</param>
|
||||
/// <param name="Parameter">"The TPCANParameter parameter to set"</param>
|
||||
/// <param name="Buffer">"Buffer with the value to be set"</param>
|
||||
/// <param name="BufferLength">"Size in bytes of the buffer"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_SetValue(
|
||||
TPCANHandle Channel,
|
||||
TPCANParameter Parameter,
|
||||
void* Buffer,
|
||||
DWORD BufferLength);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a descriptive text of a given TPCANStatus error
|
||||
/// code, in any desired language
|
||||
/// </summary>
|
||||
/// <remarks>The current languages available for translation are:
|
||||
/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
|
||||
/// Italian (0x10) and French (0x0C)</remarks>
|
||||
/// <param name="Error">"A TPCANStatus error code"</param>
|
||||
/// <param name="Language">"Indicates a 'Primary language ID'"</param>
|
||||
/// <param name="Buffer">"Buffer for a null terminated char array"</param>
|
||||
/// <returns>"A TPCANStatus error code"</returns>
|
||||
TPCANStatus __stdcall CAN_GetErrorText(
|
||||
TPCANStatus Error,
|
||||
WORD Language,
|
||||
LPSTR Buffer);
|
||||
|
||||
/// <summary>
|
||||
/// Finds a PCAN-Basic channel that matches with the given parameters
|
||||
/// </summary>
|
||||
/// <param name="Parameters">A comma separated string contained pairs of
|
||||
/// parameter-name/value to be matched within a PCAN-Basic channel</param>
|
||||
/// <param name="FoundChannel">Buffer for returning the PCAN-Basic channel,
|
||||
/// when found</param>
|
||||
/// <returns>A TPCANStatus error code</returns>
|
||||
TPCANStatus __stdcall CAN_LookUpChannel(
|
||||
LPSTR Parameters,
|
||||
TPCANHandle* FoundChannel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,838 @@
|
||||
# PCANBasic.py
|
||||
#
|
||||
# ~~~~~~~~~~~~
|
||||
#
|
||||
# PCAN-Basic API
|
||||
#
|
||||
# ~~~~~~~~~~~~
|
||||
#
|
||||
# ------------------------------------------------------------------
|
||||
# Author : Keneth Wagner
|
||||
# Last change: 2022-07-06
|
||||
#
|
||||
# Language: Python 2.7, 3.8
|
||||
# ------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 1999-2022 PEAK-System Technik GmbH, Darmstadt
|
||||
# more Info at http://www.peak-system.com
|
||||
#
|
||||
|
||||
# Module Imports
|
||||
#
|
||||
from ctypes import *
|
||||
from string import *
|
||||
import platform
|
||||
|
||||
#///////////////////////////////////////////////////////////
|
||||
# Type definitions
|
||||
#///////////////////////////////////////////////////////////
|
||||
|
||||
TPCANHandle = c_ushort # Represents a PCAN hardware channel handle
|
||||
TPCANStatus = int # Represents a PCAN status/error code
|
||||
TPCANParameter = c_ubyte # Represents a PCAN parameter to be read or set
|
||||
TPCANDevice = c_ubyte # Represents a PCAN device
|
||||
TPCANMessageType = c_ubyte # Represents the type of a PCAN message
|
||||
TPCANType = c_ubyte # Represents the type of PCAN hardware to be initialized
|
||||
TPCANMode = c_ubyte # Represents a PCAN filter mode
|
||||
TPCANBaudrate = c_ushort # Represents a PCAN Baud rate register value
|
||||
TPCANBitrateFD = c_char_p # Represents a PCAN-FD bit rate string
|
||||
TPCANTimestampFD = c_ulonglong # Represents a timestamp of a received PCAN FD message
|
||||
|
||||
#///////////////////////////////////////////////////////////
|
||||
# Value definitions
|
||||
#///////////////////////////////////////////////////////////
|
||||
|
||||
# Currently defined and supported PCAN channels
|
||||
#
|
||||
PCAN_NONEBUS = TPCANHandle(0x00) # Undefined/default value for a PCAN bus
|
||||
|
||||
PCAN_ISABUS1 = TPCANHandle(0x21) # PCAN-ISA interface, channel 1
|
||||
PCAN_ISABUS2 = TPCANHandle(0x22) # PCAN-ISA interface, channel 2
|
||||
PCAN_ISABUS3 = TPCANHandle(0x23) # PCAN-ISA interface, channel 3
|
||||
PCAN_ISABUS4 = TPCANHandle(0x24) # PCAN-ISA interface, channel 4
|
||||
PCAN_ISABUS5 = TPCANHandle(0x25) # PCAN-ISA interface, channel 5
|
||||
PCAN_ISABUS6 = TPCANHandle(0x26) # PCAN-ISA interface, channel 6
|
||||
PCAN_ISABUS7 = TPCANHandle(0x27) # PCAN-ISA interface, channel 7
|
||||
PCAN_ISABUS8 = TPCANHandle(0x28) # PCAN-ISA interface, channel 8
|
||||
|
||||
PCAN_DNGBUS1 = TPCANHandle(0x31) # PCAN-Dongle/LPT interface, channel 1
|
||||
|
||||
PCAN_PCIBUS1 = TPCANHandle(0x41) # PCAN-PCI interface, channel 1
|
||||
PCAN_PCIBUS2 = TPCANHandle(0x42) # PCAN-PCI interface, channel 2
|
||||
PCAN_PCIBUS3 = TPCANHandle(0x43) # PCAN-PCI interface, channel 3
|
||||
PCAN_PCIBUS4 = TPCANHandle(0x44) # PCAN-PCI interface, channel 4
|
||||
PCAN_PCIBUS5 = TPCANHandle(0x45) # PCAN-PCI interface, channel 5
|
||||
PCAN_PCIBUS6 = TPCANHandle(0x46) # PCAN-PCI interface, channel 6
|
||||
PCAN_PCIBUS7 = TPCANHandle(0x47) # PCAN-PCI interface, channel 7
|
||||
PCAN_PCIBUS8 = TPCANHandle(0x48) # PCAN-PCI interface, channel 8
|
||||
PCAN_PCIBUS9 = TPCANHandle(0x409) # PCAN-PCI interface, channel 9
|
||||
PCAN_PCIBUS10 = TPCANHandle(0x40A) # PCAN-PCI interface, channel 10
|
||||
PCAN_PCIBUS11 = TPCANHandle(0x40B) # PCAN-PCI interface, channel 11
|
||||
PCAN_PCIBUS12 = TPCANHandle(0x40C) # PCAN-PCI interface, channel 12
|
||||
PCAN_PCIBUS13 = TPCANHandle(0x40D) # PCAN-PCI interface, channel 13
|
||||
PCAN_PCIBUS14 = TPCANHandle(0x40E) # PCAN-PCI interface, channel 14
|
||||
PCAN_PCIBUS15 = TPCANHandle(0x40F) # PCAN-PCI interface, channel 15
|
||||
PCAN_PCIBUS16 = TPCANHandle(0x410) # PCAN-PCI interface, channel 16
|
||||
|
||||
PCAN_USBBUS1 = TPCANHandle(0x51) # PCAN-USB interface, channel 1
|
||||
PCAN_USBBUS2 = TPCANHandle(0x52) # PCAN-USB interface, channel 2
|
||||
PCAN_USBBUS3 = TPCANHandle(0x53) # PCAN-USB interface, channel 3
|
||||
PCAN_USBBUS4 = TPCANHandle(0x54) # PCAN-USB interface, channel 4
|
||||
PCAN_USBBUS5 = TPCANHandle(0x55) # PCAN-USB interface, channel 5
|
||||
PCAN_USBBUS6 = TPCANHandle(0x56) # PCAN-USB interface, channel 6
|
||||
PCAN_USBBUS7 = TPCANHandle(0x57) # PCAN-USB interface, channel 7
|
||||
PCAN_USBBUS8 = TPCANHandle(0x58) # PCAN-USB interface, channel 8
|
||||
PCAN_USBBUS9 = TPCANHandle(0x509) # PCAN-USB interface, channel 9
|
||||
PCAN_USBBUS10 = TPCANHandle(0x50A) # PCAN-USB interface, channel 10
|
||||
PCAN_USBBUS11 = TPCANHandle(0x50B) # PCAN-USB interface, channel 11
|
||||
PCAN_USBBUS12 = TPCANHandle(0x50C) # PCAN-USB interface, channel 12
|
||||
PCAN_USBBUS13 = TPCANHandle(0x50D) # PCAN-USB interface, channel 13
|
||||
PCAN_USBBUS14 = TPCANHandle(0x50E) # PCAN-USB interface, channel 14
|
||||
PCAN_USBBUS15 = TPCANHandle(0x50F) # PCAN-USB interface, channel 15
|
||||
PCAN_USBBUS16 = TPCANHandle(0x510) # PCAN-USB interface, channel 16
|
||||
|
||||
PCAN_PCCBUS1 = TPCANHandle(0x61) # PCAN-PC Card interface, channel 1
|
||||
PCAN_PCCBUS2 = TPCANHandle(0x62) # PCAN-PC Card interface, channel 2
|
||||
|
||||
PCAN_LANBUS1 = TPCANHandle(0x801) # PCAN-LAN interface, channel 1
|
||||
PCAN_LANBUS2 = TPCANHandle(0x802) # PCAN-LAN interface, channel 2
|
||||
PCAN_LANBUS3 = TPCANHandle(0x803) # PCAN-LAN interface, channel 3
|
||||
PCAN_LANBUS4 = TPCANHandle(0x804) # PCAN-LAN interface, channel 4
|
||||
PCAN_LANBUS5 = TPCANHandle(0x805) # PCAN-LAN interface, channel 5
|
||||
PCAN_LANBUS6 = TPCANHandle(0x806) # PCAN-LAN interface, channel 6
|
||||
PCAN_LANBUS7 = TPCANHandle(0x807) # PCAN-LAN interface, channel 7
|
||||
PCAN_LANBUS8 = TPCANHandle(0x808) # PCAN-LAN interface, channel 8
|
||||
PCAN_LANBUS9 = TPCANHandle(0x809) # PCAN-LAN interface, channel 9
|
||||
PCAN_LANBUS10 = TPCANHandle(0x80A) # PCAN-LAN interface, channel 10
|
||||
PCAN_LANBUS11 = TPCANHandle(0x80B) # PCAN-LAN interface, channel 11
|
||||
PCAN_LANBUS12 = TPCANHandle(0x80C) # PCAN-LAN interface, channel 12
|
||||
PCAN_LANBUS13 = TPCANHandle(0x80D) # PCAN-LAN interface, channel 13
|
||||
PCAN_LANBUS14 = TPCANHandle(0x80E) # PCAN-LAN interface, channel 14
|
||||
PCAN_LANBUS15 = TPCANHandle(0x80F) # PCAN-LAN interface, channel 15
|
||||
PCAN_LANBUS16 = TPCANHandle(0x810) # PCAN-LAN interface, channel 16
|
||||
|
||||
# Represent the PCAN error and status codes
|
||||
#
|
||||
PCAN_ERROR_OK = TPCANStatus(0x00000) # No error
|
||||
PCAN_ERROR_XMTFULL = TPCANStatus(0x00001) # Transmit buffer in CAN controller is full
|
||||
PCAN_ERROR_OVERRUN = TPCANStatus(0x00002) # CAN controller was read too late
|
||||
PCAN_ERROR_BUSLIGHT = TPCANStatus(0x00004) # Bus error: an error counter reached the 'light' limit
|
||||
PCAN_ERROR_BUSHEAVY = TPCANStatus(0x00008) # Bus error: an error counter reached the 'heavy' limit
|
||||
PCAN_ERROR_BUSWARNING = TPCANStatus(PCAN_ERROR_BUSHEAVY) # Bus error: an error counter reached the 'warning' limit
|
||||
PCAN_ERROR_BUSPASSIVE = TPCANStatus(0x40000) # Bus error: the CAN controller is error passive
|
||||
PCAN_ERROR_BUSOFF = TPCANStatus(0x00010) # Bus error: the CAN controller is in bus-off state
|
||||
PCAN_ERROR_ANYBUSERR = TPCANStatus(PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE) # Mask for all bus errors
|
||||
PCAN_ERROR_QRCVEMPTY = TPCANStatus(0x00020) # Receive queue is empty
|
||||
PCAN_ERROR_QOVERRUN = TPCANStatus(0x00040) # Receive queue was read too late
|
||||
PCAN_ERROR_QXMTFULL = TPCANStatus(0x00080) # Transmit queue is full
|
||||
PCAN_ERROR_REGTEST = TPCANStatus(0x00100) # Test of the CAN controller hardware registers failed (no hardware found)
|
||||
PCAN_ERROR_NODRIVER = TPCANStatus(0x00200) # Driver not loaded
|
||||
PCAN_ERROR_HWINUSE = TPCANStatus(0x00400) # Hardware already in use by a Net
|
||||
PCAN_ERROR_NETINUSE = TPCANStatus(0x00800) # A Client is already connected to the Net
|
||||
PCAN_ERROR_ILLHW = TPCANStatus(0x01400) # Hardware handle is invalid
|
||||
PCAN_ERROR_ILLNET = TPCANStatus(0x01800) # Net handle is invalid
|
||||
PCAN_ERROR_ILLCLIENT = TPCANStatus(0x01C00) # Client handle is invalid
|
||||
PCAN_ERROR_ILLHANDLE = TPCANStatus(PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) # Mask for all handle errors
|
||||
PCAN_ERROR_RESOURCE = TPCANStatus(0x02000) # Resource (FIFO, Client, timeout) cannot be created
|
||||
PCAN_ERROR_ILLPARAMTYPE = TPCANStatus(0x04000) # Invalid parameter
|
||||
PCAN_ERROR_ILLPARAMVAL = TPCANStatus(0x08000) # Invalid parameter value
|
||||
PCAN_ERROR_UNKNOWN = TPCANStatus(0x10000) # Unknown error
|
||||
PCAN_ERROR_ILLDATA = TPCANStatus(0x20000) # Invalid data, function, or action
|
||||
PCAN_ERROR_ILLMODE = TPCANStatus(0x80000) # Driver object state is wrong for the attempted operation
|
||||
PCAN_ERROR_CAUTION = TPCANStatus(0x2000000)# An operation was successfully carried out, however, irregularities were registered
|
||||
PCAN_ERROR_INITIALIZE = TPCANStatus(0x4000000)# Channel is not initialized [Value was changed from 0x40000 to 0x4000000]
|
||||
PCAN_ERROR_ILLOPERATION = TPCANStatus(0x8000000)# Invalid operation [Value was changed from 0x80000 to 0x8000000]
|
||||
|
||||
# PCAN devices
|
||||
#
|
||||
PCAN_NONE = TPCANDevice(0x00) # Undefined, unknown or not selected PCAN device value
|
||||
PCAN_PEAKCAN = TPCANDevice(0x01) # PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API
|
||||
PCAN_ISA = TPCANDevice(0x02) # PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
|
||||
PCAN_DNG = TPCANDevice(0x03) # PCAN-Dongle
|
||||
PCAN_PCI = TPCANDevice(0x04) # PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
|
||||
PCAN_USB = TPCANDevice(0x05) # PCAN-USB and PCAN-USB Pro
|
||||
PCAN_PCC = TPCANDevice(0x06) # PCAN-PC Card
|
||||
PCAN_VIRTUAL = TPCANDevice(0x07) # PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API
|
||||
PCAN_LAN = TPCANDevice(0x08) # PCAN Gateway devices
|
||||
|
||||
# PCAN parameters
|
||||
#
|
||||
PCAN_DEVICE_ID = TPCANParameter(0x01) # Device identifier parameter
|
||||
PCAN_5VOLTS_POWER = TPCANParameter(0x02) # 5-Volt power parameter
|
||||
PCAN_RECEIVE_EVENT = TPCANParameter(0x03) # PCAN receive event handler parameter
|
||||
PCAN_MESSAGE_FILTER = TPCANParameter(0x04) # PCAN message filter parameter
|
||||
PCAN_API_VERSION = TPCANParameter(0x05) # PCAN-Basic API version parameter
|
||||
PCAN_CHANNEL_VERSION = TPCANParameter(0x06) # PCAN device channel version parameter
|
||||
PCAN_BUSOFF_AUTORESET = TPCANParameter(0x07) # PCAN Reset-On-Busoff parameter
|
||||
PCAN_LISTEN_ONLY = TPCANParameter(0x08) # PCAN Listen-Only parameter
|
||||
PCAN_LOG_LOCATION = TPCANParameter(0x09) # Directory path for log files
|
||||
PCAN_LOG_STATUS = TPCANParameter(0x0A) # Debug-Log activation status
|
||||
PCAN_LOG_CONFIGURE = TPCANParameter(0x0B) # Configuration of the debugged information (LOG_FUNCTION_***)
|
||||
PCAN_LOG_TEXT = TPCANParameter(0x0C) # Custom insertion of text into the log file
|
||||
PCAN_CHANNEL_CONDITION = TPCANParameter(0x0D) # Availability status of a PCAN-Channel
|
||||
PCAN_HARDWARE_NAME = TPCANParameter(0x0E) # PCAN hardware name parameter
|
||||
PCAN_RECEIVE_STATUS = TPCANParameter(0x0F) # Message reception status of a PCAN-Channel
|
||||
PCAN_CONTROLLER_NUMBER = TPCANParameter(0x10) # CAN-Controller number of a PCAN-Channel
|
||||
PCAN_TRACE_LOCATION = TPCANParameter(0x11) # Directory path for PCAN trace files
|
||||
PCAN_TRACE_STATUS = TPCANParameter(0x12) # CAN tracing activation status
|
||||
PCAN_TRACE_SIZE = TPCANParameter(0x13) # Configuration of the maximum file size of a CAN trace
|
||||
PCAN_TRACE_CONFIGURE = TPCANParameter(0x14) # Configuration of the trace file storing mode (TRACE_FILE_***)
|
||||
PCAN_CHANNEL_IDENTIFYING = TPCANParameter(0x15) # Physical identification of a USB based PCAN-Channel by blinking its associated LED
|
||||
PCAN_CHANNEL_FEATURES = TPCANParameter(0x16) # Capabilities of a PCAN device (FEATURE_***)
|
||||
PCAN_BITRATE_ADAPTING = TPCANParameter(0x17) # Using of an existing bit rate (PCAN-View connected to a channel)
|
||||
PCAN_BITRATE_INFO = TPCANParameter(0x18) # Configured bit rate as Btr0Btr1 value
|
||||
PCAN_BITRATE_INFO_FD = TPCANParameter(0x19) # Configured bit rate as TPCANBitrateFD string
|
||||
PCAN_BUSSPEED_NOMINAL = TPCANParameter(0x1A) # Configured nominal CAN Bus speed as Bits per seconds
|
||||
PCAN_BUSSPEED_DATA = TPCANParameter(0x1B) # Configured CAN data speed as Bits per seconds
|
||||
PCAN_IP_ADDRESS = TPCANParameter(0x1C) # Remote address of a LAN channel as string in IPv4 format
|
||||
PCAN_LAN_SERVICE_STATUS = TPCANParameter(0x1D) # Status of the Virtual PCAN-Gateway Service
|
||||
PCAN_ALLOW_STATUS_FRAMES = TPCANParameter(0x1E) # Status messages reception status within a PCAN-Channel
|
||||
PCAN_ALLOW_RTR_FRAMES = TPCANParameter(0x1F) # RTR messages reception status within a PCAN-Channel
|
||||
PCAN_ALLOW_ERROR_FRAMES = TPCANParameter(0x20) # Error messages reception status within a PCAN-Channel
|
||||
PCAN_INTERFRAME_DELAY = TPCANParameter(0x21) # Delay, in microseconds, between sending frames
|
||||
PCAN_ACCEPTANCE_FILTER_11BIT = TPCANParameter(0x22) # Filter over code and mask patterns for 11-Bit messages
|
||||
PCAN_ACCEPTANCE_FILTER_29BIT = TPCANParameter(0x23) # Filter over code and mask patterns for 29-Bit messages
|
||||
PCAN_IO_DIGITAL_CONFIGURATION = TPCANParameter(0x24) # Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive
|
||||
PCAN_IO_DIGITAL_VALUE = TPCANParameter(0x25) # Value assigned to a 32 digital I/O pins of a PCAN-USB Chip
|
||||
PCAN_IO_DIGITAL_SET = TPCANParameter(0x26) # Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High
|
||||
PCAN_IO_DIGITAL_CLEAR = TPCANParameter(0x27) # Clear multiple digital I/O pins to 0
|
||||
PCAN_IO_ANALOG_VALUE = TPCANParameter(0x28) # Get value of a single analog input pin
|
||||
PCAN_FIRMWARE_VERSION = TPCANParameter(0x29) # Get the version of the firmware used by the device associated with a PCAN-Channel
|
||||
PCAN_ATTACHED_CHANNELS_COUNT = TPCANParameter(0x2A) # Get the amount of PCAN channels attached to a system
|
||||
PCAN_ATTACHED_CHANNELS = TPCANParameter(0x2B) # Get information about PCAN channels attached to a system
|
||||
PCAN_ALLOW_ECHO_FRAMES = TPCANParameter(0x2C) # Echo messages reception status within a PCAN-Channel
|
||||
PCAN_DEVICE_PART_NUMBER = TPCANParameter(0x2D) # Get the part number associated to a device
|
||||
|
||||
# DEPRECATED parameters
|
||||
#
|
||||
PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID # DEPRECATED. Use PCAN_DEVICE_ID instead
|
||||
|
||||
# PCAN parameter values
|
||||
#
|
||||
PCAN_PARAMETER_OFF = int(0x00) # The PCAN parameter is not set (inactive)
|
||||
PCAN_PARAMETER_ON = int(0x01) # The PCAN parameter is set (active)
|
||||
PCAN_FILTER_CLOSE = int(0x00) # The PCAN filter is closed. No messages will be received
|
||||
PCAN_FILTER_OPEN = int(0x01) # The PCAN filter is fully opened. All messages will be received
|
||||
PCAN_FILTER_CUSTOM = int(0x02) # The PCAN filter is custom configured. Only registered messages will be received
|
||||
PCAN_CHANNEL_UNAVAILABLE = int(0x00) # The PCAN-Channel handle is illegal, or its associated hardware is not available
|
||||
PCAN_CHANNEL_AVAILABLE = int(0x01) # The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in)
|
||||
PCAN_CHANNEL_OCCUPIED = int(0x02) # The PCAN-Channel handle is valid, and is already being used
|
||||
PCAN_CHANNEL_PCANVIEW = PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED # The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect
|
||||
|
||||
LOG_FUNCTION_DEFAULT = int(0x00) # Logs system exceptions / errors
|
||||
LOG_FUNCTION_ENTRY = int(0x01) # Logs the entries to the PCAN-Basic API functions
|
||||
LOG_FUNCTION_PARAMETERS = int(0x02) # Logs the parameters passed to the PCAN-Basic API functions
|
||||
LOG_FUNCTION_LEAVE = int(0x04) # Logs the exits from the PCAN-Basic API functions
|
||||
LOG_FUNCTION_WRITE = int(0x08) # Logs the CAN messages passed to the CAN_Write function
|
||||
LOG_FUNCTION_READ = int(0x10) # Logs the CAN messages received within the CAN_Read function
|
||||
LOG_FUNCTION_ALL = int(0xFFFF) # Logs all possible information within the PCAN-Basic API functions
|
||||
|
||||
TRACE_FILE_SINGLE = int(0x00) # A single file is written until it size reaches PAN_TRACE_SIZE
|
||||
TRACE_FILE_SEGMENTED = int(0x01) # Traced data is distributed in several files with size PAN_TRACE_SIZE
|
||||
TRACE_FILE_DATE = int(0x02) # Includes the date into the name of the trace file
|
||||
TRACE_FILE_TIME = int(0x04) # Includes the start time into the name of the trace file
|
||||
TRACE_FILE_OVERWRITE = int(0x80) # Causes the overwriting of available traces (same name)
|
||||
|
||||
FEATURE_FD_CAPABLE = int(0x01) # Device supports flexible data-rate (CAN-FD)
|
||||
FEATURE_DELAY_CAPABLE = int(0x02) # Device supports a delay between sending frames (FPGA based USB devices)
|
||||
FEATURE_IO_CAPABLE = int(0x04) # Device supports I/O functionality for electronic circuits (USB-Chip devices)
|
||||
|
||||
SERVICE_STATUS_STOPPED = int(0x01) # The service is not running
|
||||
SERVICE_STATUS_RUNNING = int(0x04) # The service is running
|
||||
|
||||
# Other constants
|
||||
#
|
||||
MAX_LENGTH_HARDWARE_NAME = int(33) # Maximum length of the name of a device: 32 characters + terminator
|
||||
MAX_LENGTH_VERSION_STRING = int(256) # Maximum length of a version string: 255 characters + terminator
|
||||
|
||||
# PCAN message types
|
||||
#
|
||||
PCAN_MESSAGE_STANDARD = TPCANMessageType(0x00) # The PCAN message is a CAN Standard Frame (11-bit identifier)
|
||||
PCAN_MESSAGE_RTR = TPCANMessageType(0x01) # The PCAN message is a CAN Remote-Transfer-Request Frame
|
||||
PCAN_MESSAGE_EXTENDED = TPCANMessageType(0x02) # The PCAN message is a CAN Extended Frame (29-bit identifier)
|
||||
PCAN_MESSAGE_FD = TPCANMessageType(0x04) # The PCAN message represents a FD frame in terms of CiA Specs
|
||||
PCAN_MESSAGE_BRS = TPCANMessageType(0x08) # The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate)
|
||||
PCAN_MESSAGE_ESI = TPCANMessageType(0x10) # The PCAN message represents a FD error state indicator(CAN FD transmitter was error active)
|
||||
PCAN_MESSAGE_ECHO = TPCANMessageType(0x20) # The PCAN message represents an echo CAN Frame
|
||||
PCAN_MESSAGE_ERRFRAME = TPCANMessageType(0x40) # The PCAN message represents an error frame
|
||||
PCAN_MESSAGE_STATUS = TPCANMessageType(0x80) # The PCAN message represents a PCAN status message
|
||||
|
||||
# LookUp Parameters
|
||||
#
|
||||
LOOKUP_DEVICE_TYPE = b"devicetype" # Lookup channel by Device type (see PCAN devices e.g. PCAN_USB)
|
||||
LOOKUP_DEVICE_ID = b"deviceid" # Lookup channel by device id
|
||||
LOOKUP_CONTROLLER_NUMBER = b"controllernumber" # Lookup channel by CAN controller 0-based index
|
||||
LOOKUP_IP_ADDRESS = b"ipaddress" # Lookup channel by IP address (LAN channels only)
|
||||
|
||||
# Frame Type / Initialization Mode
|
||||
#
|
||||
PCAN_MODE_STANDARD = PCAN_MESSAGE_STANDARD
|
||||
PCAN_MODE_EXTENDED = PCAN_MESSAGE_EXTENDED
|
||||
|
||||
# Baud rate codes = BTR0/BTR1 register values for the CAN controller.
|
||||
# You can define your own Baud rate with the BTROBTR1 register.
|
||||
# Take a look at www.peak-system.com for our free software "BAUDTOOL"
|
||||
# to calculate the BTROBTR1 register for every bit rate and sample point.
|
||||
#
|
||||
PCAN_BAUD_1M = TPCANBaudrate(0x0014) # 1 MBit/s
|
||||
PCAN_BAUD_800K = TPCANBaudrate(0x0016) # 800 kBit/s
|
||||
PCAN_BAUD_500K = TPCANBaudrate(0x001C) # 500 kBit/s
|
||||
PCAN_BAUD_250K = TPCANBaudrate(0x011C) # 250 kBit/s
|
||||
PCAN_BAUD_125K = TPCANBaudrate(0x031C) # 125 kBit/s
|
||||
PCAN_BAUD_100K = TPCANBaudrate(0x432F) # 100 kBit/s
|
||||
PCAN_BAUD_95K = TPCANBaudrate(0xC34E) # 95,238 kBit/s
|
||||
PCAN_BAUD_83K = TPCANBaudrate(0x852B) # 83,333 kBit/s
|
||||
PCAN_BAUD_50K = TPCANBaudrate(0x472F) # 50 kBit/s
|
||||
PCAN_BAUD_47K = TPCANBaudrate(0x1414) # 47,619 kBit/s
|
||||
PCAN_BAUD_33K = TPCANBaudrate(0x8B2F) # 33,333 kBit/s
|
||||
PCAN_BAUD_20K = TPCANBaudrate(0x532F) # 20 kBit/s
|
||||
PCAN_BAUD_10K = TPCANBaudrate(0x672F) # 10 kBit/s
|
||||
PCAN_BAUD_5K = TPCANBaudrate(0x7F7F) # 5 kBit/s
|
||||
|
||||
# Represents the configuration for a CAN bit rate
|
||||
# Note:
|
||||
# * Each parameter and its value must be separated with a '='.
|
||||
# * Each pair of parameter/value must be separated using ','.
|
||||
#
|
||||
# Example:
|
||||
# f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1
|
||||
#
|
||||
PCAN_BR_CLOCK = TPCANBitrateFD(b"f_clock")
|
||||
PCAN_BR_CLOCK_MHZ = TPCANBitrateFD(b"f_clock_mhz")
|
||||
PCAN_BR_NOM_BRP = TPCANBitrateFD(b"nom_brp")
|
||||
PCAN_BR_NOM_TSEG1 = TPCANBitrateFD(b"nom_tseg1")
|
||||
PCAN_BR_NOM_TSEG2 = TPCANBitrateFD(b"nom_tseg2")
|
||||
PCAN_BR_NOM_SJW = TPCANBitrateFD(b"nom_sjw")
|
||||
PCAN_BR_NOM_SAMPLE = TPCANBitrateFD(b"nom_sam")
|
||||
PCAN_BR_DATA_BRP = TPCANBitrateFD(b"data_brp")
|
||||
PCAN_BR_DATA_TSEG1 = TPCANBitrateFD(b"data_tseg1")
|
||||
PCAN_BR_DATA_TSEG2 = TPCANBitrateFD(b"data_tseg2")
|
||||
PCAN_BR_DATA_SJW = TPCANBitrateFD(b"data_sjw")
|
||||
PCAN_BR_DATA_SAMPLE = TPCANBitrateFD(b"data_ssp_offset")
|
||||
|
||||
# Supported Non-PnP Hardware types
|
||||
#
|
||||
PCAN_TYPE_ISA = TPCANType(0x01) # PCAN-ISA 82C200
|
||||
PCAN_TYPE_ISA_SJA = TPCANType(0x09) # PCAN-ISA SJA1000
|
||||
PCAN_TYPE_ISA_PHYTEC = TPCANType(0x04) # PHYTEC ISA
|
||||
PCAN_TYPE_DNG = TPCANType(0x02) # PCAN-Dongle 82C200
|
||||
PCAN_TYPE_DNG_EPP = TPCANType(0x03) # PCAN-Dongle EPP 82C200
|
||||
PCAN_TYPE_DNG_SJA = TPCANType(0x05) # PCAN-Dongle SJA1000
|
||||
PCAN_TYPE_DNG_SJA_EPP = TPCANType(0x06) # PCAN-Dongle EPP SJA1000
|
||||
|
||||
# Represents a PCAN message
|
||||
#
|
||||
class TPCANMsg (Structure):
|
||||
"""
|
||||
Represents a PCAN message
|
||||
"""
|
||||
_fields_ = [ ("ID", c_uint), # 11/29-bit message identifier
|
||||
("MSGTYPE", TPCANMessageType), # Type of the message
|
||||
("LEN", c_ubyte), # Data Length Code of the message (0..8)
|
||||
("DATA", c_ubyte * 8) ] # Data of the message (DATA[0]..DATA[7])
|
||||
|
||||
# Represents a timestamp of a received PCAN message
|
||||
# Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
|
||||
#
|
||||
class TPCANTimestamp (Structure):
|
||||
"""
|
||||
Represents a timestamp of a received PCAN message
|
||||
Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
|
||||
"""
|
||||
_fields_ = [ ("millis", c_uint), # Base-value: milliseconds: 0.. 2^32-1
|
||||
("millis_overflow", c_ushort), # Roll-arounds of millis
|
||||
("micros", c_ushort) ] # Microseconds: 0..999
|
||||
|
||||
# Represents a PCAN message from a FD capable hardware
|
||||
#
|
||||
class TPCANMsgFD (Structure):
|
||||
"""
|
||||
Represents a PCAN message
|
||||
"""
|
||||
_fields_ = [ ("ID", c_uint), # 11/29-bit message identifier
|
||||
("MSGTYPE", TPCANMessageType), # Type of the message
|
||||
("DLC", c_ubyte), # Data Length Code of the message (0..15)
|
||||
("DATA", c_ubyte * 64) ] # Data of the message (DATA[0]..DATA[63])
|
||||
|
||||
# Describes an available PCAN channel
|
||||
#
|
||||
class TPCANChannelInformation (Structure):
|
||||
"""
|
||||
Describes an available PCAN channel
|
||||
"""
|
||||
_fields_ = [ ("channel_handle", TPCANHandle), # PCAN channel handle
|
||||
("device_type", TPCANDevice), # Kind of PCAN device
|
||||
("controller_number", c_ubyte), # CAN-Controller number
|
||||
("device_features", c_uint), # Device capabilities flag (see FEATURE_*)
|
||||
("device_name", c_char * MAX_LENGTH_HARDWARE_NAME), # Device name
|
||||
("device_id", c_uint), # Device number
|
||||
("channel_condition", c_uint) ] # Availability status of a PCAN-Channel
|
||||
|
||||
#///////////////////////////////////////////////////////////
|
||||
# PCAN-Basic API function declarations
|
||||
#///////////////////////////////////////////////////////////
|
||||
|
||||
# PCAN-Basic API class implementation
|
||||
#
|
||||
class PCANBasic:
|
||||
"""
|
||||
PCAN-Basic API class implementation
|
||||
"""
|
||||
def __init__(self):
|
||||
# Loads the PCANBasic API
|
||||
#
|
||||
if platform.system() == 'Windows':
|
||||
# Loads the API on Windows
|
||||
self.__m_dllBasic = windll.LoadLibrary("PCANBasic")
|
||||
elif platform.system() == 'Linux':
|
||||
# Loads the API on Linux
|
||||
self.__m_dllBasic = cdll.LoadLibrary("libpcanbasic.so")
|
||||
elif platform.system() == 'Darwin':
|
||||
# Loads the API on Mac
|
||||
#
|
||||
# NOTE:
|
||||
# ~~~~~
|
||||
# The macOS library for PCAN-USB interfaces from PEAK-System, PCBUSB library,
|
||||
# is a third-party software creaded and mantained by the MacCAN project. For
|
||||
# information and support, please contact MacCAN (info@mac-can).
|
||||
#
|
||||
self.__m_dllBasic = cdll.LoadLibrary("libPCBUSB.dylib")
|
||||
|
||||
if self.__m_dllBasic == None:
|
||||
print ("Exception: The PCAN-Basic DLL couldn't be loaded!")
|
||||
|
||||
# Initializes a PCAN Channel
|
||||
#
|
||||
def Initialize(
|
||||
self,
|
||||
Channel,
|
||||
Btr0Btr1,
|
||||
HwType = TPCANType(0),
|
||||
IOPort = c_uint(0),
|
||||
Interrupt = c_ushort(0)):
|
||||
|
||||
"""
|
||||
Initializes a PCAN Channel
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
Btr0Btr1 : The speed for the communication (BTR0BTR1 code)
|
||||
HwType : Non-PnP: The type of hardware and operation mode
|
||||
IOPort : Non-PnP: The I/O address for the parallel port
|
||||
Interrupt: Non-PnP: Interrupt number of the parallel port
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_Initialize(Channel,Btr0Btr1,HwType,IOPort,Interrupt)
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.Initialize")
|
||||
raise
|
||||
|
||||
# Initializes a FD capable PCAN Channel
|
||||
#
|
||||
def InitializeFD(
|
||||
self,
|
||||
Channel,
|
||||
BitrateFD):
|
||||
|
||||
"""
|
||||
Initializes a FD capable PCAN Channel
|
||||
|
||||
Parameters:
|
||||
Channel : The handle of a FD capable PCAN Channel
|
||||
BitrateFD : The speed for the communication (FD bit rate string)
|
||||
|
||||
Remarks:
|
||||
See PCAN_BR_* values.
|
||||
* parameter and values must be separated by '='
|
||||
* Couples of Parameter/value must be separated by ','
|
||||
* Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2,
|
||||
nom_brp, nom_sjw, nom_tseg1, nom_tseg2.
|
||||
* Following Parameters are optional (not used yet): data_ssp_offset, nom_sam
|
||||
|
||||
Example:
|
||||
f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_InitializeFD(Channel,BitrateFD)
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.InitializeFD")
|
||||
raise
|
||||
|
||||
# Uninitializes one or all PCAN Channels initialized by CAN_Initialize
|
||||
#
|
||||
def Uninitialize(
|
||||
self,
|
||||
Channel):
|
||||
|
||||
"""
|
||||
Uninitializes one or all PCAN Channels initialized by CAN_Initialize
|
||||
|
||||
Remarks:
|
||||
Giving the TPCANHandle value "PCAN_NONEBUS", uninitialize all initialized channels
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_Uninitialize(Channel)
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.Uninitialize")
|
||||
raise
|
||||
|
||||
# Resets the receive and transmit queues of the PCAN Channel
|
||||
#
|
||||
def Reset(
|
||||
self,
|
||||
Channel):
|
||||
|
||||
"""
|
||||
Resets the receive and transmit queues of the PCAN Channel
|
||||
|
||||
Remarks:
|
||||
A reset of the CAN controller is not performed
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_Reset(Channel)
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.Reset")
|
||||
raise
|
||||
|
||||
# Gets the current status of a PCAN Channel
|
||||
#
|
||||
def GetStatus(
|
||||
self,
|
||||
Channel):
|
||||
|
||||
"""
|
||||
Gets the current status of a PCAN Channel
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_GetStatus(Channel)
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.GetStatus")
|
||||
raise
|
||||
|
||||
# Reads a CAN message from the receive queue of a PCAN Channel
|
||||
#
|
||||
def Read(
|
||||
self,
|
||||
Channel):
|
||||
|
||||
"""
|
||||
Reads a CAN message from the receive queue of a PCAN Channel
|
||||
|
||||
Remarks:
|
||||
The return value of this method is a 3-touple, where
|
||||
the first value is the result (TPCANStatus) of the method.
|
||||
The order of the values are:
|
||||
[0]: A TPCANStatus error code
|
||||
[1]: A TPCANMsg structure with the CAN message read
|
||||
[2]: A TPCANTimestamp structure with the time when a message was read
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
|
||||
Returns:
|
||||
A touple with three values
|
||||
"""
|
||||
try:
|
||||
msg = TPCANMsg()
|
||||
timestamp = TPCANTimestamp()
|
||||
res = self.__m_dllBasic.CAN_Read(Channel,byref(msg),byref(timestamp))
|
||||
return TPCANStatus(res),msg,timestamp
|
||||
except:
|
||||
print ("Exception on PCANBasic.Read")
|
||||
raise
|
||||
|
||||
# Reads a CAN message from the receive queue of a FD capable PCAN Channel
|
||||
#
|
||||
def ReadFD(
|
||||
self,
|
||||
Channel):
|
||||
|
||||
"""
|
||||
Reads a CAN message from the receive queue of a FD capable PCAN Channel
|
||||
|
||||
Remarks:
|
||||
The return value of this method is a 3-touple, where
|
||||
the first value is the result (TPCANStatus) of the method.
|
||||
The order of the values are:
|
||||
[0]: A TPCANStatus error code
|
||||
[1]: A TPCANMsgFD structure with the CAN message read
|
||||
[2]: A TPCANTimestampFD that is the time when a message was read
|
||||
|
||||
Parameters:
|
||||
Channel : The handle of a FD capable PCAN Channel
|
||||
|
||||
Returns:
|
||||
A touple with three values
|
||||
"""
|
||||
try:
|
||||
msg = TPCANMsgFD()
|
||||
timestamp = TPCANTimestampFD()
|
||||
res = self.__m_dllBasic.CAN_ReadFD(Channel,byref(msg),byref(timestamp))
|
||||
return TPCANStatus(res),msg,timestamp
|
||||
except:
|
||||
print ("Exception on PCANBasic.ReadFD")
|
||||
raise
|
||||
|
||||
# Transmits a CAN message
|
||||
#
|
||||
def Write(
|
||||
self,
|
||||
Channel,
|
||||
MessageBuffer):
|
||||
|
||||
"""
|
||||
Transmits a CAN message
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
MessageBuffer: A TPCANMsg representing the CAN message to be sent
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_Write(Channel,byref(MessageBuffer))
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.Write")
|
||||
raise
|
||||
|
||||
# Transmits a CAN message over a FD capable PCAN Channel
|
||||
#
|
||||
def WriteFD(
|
||||
self,
|
||||
Channel,
|
||||
MessageBuffer):
|
||||
|
||||
"""
|
||||
Transmits a CAN message over a FD capable PCAN Channel
|
||||
|
||||
Parameters:
|
||||
Channel : The handle of a FD capable PCAN Channel
|
||||
MessageBuffer: A TPCANMsgFD buffer with the message to be sent
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_WriteFD(Channel,byref(MessageBuffer))
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.WriteFD")
|
||||
raise
|
||||
|
||||
# Configures the reception filter
|
||||
#
|
||||
def FilterMessages(
|
||||
self,
|
||||
Channel,
|
||||
FromID,
|
||||
ToID,
|
||||
Mode):
|
||||
|
||||
"""
|
||||
Configures the reception filter
|
||||
|
||||
Remarks:
|
||||
The message filter will be expanded with every call to this function.
|
||||
If it is desired to reset the filter, please use the 'SetValue' function.
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
FromID : A c_uint value with the lowest CAN ID to be received
|
||||
ToID : A c_uint value with the highest CAN ID to be received
|
||||
Mode : A TPCANMode representing the message type (Standard, 11-bit
|
||||
identifier, or Extended, 29-bit identifier)
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
res = self.__m_dllBasic.CAN_FilterMessages(Channel,FromID,ToID,Mode)
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.FilterMessages")
|
||||
raise
|
||||
|
||||
# Retrieves a PCAN Channel value
|
||||
#
|
||||
def GetValue(
|
||||
self,
|
||||
Channel,
|
||||
Parameter):
|
||||
|
||||
"""
|
||||
Retrieves a PCAN Channel value
|
||||
|
||||
Remarks:
|
||||
Parameters can be present or not according with the kind
|
||||
of Hardware (PCAN Channel) being used. If a parameter is not available,
|
||||
a PCAN_ERROR_ILLPARAMTYPE error will be returned.
|
||||
|
||||
The return value of this method is a 2-touple, where
|
||||
the first value is the result (TPCANStatus) of the method and
|
||||
the second one, the asked value
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
Parameter : The TPCANParameter parameter to get
|
||||
|
||||
Returns:
|
||||
A touple with 2 values
|
||||
"""
|
||||
try:
|
||||
if Parameter == PCAN_API_VERSION or Parameter == PCAN_HARDWARE_NAME or Parameter == PCAN_CHANNEL_VERSION or Parameter == PCAN_LOG_LOCATION or Parameter == PCAN_TRACE_LOCATION or Parameter == PCAN_BITRATE_INFO_FD or Parameter == PCAN_IP_ADDRESS or Parameter == PCAN_FIRMWARE_VERSION or Parameter == PCAN_DEVICE_PART_NUMBER:
|
||||
mybuffer = create_string_buffer(256)
|
||||
|
||||
elif Parameter == PCAN_ATTACHED_CHANNELS:
|
||||
res = self.GetValue(Channel, PCAN_ATTACHED_CHANNELS_COUNT)
|
||||
if TPCANStatus(res[0]) != PCAN_ERROR_OK:
|
||||
return TPCANStatus(res[0]),
|
||||
mybuffer = (TPCANChannelInformation * res[1])()
|
||||
|
||||
elif Parameter == PCAN_ACCEPTANCE_FILTER_11BIT or PCAN_ACCEPTANCE_FILTER_29BIT:
|
||||
mybuffer = c_int64(0)
|
||||
|
||||
else:
|
||||
mybuffer = c_int(0)
|
||||
|
||||
res = self.__m_dllBasic.CAN_GetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer))
|
||||
if Parameter == PCAN_ATTACHED_CHANNELS:
|
||||
return TPCANStatus(res),mybuffer
|
||||
else:
|
||||
return TPCANStatus(res),mybuffer.value
|
||||
except:
|
||||
print ("Exception on PCANBasic.GetValue")
|
||||
raise
|
||||
|
||||
# Returns a descriptive text of a given TPCANStatus
|
||||
# error code, in any desired language
|
||||
#
|
||||
def SetValue(
|
||||
self,
|
||||
Channel,
|
||||
Parameter,
|
||||
Buffer):
|
||||
|
||||
"""
|
||||
Configures or sets a PCAN Channel value
|
||||
|
||||
Remarks:
|
||||
Parameters can be present or not according with the kind
|
||||
of Hardware (PCAN Channel) being used. If a parameter is not available,
|
||||
a PCAN_ERROR_ILLPARAMTYPE error will be returned.
|
||||
|
||||
Parameters:
|
||||
Channel : A TPCANHandle representing a PCAN Channel
|
||||
Parameter : The TPCANParameter parameter to set
|
||||
Buffer : Buffer with the value to be set
|
||||
BufferLength : Size in bytes of the buffer
|
||||
|
||||
Returns:
|
||||
A TPCANStatus error code
|
||||
"""
|
||||
try:
|
||||
if Parameter == PCAN_LOG_LOCATION or Parameter == PCAN_LOG_TEXT or Parameter == PCAN_TRACE_LOCATION:
|
||||
mybuffer = create_string_buffer(256)
|
||||
elif Parameter == PCAN_ACCEPTANCE_FILTER_11BIT or PCAN_ACCEPTANCE_FILTER_29BIT:
|
||||
mybuffer = c_int64(0)
|
||||
else:
|
||||
mybuffer = c_int(0)
|
||||
|
||||
mybuffer.value = Buffer
|
||||
res = self.__m_dllBasic.CAN_SetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer))
|
||||
return TPCANStatus(res)
|
||||
except:
|
||||
print ("Exception on PCANBasic.SetValue")
|
||||
raise
|
||||
|
||||
def GetErrorText(
|
||||
self,
|
||||
Error,
|
||||
Language = 0):
|
||||
|
||||
"""
|
||||
Returns a descriptive text of a given TPCANStatus error
|
||||
code, in any desired language
|
||||
|
||||
Remarks:
|
||||
|
||||
The current languages available for translation are:
|
||||
Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
|
||||
Italian (0x10) and French (0x0C)
|
||||
|
||||
The return value of this method is a 2-touple, where
|
||||
the first value is the result (TPCANStatus) of the method and
|
||||
the second one, the error text
|
||||
|
||||
Parameters:
|
||||
Error : A TPCANStatus error code
|
||||
Language : Indicates a 'Primary language ID' (Default is Neutral(0))
|
||||
|
||||
Returns:
|
||||
A touple with 2 values
|
||||
"""
|
||||
try:
|
||||
mybuffer = create_string_buffer(256)
|
||||
res = self.__m_dllBasic.CAN_GetErrorText(Error,Language,byref(mybuffer))
|
||||
return TPCANStatus(res),mybuffer.value
|
||||
except:
|
||||
print ("Exception on PCANBasic.GetErrorText")
|
||||
raise
|
||||
|
||||
def LookUpChannel(
|
||||
self,
|
||||
Parameters):
|
||||
|
||||
"""
|
||||
Finds a PCAN-Basic channel that matches with the given parameters
|
||||
|
||||
Remarks:
|
||||
|
||||
The return value of this method is a 2-touple, where
|
||||
the first value is the result (TPCANStatus) of the method and
|
||||
the second one a TPCANHandle value
|
||||
|
||||
Parameters:
|
||||
Parameters : A comma separated string contained pairs of parameter-name/value
|
||||
to be matched within a PCAN-Basic channel
|
||||
|
||||
Returns:
|
||||
A touple with 2 values
|
||||
"""
|
||||
try:
|
||||
mybuffer = TPCANHandle(0)
|
||||
res = self.__m_dllBasic.CAN_LookUpChannel(Parameters,byref(mybuffer))
|
||||
return TPCANStatus(res),mybuffer
|
||||
except:
|
||||
print ("Exception on PCANBasic.LookUpChannel")
|
||||
raise
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user