commit 12d88f9a73190840bff149cddd4230b9f33a2762 Author: jfmartel Date: Fri Jan 6 12:25:54 2023 -0500 Création du repo et ajout de la librairie PCAN diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96d640a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.pro.user +*~* diff --git a/PCAN API/PCAN-Basic API/ARM64/PCANBasic.dll b/PCAN API/PCAN-Basic API/ARM64/PCANBasic.dll new file mode 100644 index 0000000..bb27706 Binary files /dev/null and b/PCAN API/PCAN-Basic API/ARM64/PCANBasic.dll differ diff --git a/PCAN API/PCAN-Basic API/ARM64/PCANBasicExample.exe b/PCAN API/PCAN-Basic API/ARM64/PCANBasicExample.exe new file mode 100644 index 0000000..c271e9e Binary files /dev/null and b/PCAN API/PCAN-Basic API/ARM64/PCANBasicExample.exe differ diff --git a/PCAN API/PCAN-Basic API/ARM64/VC_LIB/PCANBasic.lib b/PCAN API/PCAN-Basic API/ARM64/VC_LIB/PCANBasic.lib new file mode 100644 index 0000000..a1a59aa Binary files /dev/null and b/PCAN API/PCAN-Basic API/ARM64/VC_LIB/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Include/PCANBasic.bas b/PCAN API/PCAN-Basic API/Include/PCANBasic.bas new file mode 100644 index 0000000..630c9c7 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Include/PCANBasic.bas @@ -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 + +''' +''' Initializes a PCAN Channel +''' +''' "The handle of a PCAN Channel" +''' "The speed for the communication (BTR0BTR1 code)" +''' "Non-PnP: The type of hardware and operation mode" +''' "Non-PnP: The I/O address for the parallel port" +''' "Non-PnP: Interrupt number of the parallel port" +''' "A TPCANStatus error code" +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 + + +''' +''' Initializes a FD capable PCAN Channel +''' +''' "The handle of a FD capable PCAN Channel" +''' "The speed for the communication (FD bit rate string)" +''' 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 +''' +''' 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 +''' "A TPCANStatus error code" +Public Declare Function CAN_InitializeFD Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer, _ + ByVal BitrateFD As String) As Long + + +''' +''' Uninitializes one or all PCAN Channels initialized by CAN_Initialize +''' +''' Giving the TPCANHandle value "PCAN_NONEBUS", +''' uninitialize all initialized channels +''' "The handle of a PCAN Channel" +''' "A TPCANStatus error code" +Public Declare Function CAN_Uninitialize Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer) As Long + + +''' +''' Resets the receive and transmit queues of the PCAN Channel +''' +''' +''' A reset of the CAN controller is not performed. +''' +''' "The handle of a PCAN Channel" +''' "A TPCANStatus error code" +Public Declare Function CAN_Reset Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer) As Long + + +''' +''' Gets the current status of a PCAN Channel +''' +''' "The handle of a PCAN Channel" +''' "A TPCANStatus error code" +Public Declare Function CAN_GetStatus Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer) As Long + + +''' +''' Reads a CAN message from the receive queue of a PCAN Channel +''' +''' "The handle of a PCAN Channel" +''' "A TPCANMsg structure buffer to store the CAN message" +''' "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" +''' "A TPCANStatus error code" +Public Declare Function CAN_Read Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer, _ + ByRef MessageBuffer As TPCANMsg, _ + ByRef TimestampBuffer As TPCANTimestamp) As Long + + +''' +''' Reads a CAN message from the receive queue of a FD capable PCAN Channel +''' +''' "The handle of a FD capable PCAN Channel" +''' "A TPCANMsgFD structure buffer to store the CAN message" +''' "A TPCANTimestampFD buffer to get +''' the reception time of the message. If this value is not desired, this parameter +''' should be passed as NULL" +''' "A TPCANStatus error code" +Public Declare Function CAN_ReadFD Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer, + ByRef MessageBuffer As TPCANMsgFD, + ByRef TimestampBuffer As Long) As Long + + +''' +''' Transmits a CAN message over a FD capable PCAN Channel +''' +''' "The handle of a FD capable PCAN Channel" +''' "A TPCANMsgFD buffer with the message to be sent" +''' "A TPCANStatus error code" +Public Declare Function CAN_WriteFD Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer, _ + ByRef MessageBuffer As TPCANMsgFD) As Long + + +''' +''' Transmits a CAN message +''' +''' "The handle of a PCAN Channel" +''' "A TPCANMsg buffer with the message to be sent" +''' "A TPCANStatus error code" +Public Declare Function CAN_Write Lib "PCANBasic.DLL" _ + (ByVal Channel As Integer, _ + ByRef MessageBuffer As TPCANMsg) As Long + + +''' +''' Configures the reception filter. +''' +''' 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 +''' "The handle of a PCAN Channel" +''' "The lowest CAN ID to be received" +''' "The highest CAN ID to be received" +''' "Message type, Standard (11-bit identifier) or +''' Extended (29-bit identifier)" +''' "A TPCANStatus error code" +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 + + +''' +''' Retrieves a PCAN Channel value +''' +''' 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 handle of a PCAN Channel" +''' "The TPCANParameter parameter to get" +''' "Buffer for the parameter value" +''' "Size in bytes of the buffer" +''' "A TPCANStatus error code" +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 + + +''' +''' Configures or sets a PCAN Channel value +''' +''' 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 handle of a PCAN Channel" +''' "The TPCANParameter parameter to set" +''' "Buffer with the value to be set" +''' "Size in bytes of the buffer" +''' "A TPCANStatus error code" +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 + + +''' +''' Returns a descriptive text of a given TPCANStatus error +''' code, in any desired language +''' +''' The current languages available for translation are: +''' Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +''' Italian (0x10) and French (0x0C) +''' "A TPCANStatus error code" +''' "Indicates a 'Primary language ID'" +''' "Buffer for a null terminated char array" +''' "A TPCANStatus error code" +Public Declare Function CAN_GetErrorText Lib "PCANBasic.DLL" _ + (ByVal ErrorCode As Long, + ByVal Language As Integer, + ByVal Buffer As String) As Long + +''' +''' Finds a PCAN-Basic channel that matches with the given parameters +''' +''' A comma separated string contained pairs of +''' parameter-name/value to be matched within a PCAN-Basic channel +''' Buffer for returning the PCAN-Basic channel, +''' when found +''' A TPCANStatus error code +Public Declare Function CAN_LookUpChannel Lib "PCANBasic.DLL" _ + (ByVal Parameters As String, + ByRef FoundChannel As Integer) As Long \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Include/PCANBasic.cs b/PCAN API/PCAN-Basic API/Include/PCANBasic.cs new file mode 100644 index 0000000..edacaa8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Include/PCANBasic.cs @@ -0,0 +1,1494 @@ +// PCANBasic.cs +// +// ~~~~~~~~~~~~ +// +// PCAN-Basic API +// +// ~~~~~~~~~~~~ +// +// ------------------------------------------------------------------ +// Author : Keneth Wagner +// Last change: 2022-07-06 +// +// Language: C# 1.0 +// ------------------------------------------------------------------ +// +// Copyright (C) 1999-2022 PEAK-System Technik GmbH, Darmstadt +// more Info at http://www.peak-system.com +// +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Peak.Can.Basic +{ + using TPCANHandle = System.UInt16; + using TPCANBitrateFD = System.String; + using TPCANTimestampFD = System.UInt64; + + #region Enumerations + /// + /// Represents a PCAN status/error code + /// + [Flags] + public enum TPCANStatus : uint + { + /// + /// No error + /// + PCAN_ERROR_OK = 0x00000, + /// + /// Transmit buffer in CAN controller is full + /// + PCAN_ERROR_XMTFULL = 0x00001, + /// + /// CAN controller was read too late + /// + PCAN_ERROR_OVERRUN = 0x00002, + /// + /// Bus error: an error counter reached the 'light' limit + /// + PCAN_ERROR_BUSLIGHT = 0x00004, + /// + /// Bus error: an error counter reached the 'heavy' limit + /// + PCAN_ERROR_BUSHEAVY = 0x00008, + /// + /// Bus error: an error counter reached the 'warning' limit + /// + PCAN_ERROR_BUSWARNING = PCAN_ERROR_BUSHEAVY, + /// + /// Bus error: the CAN controller is error passive + /// + PCAN_ERROR_BUSPASSIVE = 0x40000, + /// + /// Bus error: the CAN controller is in bus-off state + /// + PCAN_ERROR_BUSOFF = 0x00010, + /// + /// Mask for all bus errors + /// + PCAN_ERROR_ANYBUSERR = (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE), + /// + /// Receive queue is empty + /// + PCAN_ERROR_QRCVEMPTY = 0x00020, + /// + /// Receive queue was read too late + /// + PCAN_ERROR_QOVERRUN = 0x00040, + /// + /// Transmit queue is full + /// + PCAN_ERROR_QXMTFULL = 0x00080, + /// + /// Test of the CAN controller hardware registers failed (no hardware found) + /// + PCAN_ERROR_REGTEST = 0x00100, + /// + /// Driver not loaded + /// + PCAN_ERROR_NODRIVER = 0x00200, + /// + /// Hardware already in use by a Net + /// + PCAN_ERROR_HWINUSE = 0x00400, + /// + /// A Client is already connected to the Net + /// + PCAN_ERROR_NETINUSE = 0x00800, + /// + /// Hardware handle is invalid + /// + PCAN_ERROR_ILLHW = 0x01400, + /// + /// Net handle is invalid + /// + PCAN_ERROR_ILLNET = 0x01800, + /// + /// Client handle is invalid + /// + PCAN_ERROR_ILLCLIENT = 0x01C00, + /// + /// Mask for all handle errors + /// + PCAN_ERROR_ILLHANDLE = (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT), + /// + /// Resource (FIFO, Client, timeout) cannot be created + /// + PCAN_ERROR_RESOURCE = 0x02000, + /// + /// Invalid parameter + /// + PCAN_ERROR_ILLPARAMTYPE = 0x04000, + /// + /// Invalid parameter value + /// + PCAN_ERROR_ILLPARAMVAL = 0x08000, + /// + /// Unknown error + /// + PCAN_ERROR_UNKNOWN = 0x10000, + /// + /// Invalid data, function, or action. + /// + PCAN_ERROR_ILLDATA = 0x20000, + /// + /// Driver object state is wrong for the attempted operation + /// + PCAN_ERROR_ILLMODE = 0x80000, + /// + /// An operation was successfully carried out, however, irregularities were registered + /// + PCAN_ERROR_CAUTION = 0x2000000, + /// + /// Channel is not initialized + /// Value was changed from 0x40000 to 0x4000000 + /// + PCAN_ERROR_INITIALIZE = 0x4000000, + /// + /// Invalid operation + /// Value was changed from 0x80000 to 0x8000000 + /// + PCAN_ERROR_ILLOPERATION = 0x8000000, + } + + /// + /// Represents a PCAN device + /// + public enum TPCANDevice : byte + { + /// + /// Undefined, unknown or not selected PCAN device value + /// + PCAN_NONE = 0, + /// + /// PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API + /// + PCAN_PEAKCAN = 1, + /// + /// PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus + /// + PCAN_ISA = 2, + /// + /// PCAN-Dongle + /// + PCAN_DNG = 3, + /// + /// PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express + /// + PCAN_PCI = 4, + /// + /// PCAN-USB and PCAN-USB Pro + /// + PCAN_USB = 5, + /// + /// PCAN-PC Card + /// + PCAN_PCC = 6, + /// + /// PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API + /// + PCAN_VIRTUAL = 7, + /// + /// PCAN Gateway devices + /// + PCAN_LAN = 8 + } + + /// + /// Represents a PCAN parameter to be read or set + /// + public enum TPCANParameter : byte + { + /// + /// Device identifier parameter + /// + PCAN_DEVICE_ID = 1, + /// + /// DEPRECATED parameter. Use PCAN_DEVICE_ID instead + /// + [Obsolete] + PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID, + /// + /// 5-Volt power parameter + /// + PCAN_5VOLTS_POWER = 2, + /// + /// PCAN receive event handler parameter + /// + PCAN_RECEIVE_EVENT = 3, + /// + /// PCAN message filter parameter + /// + PCAN_MESSAGE_FILTER = 4, + /// + /// PCAN-Basic API version parameter + /// + PCAN_API_VERSION = 5, + /// + /// PCAN device channel version parameter + /// + PCAN_CHANNEL_VERSION = 6, + /// + /// PCAN Reset-On-Busoff parameter + /// + PCAN_BUSOFF_AUTORESET = 7, + /// + /// PCAN Listen-Only parameter + /// + PCAN_LISTEN_ONLY = 8, + /// + /// Directory path for log files + /// + PCAN_LOG_LOCATION = 9, + /// + /// Debug-Log activation status + /// + PCAN_LOG_STATUS = 10, + /// + /// Configuration of the debugged information (LOG_FUNCTION_***) + /// + PCAN_LOG_CONFIGURE = 11, + /// + /// Custom insertion of text into the log file + /// + PCAN_LOG_TEXT = 12, + /// + /// Availability status of a PCAN-Channel + /// + PCAN_CHANNEL_CONDITION = 13, + /// + /// PCAN hardware name parameter + /// + PCAN_HARDWARE_NAME = 14, + /// + /// Message reception status of a PCAN-Channel + /// + PCAN_RECEIVE_STATUS = 15, + /// + /// CAN-Controller number of a PCAN-Channel + /// + PCAN_CONTROLLER_NUMBER = 16, + /// + /// Directory path for PCAN trace files + /// + PCAN_TRACE_LOCATION = 17, + /// + /// CAN tracing activation status + /// + PCAN_TRACE_STATUS = 18, + /// + /// Configuration of the maximum file size of a CAN trace + /// + PCAN_TRACE_SIZE = 19, + /// + /// Configuration of the trace file storing mode (TRACE_FILE_***) + /// + PCAN_TRACE_CONFIGURE = 20, + /// + /// Physical identification of a USB based PCAN-Channel by blinking its associated LED + /// + PCAN_CHANNEL_IDENTIFYING = 21, + /// + /// Capabilities of a PCAN device (FEATURE_***) + /// + PCAN_CHANNEL_FEATURES = 22, + /// + /// Using of an existing bit rate (PCAN-View connected to a channel) + /// + PCAN_BITRATE_ADAPTING = 23, + /// + /// Configured bit rate as Btr0Btr1 value + /// + PCAN_BITRATE_INFO = 24, + /// + /// Configured bit rate as TPCANBitrateFD string + /// + PCAN_BITRATE_INFO_FD = 25, + /// + /// Configured nominal CAN Bus speed as Bits per seconds + /// + PCAN_BUSSPEED_NOMINAL = 26, + /// + /// Configured CAN data speed as Bits per seconds + /// + PCAN_BUSSPEED_DATA = 27, + /// + /// Remote address of a LAN channel as string in IPv4 format + /// + PCAN_IP_ADDRESS = 28, + /// + /// Status of the Virtual PCAN-Gateway Service + /// + PCAN_LAN_SERVICE_STATUS = 29, + /// + /// Status messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_STATUS_FRAMES = 30, + /// + /// RTR messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_RTR_FRAMES = 31, + /// + /// Error messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_ERROR_FRAMES = 32, + /// + /// Delay, in microseconds, between sending frames + /// + PCAN_INTERFRAME_DELAY = 33, + /// + /// Filter over code and mask patterns for 11-Bit messages + /// + PCAN_ACCEPTANCE_FILTER_11BIT = 34, + /// + /// Filter over code and mask patterns for 29-Bit messages + /// + PCAN_ACCEPTANCE_FILTER_29BIT = 35, + /// + /// Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive + /// + PCAN_IO_DIGITAL_CONFIGURATION = 36, + /// + /// Value assigned to a 32 digital I/O pins of a PCAN-USB Chip + /// + PCAN_IO_DIGITAL_VALUE = 37, + /// + /// 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_SET = 38, + /// + /// Clear multiple digital I/O pins to 0 + /// + PCAN_IO_DIGITAL_CLEAR = 39, + /// + /// Get value of a single analog input pin + /// + PCAN_IO_ANALOG_VALUE = 40, + /// + /// Get the version of the firmware used by the device associated with a PCAN-Channel + /// + PCAN_FIRMWARE_VERSION = 41, + /// + /// Get the amount of PCAN channels attached to a system + /// + PCAN_ATTACHED_CHANNELS_COUNT = 42, + /// + /// Get information about PCAN channels attached to a system + /// + PCAN_ATTACHED_CHANNELS = 43, + /// + /// Echo messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_ECHO_FRAMES = 44, + /// + /// Get the part number associated to a device + /// + PCAN_DEVICE_PART_NUMBER = 45, + } + + /// + /// Represents the type of a PCAN message + /// + [Flags] + public enum TPCANMessageType : byte + { + /// + /// The PCAN message is a CAN Standard Frame (11-bit identifier) + /// + PCAN_MESSAGE_STANDARD = 0x00, + /// + /// The PCAN message is a CAN Remote-Transfer-Request Frame + /// + PCAN_MESSAGE_RTR = 0x01, + /// + /// The PCAN message is a CAN Extended Frame (29-bit identifier) + /// + PCAN_MESSAGE_EXTENDED = 0x02, + /// + /// The PCAN message represents a FD frame in terms of CiA Specs + /// + PCAN_MESSAGE_FD = 0x04, + /// + /// The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) + /// + PCAN_MESSAGE_BRS = 0x08, + /// + /// The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) + /// + PCAN_MESSAGE_ESI = 0x10, + /// + /// The PCAN message represents an echo CAN Frame + /// + PCAN_MESSAGE_ECHO = 0x20, + /// + /// The PCAN message represents an error frame + /// + PCAN_MESSAGE_ERRFRAME = 0x40, + /// + /// The PCAN message represents a PCAN status message + /// + PCAN_MESSAGE_STATUS = 0x80, + } + + /// + /// Represents a PCAN filter mode + /// + public enum TPCANMode : byte + { + /// + /// Mode is Standard (11-bit identifier) + /// + PCAN_MODE_STANDARD = TPCANMessageType.PCAN_MESSAGE_STANDARD, + /// + /// Mode is Extended (29-bit identifier) + /// + PCAN_MODE_EXTENDED = TPCANMessageType.PCAN_MESSAGE_EXTENDED, + } + + /// + /// Represents a PCAN Baud rate register value + /// + public enum TPCANBaudrate : ushort + { + /// + /// 1 MBit/s + /// + PCAN_BAUD_1M = 0x0014, + /// + /// 800 KBit/s + /// + PCAN_BAUD_800K = 0x0016, + /// + /// 500 kBit/s + /// + PCAN_BAUD_500K = 0x001C, + /// + /// 250 kBit/s + /// + PCAN_BAUD_250K = 0x011C, + /// + /// 125 kBit/s + /// + PCAN_BAUD_125K = 0x031C, + /// + /// 100 kBit/s + /// + PCAN_BAUD_100K = 0x432F, + /// + /// 95,238 KBit/s + /// + PCAN_BAUD_95K = 0xC34E, + /// + /// 83,333 KBit/s + /// + PCAN_BAUD_83K = 0x852B, + /// + /// 50 kBit/s + /// + PCAN_BAUD_50K = 0x472F, + /// + /// 47,619 KBit/s + /// + PCAN_BAUD_47K = 0x1414, + /// + /// 33,333 KBit/s + /// + PCAN_BAUD_33K = 0x8B2F, + /// + /// 20 kBit/s + /// + PCAN_BAUD_20K = 0x532F, + /// + /// 10 kBit/s + /// + PCAN_BAUD_10K = 0x672F, + /// + /// 5 kBit/s + /// + PCAN_BAUD_5K = 0x7F7F, + } + + /// + /// Represents the type of PCAN (Non-PnP) hardware to be initialized + /// + public enum TPCANType : byte + { + /// + /// PCAN-ISA 82C200 + /// + PCAN_TYPE_ISA = 0x01, + /// + /// PCAN-ISA SJA1000 + /// + PCAN_TYPE_ISA_SJA = 0x09, + /// + /// PHYTEC ISA + /// + PCAN_TYPE_ISA_PHYTEC = 0x04, + /// + /// PCAN-Dongle 82C200 + /// + PCAN_TYPE_DNG = 0x02, + /// + /// PCAN-Dongle EPP 82C200 + /// + PCAN_TYPE_DNG_EPP = 0x03, + /// + /// PCAN-Dongle SJA1000 + /// + PCAN_TYPE_DNG_SJA = 0x05, + /// + /// PCAN-Dongle EPP SJA1000 + /// + PCAN_TYPE_DNG_SJA_EPP = 0x06, + } + #endregion + + #region Structures + /// + /// Represents a PCAN message + /// + public struct TPCANMsg + { + /// + /// 11/29-bit message identifier + /// + public uint ID; + /// + /// Type of the message + /// + [MarshalAs(UnmanagedType.U1)] + public TPCANMessageType MSGTYPE; + /// + /// Data Length Code of the message (0..8) + /// + public byte LEN; + /// + /// Data of the message (DATA[0]..DATA[7]) + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] + public byte[] DATA; + } + + /// + /// Represents a timestamp of a received PCAN message. + /// Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow + /// + public struct TPCANTimestamp + { + /// + /// Base-value: milliseconds: 0.. 2^32-1 + /// + public uint millis; + /// + /// Roll-arounds of millis + /// + public ushort millis_overflow; + /// + /// Microseconds: 0..999 + /// + public ushort micros; + } + + /// + /// Represents a PCAN message from a FD capable hardware + /// + public struct TPCANMsgFD + { + /// + /// 11/29-bit message identifier + /// + public uint ID; + /// + /// Type of the message + /// + [MarshalAs(UnmanagedType.U1)] + public TPCANMessageType MSGTYPE; + /// + /// Data Length Code of the message (0..15) + /// + public byte DLC; + /// + /// Data of the message (DATA[0]..DATA[63]) + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] + public byte[] DATA; + } + + /// + /// Describes an available PCAN channel + /// + public struct TPCANChannelInformation + { + /// + /// PCAN channel handle + /// + [MarshalAs(UnmanagedType.U2)] + public TPCANHandle channel_handle; + /// + /// Kind of PCAN device + /// + [MarshalAs(UnmanagedType.U1)] + public TPCANDevice device_type; + /// + /// CAN-Controller number + /// + public byte controller_number; + /// + /// Device capabilities flag (see FEATURE_*) + /// + public uint device_features; + /// + /// Device name + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = PCANBasic.MAX_LENGTH_HARDWARE_NAME)] + public string device_name; + /// + /// Device number + /// + public uint device_id; + /// + /// Availability status of a PCAN-Channel + /// + public uint channel_condition; + } + #endregion + + #region PCANBasic class + /// + /// PCAN-Basic API class implementation + /// + public static class PCANBasic + { + #region PCAN-BUS Handles Definition + /// + /// Undefined/default value for a PCAN bus + /// + public const TPCANHandle PCAN_NONEBUS = 0x00; + + /// + /// PCAN-ISA interface, channel 1 + /// + public const TPCANHandle PCAN_ISABUS1 = 0x21; + /// + /// PCAN-ISA interface, channel 2 + /// + public const TPCANHandle PCAN_ISABUS2 = 0x22; + /// + /// PCAN-ISA interface, channel 3 + /// + public const TPCANHandle PCAN_ISABUS3 = 0x23; + /// + /// PCAN-ISA interface, channel 4 + /// + public const TPCANHandle PCAN_ISABUS4 = 0x24; + /// + /// PCAN-ISA interface, channel 5 + /// + public const TPCANHandle PCAN_ISABUS5 = 0x25; + /// + /// PCAN-ISA interface, channel 6 + /// + public const TPCANHandle PCAN_ISABUS6 = 0x26; + /// + /// PCAN-ISA interface, channel 7 + /// + public const TPCANHandle PCAN_ISABUS7 = 0x27; + /// + /// PCAN-ISA interface, channel 8 + /// + public const TPCANHandle PCAN_ISABUS8 = 0x28; + + /// + /// PPCAN-Dongle/LPT interface, channel 1 + /// + public const TPCANHandle PCAN_DNGBUS1 = 0x31; + + /// + /// PCAN-PCI interface, channel 1 + /// + public const TPCANHandle PCAN_PCIBUS1 = 0x41; + /// + /// PCAN-PCI interface, channel 2 + /// + public const TPCANHandle PCAN_PCIBUS2 = 0x42; + /// + /// PCAN-PCI interface, channel 3 + /// + public const TPCANHandle PCAN_PCIBUS3 = 0x43; + /// + /// PCAN-PCI interface, channel 4 + /// + public const TPCANHandle PCAN_PCIBUS4 = 0x44; + /// + /// PCAN-PCI interface, channel 5 + /// + public const TPCANHandle PCAN_PCIBUS5 = 0x45; + /// + /// PCAN-PCI interface, channel 6 + /// + public const TPCANHandle PCAN_PCIBUS6 = 0x46; + /// + /// PCAN-PCI interface, channel 7 + /// + public const TPCANHandle PCAN_PCIBUS7 = 0x47; + /// + /// PCAN-PCI interface, channel 8 + /// + public const TPCANHandle PCAN_PCIBUS8 = 0x48; + /// + /// PCAN-PCI interface, channel 9 + /// + public const TPCANHandle PCAN_PCIBUS9 = 0x409; + /// + /// PCAN-PCI interface, channel 10 + /// + public const TPCANHandle PCAN_PCIBUS10 = 0x40A; + /// + /// PCAN-PCI interface, channel 11 + /// + public const TPCANHandle PCAN_PCIBUS11 = 0x40B; + /// + /// PCAN-PCI interface, channel 12 + /// + public const TPCANHandle PCAN_PCIBUS12 = 0x40C; + /// + /// PCAN-PCI interface, channel 13 + /// + public const TPCANHandle PCAN_PCIBUS13 = 0x40D; + /// + /// PCAN-PCI interface, channel 14 + /// + public const TPCANHandle PCAN_PCIBUS14 = 0x40E; + /// + /// PCAN-PCI interface, channel 15 + /// + public const TPCANHandle PCAN_PCIBUS15 = 0x40F; + /// + /// PCAN-PCI interface, channel 16 + /// + public const TPCANHandle PCAN_PCIBUS16 = 0x410; + + /// + /// PCAN-USB interface, channel 1 + /// + public const TPCANHandle PCAN_USBBUS1 = 0x51; + /// + /// PCAN-USB interface, channel 2 + /// + public const TPCANHandle PCAN_USBBUS2 = 0x52; + /// + /// PCAN-USB interface, channel 3 + /// + public const TPCANHandle PCAN_USBBUS3 = 0x53; + /// + /// PCAN-USB interface, channel 4 + /// + public const TPCANHandle PCAN_USBBUS4 = 0x54; + /// + /// PCAN-USB interface, channel 5 + /// + public const TPCANHandle PCAN_USBBUS5 = 0x55; + /// + /// PCAN-USB interface, channel 6 + /// + public const TPCANHandle PCAN_USBBUS6 = 0x56; + /// + /// PCAN-USB interface, channel 7 + /// + public const TPCANHandle PCAN_USBBUS7 = 0x57; + /// + /// PCAN-USB interface, channel 8 + /// + public const TPCANHandle PCAN_USBBUS8 = 0x58; + /// + /// PCAN-USB interface, channel 9 + /// + public const TPCANHandle PCAN_USBBUS9 = 0x509; + /// + /// PCAN-USB interface, channel 10 + /// + public const TPCANHandle PCAN_USBBUS10 = 0x50A; + /// + /// PCAN-USB interface, channel 11 + /// + public const TPCANHandle PCAN_USBBUS11 = 0x50B; + /// + /// PCAN-USB interface, channel 12 + /// + public const TPCANHandle PCAN_USBBUS12 = 0x50C; + /// + /// PCAN-USB interface, channel 13 + /// + public const TPCANHandle PCAN_USBBUS13 = 0x50D; + /// + /// PCAN-USB interface, channel 14 + /// + public const TPCANHandle PCAN_USBBUS14 = 0x50E; + /// + /// PCAN-USB interface, channel 15 + /// + public const TPCANHandle PCAN_USBBUS15 = 0x50F; + /// + /// PCAN-USB interface, channel 16 + /// + public const TPCANHandle PCAN_USBBUS16 = 0x510; + + /// + /// PCAN-PC Card interface, channel 1 + /// + public const TPCANHandle PCAN_PCCBUS1 = 0x61; + /// + /// PCAN-PC Card interface, channel 2 + /// + public const TPCANHandle PCAN_PCCBUS2 = 0x62; + + /// + /// PCAN-LAN interface, channel 1 + /// + public const TPCANHandle PCAN_LANBUS1 = 0x801; + /// + /// PCAN-LAN interface, channel 2 + /// + public const TPCANHandle PCAN_LANBUS2 = 0x802; + /// + /// PCAN-LAN interface, channel 3 + /// + public const TPCANHandle PCAN_LANBUS3 = 0x803; + /// + /// PCAN-LAN interface, channel 4 + /// + public const TPCANHandle PCAN_LANBUS4 = 0x804; + /// + /// PCAN-LAN interface, channel 5 + /// + public const TPCANHandle PCAN_LANBUS5 = 0x805; + /// + /// PCAN-LAN interface, channel 6 + /// + public const TPCANHandle PCAN_LANBUS6 = 0x806; + /// + /// PCAN-LAN interface, channel 7 + /// + public const TPCANHandle PCAN_LANBUS7 = 0x807; + /// + /// PCAN-LAN interface, channel 8 + /// + public const TPCANHandle PCAN_LANBUS8 = 0x808; + /// + /// PCAN-LAN interface, channel 9 + /// + public const TPCANHandle PCAN_LANBUS9 = 0x809; + /// + /// PCAN-LAN interface, channel 10 + /// + public const TPCANHandle PCAN_LANBUS10 = 0x80A; + /// + /// PCAN-LAN interface, channel 11 + /// + public const TPCANHandle PCAN_LANBUS11 = 0x80B; + /// + /// PCAN-LAN interface, channel 12 + /// + public const TPCANHandle PCAN_LANBUS12 = 0x80C; + /// + /// PCAN-LAN interface, channel 13 + /// + public const TPCANHandle PCAN_LANBUS13 = 0x80D; + /// + /// PCAN-LAN interface, channel 14 + /// + public const TPCANHandle PCAN_LANBUS14 = 0x80E; + /// + /// PCAN-LAN interface, channel 15 + /// + public const TPCANHandle PCAN_LANBUS15 = 0x80F; + /// + /// PCAN-LAN interface, channel 16 + /// + public const TPCANHandle PCAN_LANBUS16 = 0x810; + #endregion + + #region FD Bit rate parameters + /// + /// Clock frequency in Herz (80000000, 60000000, 40000000, 30000000, 24000000, 20000000) + /// + public const string PCAN_BR_CLOCK = "f_clock"; + /// + /// Clock frequency in Megaherz (80, 60, 40, 30, 24, 20) + /// + public const string PCAN_BR_CLOCK_MHZ = "f_clock_mhz"; + /// + /// Clock prescaler for nominal time quantum + /// + public const string PCAN_BR_NOM_BRP = "nom_brp"; + /// + /// TSEG1 segment for nominal bit rate in time quanta + /// + public const string PCAN_BR_NOM_TSEG1 = "nom_tseg1"; + /// + /// TSEG2 segment for nominal bit rate in time quanta + /// + public const string PCAN_BR_NOM_TSEG2 = "nom_tseg2"; + /// + /// Synchronization Jump Width for nominal bit rate in time quanta + /// + public const string PCAN_BR_NOM_SJW = "nom_sjw"; + /// + /// Sample point for nominal bit rate + /// + public const string PCAN_BR_NOM_SAMPLE = "nom_sam"; + /// + /// Clock prescaler for highspeed data time quantum + /// + public const string PCAN_BR_DATA_BRP = "data_brp"; + /// + /// TSEG1 segment for fast data bit rate in time quanta + /// + public const string PCAN_BR_DATA_TSEG1 = "data_tseg1"; + /// + /// TSEG2 segment for fast data bit rate in time quanta + /// + public const string PCAN_BR_DATA_TSEG2 = "data_tseg2"; + /// + /// Synchronization Jump Width for highspeed data bit rate in time quanta + /// + public const string PCAN_BR_DATA_SJW = "data_sjw"; + /// + /// Secondary sample point delay for highspeed data bit rate in cyles + /// + public const string PCAN_BR_DATA_SAMPLE = "data_ssp_offset"; + #endregion + + #region Parameter values definition + /// + /// The PCAN parameter is not set (inactive) + /// + public const int PCAN_PARAMETER_OFF = 0; + /// + /// The PCAN parameter is set (active) + /// + public const int PCAN_PARAMETER_ON = 1; + /// + /// The PCAN filter is closed. No messages will be received + /// + public const int PCAN_FILTER_CLOSE = 0; + /// + /// The PCAN filter is fully opened. All messages will be received + /// + public const int PCAN_FILTER_OPEN = 1; + /// + /// The PCAN filter is custom configured. Only registered + /// messages will be received + /// + public const int PCAN_FILTER_CUSTOM = 2; + /// + /// The PCAN-Channel handle is illegal, or its associated hardware is not available + /// + public const int PCAN_CHANNEL_UNAVAILABLE = 0; + /// + /// The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) + /// + public const int PCAN_CHANNEL_AVAILABLE = 1; + /// + /// The PCAN-Channel handle is valid, and is already being used + /// + public const int PCAN_CHANNEL_OCCUPIED = 2; + /// + /// The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect + /// + public const int PCAN_CHANNEL_PCANVIEW = (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED); + + /// + /// Logs system exceptions / errors + /// + public const int LOG_FUNCTION_DEFAULT = 0x00; + /// + /// Logs the entries to the PCAN-Basic API functions + /// + public const int LOG_FUNCTION_ENTRY = 0x01; + /// + /// Logs the parameters passed to the PCAN-Basic API functions + /// + public const int LOG_FUNCTION_PARAMETERS = 0x02; + /// + /// Logs the exits from the PCAN-Basic API functions + /// + public const int LOG_FUNCTION_LEAVE = 0x04; + /// + /// Logs the CAN messages passed to the CAN_Write function + /// + public const int LOG_FUNCTION_WRITE = 0x08; + /// + /// Logs the CAN messages received within the CAN_Read function + /// + public const int LOG_FUNCTION_READ = 0x10; + /// + /// Logs all possible information within the PCAN-Basic API functions + /// + public const int LOG_FUNCTION_ALL = 0xFFFF; + + /// + /// A single file is written until it size reaches PAN_TRACE_SIZE + /// + public const int TRACE_FILE_SINGLE = 0x00; + /// + /// Traced data is distributed in several files with size PAN_TRACE_SIZE + /// + public const int TRACE_FILE_SEGMENTED = 0x01; + /// + /// Includes the date into the name of the trace file + /// + public const int TRACE_FILE_DATE = 0x02; + /// + /// Includes the start time into the name of the trace file + /// + public const int TRACE_FILE_TIME = 0x04; + /// + /// Causes the overwriting of available traces (same name) + /// + public const int TRACE_FILE_OVERWRITE = 0x80; + + /// + /// Device supports flexible data-rate (CAN-FD) + /// + public const int FEATURE_FD_CAPABLE = 0x01; + /// + /// Device supports a delay between sending frames (FPGA based USB devices) + /// + public const int FEATURE_DELAY_CAPABLE = 0x02; + /// + /// Device supports I/O functionality for electronic circuits (USB-Chip devices) + /// + public const int FEATURE_IO_CAPABLE = 0x04; + + /// + /// The service is not running + /// + public const int SERVICE_STATUS_STOPPED = 0x01; + /// + /// The service is running + /// + public const int SERVICE_STATUS_RUNNING = 0x04; + #endregion + + #region Lookup Parameters + /// + /// Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) + /// + public const string LOOKUP_DEVICE_TYPE = "devicetype"; + /// + /// Lookup channel by device id + /// + public const string LOOKUP_DEVICE_ID = "deviceid"; + /// + /// Lookup channel by CAN controller 0-based index + /// + public const string LOOKUP_CONTROLLER_NUMBER = "controllernumber"; + /// + /// Lookup channel by IP address (LAN channels only) + /// + public const string LOOKUP_IP_ADDRESS = "ipaddress"; + #endregion + + #region Other Constants + /// + /// Maximum length of the name of a device: 32 characters + terminator + /// + public const int MAX_LENGTH_HARDWARE_NAME = 33; + /// + /// Maximum length of a version string: 255 characters + terminator + /// + public const int MAX_LENGTH_VERSION_STRING = 256; + #endregion + + #region PCANBasic API Implementation + /// + /// Initializes a PCAN Channel + /// + /// The handle of a PCAN Channel + /// The speed for the communication (BTR0BTR1 code) + /// Non-PnP: The type of hardware and operation mode + /// Non-PnP: The I/O address for the parallel port + /// Non-PnP: Interrupt number of the parallel por + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Initialize")] + public static extern TPCANStatus Initialize( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U2)] + TPCANBaudrate Btr0Btr1, + [MarshalAs(UnmanagedType.U1)] + TPCANType HwType, + UInt32 IOPort, + UInt16 Interrupt); + + /// + /// Initializes a PCAN Channel + /// + /// The handle of a PCAN Channel + /// The speed for the communication (BTR0BTR1 code) + /// A TPCANStatus error code + public static TPCANStatus Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1) + { + return Initialize(Channel, Btr0Btr1, (TPCANType)0, 0, 0); + } + + /// + /// Initializes a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// The speed for the communication (FD bit rate string) + /// See PCAN_BR_* values + /// Bit rate string must follow the following construction rules: + /// * parameters 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 + /// 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 + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_InitializeFD")] + public static extern TPCANStatus InitializeFD( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + /// + /// Uninitializes one or all PCAN Channels initialized by CAN_Initialize + /// + /// Giving the TPCANHandle value "PCAN_NONEBUS", + /// uninitialize all initialized channels + /// The handle of a PCAN Channel + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Uninitialize")] + public static extern TPCANStatus Uninitialize( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel); + + /// + /// Resets the receive and transmit queues of the PCAN Channel + /// + /// A reset of the CAN controller is not performed + /// The handle of a PCAN Channel + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Reset")] + public static extern TPCANStatus Reset( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel); + + /// + /// Gets the current status of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetStatus")] + public static extern TPCANStatus GetStatus( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel); + + /// + /// Reads a CAN message from the receive queue of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANMsg structure buffer to store the CAN message + /// A TPCANTimestamp structure buffer to get + /// the reception time of the message + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")] + public static extern TPCANStatus Read( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + out TPCANMsg MessageBuffer, + out TPCANTimestamp TimestampBuffer); + + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")] + private static extern TPCANStatus Read( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + out TPCANMsg MessageBuffer, + IntPtr bufferPointer); + + /// + /// Reads a CAN message from the receive queue of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANMsg structure buffer to store the CAN message + /// A TPCANStatus error code + public static TPCANStatus Read( + TPCANHandle Channel, + out TPCANMsg MessageBuffer) + { + return Read(Channel, out MessageBuffer, IntPtr.Zero); + } + + /// + /// Reads a CAN message from the receive queue of a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD structure buffer to store the CAN message + /// A TPCANTimestampFD buffer to get the + /// reception time of the message + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_ReadFD")] + public static extern TPCANStatus ReadFD( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + out TPCANMsgFD MessageBuffer, + out TPCANTimestampFD TimestampBuffer); + + [DllImport("PCANBasic.dll", EntryPoint = "CAN_ReadFD")] + private static extern TPCANStatus ReadFD( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + out TPCANMsgFD MessageBuffer, + IntPtr TimestampBuffer); + + /// + /// Reads a CAN message from the receive queue of a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD structure buffer to store the CAN message + /// A TPCANStatus error code + public static TPCANStatus ReadFD( + TPCANHandle Channel, + out TPCANMsgFD MessageBuffer) + { + return ReadFD(Channel, out MessageBuffer, IntPtr.Zero); + } + + /// + /// Transmits a CAN message + /// + /// The handle of a PCAN Channel + /// A TPCANMsg buffer with the message to be sent + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Write")] + public static extern TPCANStatus Write( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + ref TPCANMsg MessageBuffer); + + /// + /// Transmits a CAN message over a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD buffer with the message to be sent + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_WriteFD")] + public static extern TPCANStatus WriteFD( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + ref TPCANMsgFD MessageBuffer); + + /// + /// Configures the reception filter + /// + /// 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 + /// The handle of a PCAN Channel + /// The lowest CAN ID to be received + /// The highest CAN ID to be received + /// Message type, Standard (11-bit identifier) or + /// Extended (29-bit identifier) + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_FilterMessages")] + public static extern TPCANStatus FilterMessages( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + UInt32 FromID, + UInt32 ToID, + [MarshalAs(UnmanagedType.U1)] + TPCANMode Mode); + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + public static extern TPCANStatus GetValue( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U1)] + TPCANParameter Parameter, + StringBuilder StringBuffer, + UInt32 BufferLength); + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + public static extern TPCANStatus GetValue( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U1)] + TPCANParameter Parameter, + out UInt32 NumericBuffer, + UInt32 BufferLength); + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + public static extern TPCANStatus GetValue( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U1)] + TPCANParameter Parameter, + out UInt64 NumericBuffer, + UInt32 BufferLength); + + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + private static extern TPCANStatus GetValue( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U1)] + TPCANParameter Parameter, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] + [In, Out]TPCANChannelInformation[] ChannelsBuffer, + UInt32 BufferLength); + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// A TPCANStatus error code + public static TPCANStatus GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + TPCANChannelInformation[] ChannelsBuffer) + { + if (ChannelsBuffer == null) + return TPCANStatus.PCAN_ERROR_ILLPARAMVAL; + return GetValue(Channel, Parameter, ChannelsBuffer, (uint)(ChannelsBuffer.Length * Marshal.SizeOf(typeof(TPCANChannelInformation)))); + } + + /// + /// Configures or sets a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to set + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")] + public static extern TPCANStatus SetValue( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U1)] + TPCANParameter Parameter, + ref UInt32 NumericBuffer, + UInt32 BufferLength); + + /// + /// Configures or sets a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to set + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")] + public static extern TPCANStatus SetValue( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U1)] + TPCANParameter Parameter, + ref UInt64 NumericBuffer, + UInt32 BufferLength); + + /// + /// Configures or sets a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")] + public static extern TPCANStatus SetValue( + [MarshalAs(UnmanagedType.U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType.U1)] + TPCANParameter Parameter, + [MarshalAs(UnmanagedType.LPStr,SizeParamIndex=3)] + string StringBuffer, + UInt32 BufferLength); + + /// + /// Returns a descriptive text of a given TPCANStatus error + /// code, in any desired language + /// + /// The current languages available for translation are: + /// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), + /// Italian (0x10) and French (0x0C) + /// A TPCANStatus error code + /// Indicates a 'Primary language ID' + /// Buffer for the text (must be at least 256 in length) + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetErrorText")] + public static extern TPCANStatus GetErrorText( + [MarshalAs(UnmanagedType.U4)] + TPCANStatus Error, + UInt16 Language, + StringBuilder StringBuffer); + + + /// + /// Finds a PCAN-Basic channel that matches with the given parameters + /// + /// A comma separated string contained pairs of + /// parameter-name/value to be matched within a PCAN-Basic channel + /// Buffer for returning the PCAN-Basic channel, + /// when found + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_LookUpChannel")] + public static extern TPCANStatus LookUpChannel( + String Parameters, + out TPCANHandle FoundChannel); + #endregion + } + #endregion +} diff --git a/PCAN API/PCAN-Basic API/Include/PCANBasic.h b/PCAN API/PCAN-Basic API/Include/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Include/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Include/PCANBasic.pas b/PCAN API/PCAN-Basic API/Include/PCANBasic.pas new file mode 100644 index 0000000..0453eee --- /dev/null +++ b/PCAN API/PCAN-Basic API/Include/PCANBasic.pas @@ -0,0 +1,1548 @@ +// PCANBasic.pas +// +// ~~~~~~~~~~~~ +// +// PCAN-Basic API +// +// ~~~~~~~~~~~~ +// +// ------------------------------------------------------------------ +// Author : Keneth Wagner +// Last change: 2022-07-06 +// +// Language: Object Pascal +// ------------------------------------------------------------------ +// +// Copyright (C) 1999-2022 PEAK-System Technik GmbH, Darmstadt +// more Info at http://www.peak-system.com +// +unit PCANBasic; + +interface +Const + // Other constants + // + MAX_LENGTH_HARDWARE_NAME = 33; // Maximum length of the name of a device: 32 characters + terminator + MAX_LENGTH_VERSION_STRING = 256; // Maximum length of a version string: 255 characters + terminator + +type + TPCANHandle = Word; + PTPCANHandle = ^Word; + TPCANBitrateFD = PAnsiChar; + TPCANTimestampFD = UInt64; + PUInt64 = ^UInt64; + +{$Z4} + /// + /// Represents a PCAN status/error code + /// + TPCANStatus = ( + /// + /// No error + /// + PCAN_ERROR_OK = $00000, + /// + /// Transmit buffer in CAN controller is full + /// + PCAN_ERROR_XMTFULL = $00001, + /// + /// CAN controller was read too late + /// + PCAN_ERROR_OVERRUN = $00002, + /// + /// Bus error: an error counter reached the 'light' limit + /// + PCAN_ERROR_BUSLIGHT = $00004, + /// + /// Bus error: an error counter reached the 'heavy' limit + /// + PCAN_ERROR_BUSHEAVY = $00008, + /// + /// Bus error: an error counter reached the 'warning' limit + /// + PCAN_ERROR_BUSWARNING = LongWord(PCAN_ERROR_BUSHEAVY), + /// + /// Bus error: the CAN controller is error passive + /// + PCAN_ERROR_BUSPASSIVE = $40000, + /// + /// Bus error: the CAN controller is in bus-off state + /// + PCAN_ERROR_BUSOFF = $00010, + /// + /// Mask for all bus errors + /// + PCAN_ERROR_ANYBUSERR = LongWord(PCAN_ERROR_BUSWARNING) Or LongWord(PCAN_ERROR_BUSLIGHT) Or LongWord(PCAN_ERROR_BUSHEAVY) Or LongWord(PCAN_ERROR_BUSOFF) Or LongWord(PCAN_ERROR_BUSPASSIVE), + /// + /// Receive queue is empty + /// + PCAN_ERROR_QRCVEMPTY = $00020, + /// + /// Receive queue was read too late + /// + PCAN_ERROR_QOVERRUN = $00040, + /// + /// Transmit queue is full + /// + PCAN_ERROR_QXMTFULL = $00080, + /// + /// Test of the CAN controller hardware registers failed (no hardware found) + /// + PCAN_ERROR_REGTEST = $00100, + /// + /// Driver not loaded + /// + PCAN_ERROR_NODRIVER = $00200, + /// + /// Hardware already in use by a Net + /// + PCAN_ERROR_HWINUSE = $00400, + /// + /// A Client is already connected to the Net + /// + PCAN_ERROR_NETINUSE = $00800, + /// + /// Hardware handle is invalid + /// + PCAN_ERROR_ILLHW = $01400, + /// + /// Net handle is invalid + /// + PCAN_ERROR_ILLNET = $01800, + /// + /// Client handle is invalid + /// + PCAN_ERROR_ILLCLIENT = $01C00, + /// + /// Mask for all handle errors + /// + PCAN_ERROR_ILLHANDLE = LongWord(PCAN_ERROR_ILLHW) Or LongWord(PCAN_ERROR_ILLNET) Or LongWord(PCAN_ERROR_ILLCLIENT), + /// + /// Resource (FIFO, Client, timeout) cannot be created + /// + PCAN_ERROR_RESOURCE = $02000, + /// + /// Invalid parameter + /// + PCAN_ERROR_ILLPARAMTYPE = $04000, + /// + /// Invalid parameter value + /// + PCAN_ERROR_ILLPARAMVAL = $08000, + /// + /// Unknown error + /// + PCAN_ERROR_UNKNOWN = $10000, + /// + /// Invalid data, function, or action + /// + PCAN_ERROR_ILLDATA = $20000, + /// + /// Driver object state is wrong for the attempted operation + /// + PCAN_ERROR_ILLMODE = $80000, + /// + /// An operation was successfully carried out, however, irregularities were registered + /// + PCAN_ERROR_CAUTION = $2000000, + /// + /// Channel is not initialized + /// Value was changed from 0x40000 to 0x4000000 + /// + PCAN_ERROR_INITIALIZE = $4000000, + /// + /// Invalid operation + /// Value was changed from 0x80000 to 0x8000000 + /// + PCAN_ERROR_ILLOPERATION = $8000000 + ); + +{$Z1} + /// + /// Represents a PCAN device + /// + TPCANDevice = ( + /// + /// Undefined, unknown or not selected PCAN device value + /// + PCAN_NONE = 0, + /// + /// PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API + /// + PCAN_PEAKCAN = 1, + /// + /// PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus + /// + PCAN_ISA = 2, + /// + /// PCAN-Dongle + /// + PCAN_DNG = 3, + /// + /// PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express + /// + PCAN_PCI = 4, + /// + /// PCAN-USB and PCAN-USB Pro + /// + PCAN_USB = 5, + /// + /// PCAN-PC Card + /// + PCAN_PCC = 6, + /// + /// PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API + /// + PCAN_VIRTUAL = 7, + /// + /// PCAN Gateway devices + /// + PCAN_LAN = 8 + ); + + /// + /// Represents a PCAN parameter to be read or set + /// + TPCANParameter = ( + /// + /// Device identifier parameter + /// + PCAN_DEVICE_ID = 1, + /// + /// DEPRECATED. Use PCAN_DEVICE_ID instead + /// + PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID, + /// + /// 5-Volt power parameter + /// + PCAN_5VOLTS_POWER = 2, + /// + /// PCAN receive event handler parameter + /// + PCAN_RECEIVE_EVENT = 3, + /// + /// PCAN message filter parameter + /// + PCAN_MESSAGE_FILTER = 4, + /// + /// PCAN-Basic API version parameter + /// + PCAN_API_VERSION = 5, + /// + /// PCAN device channel version parameter + /// + PCAN_CHANNEL_VERSION = 6, + /// + /// PCAN Reset-On-Busoff parameter + /// + PCAN_BUSOFF_AUTORESET = 7, + /// + /// PCAN Listen-Only parameter + /// + PCAN_LISTEN_ONLY = 8, + /// + /// Directory path for log files + /// + PCAN_LOG_LOCATION = 9, + /// + /// Debug-Log activation status + /// + PCAN_LOG_STATUS = 10, + /// + /// Configuration of the debugged information (LOG_FUNCTION_***) + /// + PCAN_LOG_CONFIGURE = 11, + /// + /// Custom insertion of text into the log file + /// + PCAN_LOG_TEXT = 12, + /// + /// Availability status of a PCAN-Channel + /// + PCAN_CHANNEL_CONDITION = 13, + /// + /// PCAN hardware name parameter + /// + PCAN_HARDWARE_NAME = 14, + /// + /// Message reception status of a PCAN-Channel + /// + PCAN_RECEIVE_STATUS = 15, + /// + /// CAN-Controller number of a PCAN-Channel + /// + PCAN_CONTROLLER_NUMBER = 16, + /// + /// Directory path for PCAN trace files + /// + PCAN_TRACE_LOCATION = 17, + /// + /// CAN tracing activation status + /// + PCAN_TRACE_STATUS = 18, + /// + /// Configuration of the maximum file size of a CAN trace + /// + PCAN_TRACE_SIZE = 19, + /// + /// Configuration of the trace file storing mode (TRACE_FILE_***) + /// + PCAN_TRACE_CONFIGURE = 20, + /// + /// Physical identification of a USB based PCAN-Channel by blinking its associated LED + /// + PCAN_CHANNEL_IDENTIFYING = 21, + /// + /// Capabilities of a PCAN device (FEATURE_***) + /// + PCAN_CHANNEL_FEATURES = 22, + /// + /// Using of an existing bit rate (PCAN-View connected to a channel) + /// + PCAN_BITRATE_ADAPTING = 23, + /// + /// Configured bit rate as Btr0Btr1 value + /// + PCAN_BITRATE_INFO = 24, + /// + /// Configured bit rate as TPCANBitrateFD string + /// + PCAN_BITRATE_INFO_FD = 25, + /// + /// Configured nominal CAN Bus speed as Bits per seconds + /// + PCAN_BUSSPEED_NOMINAL = 26, + /// + /// Configured CAN data speed as Bits per seconds + /// + PCAN_BUSSPEED_DATA = 27, + /// + /// Remote address of a LAN channel as string in IPv4 format + /// + PCAN_IP_ADDRESS = 28, + /// + /// Status of the Virtual PCAN-Gateway Service + /// + PCAN_LAN_SERVICE_STATUS = 29, + /// + /// Status messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_STATUS_FRAMES = 30, + /// + /// RTR messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_RTR_FRAMES = 31, + /// + /// Error messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_ERROR_FRAMES = 32, + /// + /// Delay, in microseconds, between sending frames + /// + PCAN_INTERFRAME_DELAY = 33, + /// + /// Filter over code and mask patterns for 11-Bit messages + /// + PCAN_ACCEPTANCE_FILTER_11BIT = 34, + /// + /// Filter over code and mask patterns for 29-Bit messages + /// + PCAN_ACCEPTANCE_FILTER_29BIT = 35, + /// + /// Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive + /// + PCAN_IO_DIGITAL_CONFIGURATION = 36, + /// + /// Value assigned to a 32 digital I/O pins of a PCAN-USB Chip + /// + PCAN_IO_DIGITAL_VALUE = 37, + /// + /// 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_SET = 38, + /// + /// Clear multiple digital I/O pins to 0 + /// + PCAN_IO_DIGITAL_CLEAR = 39, + /// + /// Get value of a single analog input pin + /// + PCAN_IO_ANALOG_VALUE = 40, + /// + /// Get the version of the firmware used by the device associated with a PCAN-Channel + /// + PCAN_FIRMWARE_VERSION = 41, + /// + /// Get the amount of PCAN channels attached to a system + /// + PCAN_ATTACHED_CHANNELS_COUNT = 42, + /// + /// Get information about PCAN channels attached to a system + /// + PCAN_ATTACHED_CHANNELS = 43, + /// + /// Echo messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_ECHO_FRAMES = 44, + /// + /// Get the part number associated to a device + /// + PCAN_DEVICE_PART_NUMBER = 45 + ); + + /// + /// Represents the type of a PCAN message + /// + TPCANMessageType = ( + /// + /// The PCAN message is a CAN Standard Frame (11-bit identifier) + /// + PCAN_MESSAGE_STANDARD = $00, + /// + /// The PCAN message is a CAN Remote-Transfer-Request Frame + /// + PCAN_MESSAGE_RTR = $01, + /// + /// The PCAN message is a CAN Extended Frame (29-bit identifier) + /// + PCAN_MESSAGE_EXTENDED = $02, + /// + /// The PCAN message represents a FD frame in terms of CiA Specs + /// + PCAN_MESSAGE_FD = $04, + /// + /// The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) + /// + PCAN_MESSAGE_BRS = $08, + /// + /// The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) + /// + PCAN_MESSAGE_ESI = $10, + /// + /// The PCAN message represents an echo CAN Frame + /// + PCAN_MESSAGE_ECHO = $20, + /// + /// The PCAN message represents an error frame + /// + PCAN_MESSAGE_ERRFRAME = $40, + /// + /// The PCAN message represents a PCAN status message + /// + PCAN_MESSAGE_STATUS = $80 + ); + + /// + /// Represents a PCAN filter mode + /// + TPCANMode = ( + /// + /// Mode is Standard (11-bit identifier) + /// + PCAN_MODE_STANDARD = Byte(PCAN_MESSAGE_STANDARD), + /// + /// Mode is Extended (29-bit identifier) + /// + PCAN_MODE_EXTENDED = Byte(PCAN_MESSAGE_EXTENDED) + ); + +{$Z2} + /// + /// Represents a PCAN Baud rate register value + /// + TPCANBaudrate = ( + /// + /// 1 MBit/s + /// + PCAN_BAUD_1M = $0014, + /// + /// 800 kBit/s + /// + PCAN_BAUD_800K = $0016, + /// + /// 500 kBit/s + /// + PCAN_BAUD_500K = $001C, + /// + /// 250 kBit/s + /// + PCAN_BAUD_250K = $011C, + /// + /// 125 kBit/s + /// + PCAN_BAUD_125K = $031C, + /// + /// 100 kBit/s + /// + PCAN_BAUD_100K = $432F, + /// + /// 95,238 kBit/s + /// + PCAN_BAUD_95K = $C34E, + /// + /// 83,333 kBit/s + /// + PCAN_BAUD_83K = $852B, + /// + /// 50 kBit/s + /// + PCAN_BAUD_50K = $472F, + /// + /// 47,619 kBit/s + /// + PCAN_BAUD_47K = $1414, + /// + /// 33,333 kBit/s + /// + PCAN_BAUD_33K = $8B2F, + /// + /// 20 kBit/s + /// + PCAN_BAUD_20K = $532F, + /// + /// 10 kBit/s + /// + PCAN_BAUD_10K = $672F, + /// + /// 5 kBit/s + /// + PCAN_BAUD_5K = $7F7F + ); + +{$Z1} + /// + /// Represents the type of PCAN (Non-PnP) hardware to be initialized + /// + TPCANType = ( + /// + /// PCAN-ISA 82C200 + /// + PCAN_TYPE_ISA = $01, + /// + /// PCAN-ISA SJA1000 + /// + PCAN_TYPE_ISA_SJA = $09, + /// + /// PHYTEC ISA + /// + PCAN_TYPE_ISA_PHYTEC = $04, + /// + /// PCAN-Dongle 82C200 + /// + PCAN_TYPE_DNG = $02, + /// + /// PCAN-Dongle EPP 82C200 + /// + PCAN_TYPE_DNG_EPP = $03, + /// + /// PCAN-Dongle SJA1000 + /// + PCAN_TYPE_DNG_SJA = $05, + /// + /// PCAN-Dongle EPP SJA1000 + /// + PCAN_TYPE_DNG_SJA_EPP = $06 + ); + + /// + /// Represents a PCAN message + /// + TPCANMsg = record + /// + /// 11/29-bit message identifier + /// + ID: Longword; + /// + /// Type of the message + /// + MSGTYPE: TPCANMessageType; + /// + /// Data Length Code of the message (0..8) + /// + LEN: Byte; + /// + /// Data of the message (DATA[0]..DATA[7]) + /// + DATA: array[0..7] of Byte; + end; + PTPCANMsg = ^TPCANMsg; + + /// + /// Represents a timestamp of a received PCAN message. + /// Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow + /// + TPCANTimestamp = record + /// + /// Base-value: milliseconds: 0.. 2^32-1 + /// + millis: Longword; + /// + /// Roll-arounds of millis + /// + millis_overflow: Word; + /// + /// Microseconds: 0..999 + /// + micros: Word; + end; + PTPCANTimestamp = ^TPCANTimestamp; + + /// + /// Represents a PCAN message from a FD capable hardware + /// + TPCANMsgFD = record + /// + /// 11/29-bit message identifier + /// + ID: Longword; + /// + /// Type of the message + /// + MSGTYPE: TPCANMessageType; + /// + /// Data Length Code of the message (0..15) + /// + DLC: Byte; + /// + /// Data of the message (DATA[0]..DATA[63]) + /// + DATA: array[0..63] of Byte; + end; + PTPCANMsgFD = ^TPCANMsgFD; + + + /// + /// Describes an available PCAN channel + /// + TPCANChannelInformation = record + /// + /// PCAN channel handle + /// + channel_handle: TPCANHandle; + /// + /// Kind of PCAN device + /// + device_type: TPCANDevice; + /// + /// CAN-Controller number + /// + controller_number: Byte; + /// + /// Device capabilities flag (see FEATURE_*) + /// + device_features: Longword; + /// + /// Device name + /// + device_name: array [0..MAX_LENGTH_HARDWARE_NAME-1] of AnsiChar; + /// + /// Device number + /// + device_id: Longword; + /// + /// Availability status of a PCAN-Channel + /// + channel_condition: Longword; + end; + PTPCANChannelInformation = ^TPCANChannelInformation; + + /// + /// PCAN-Basic API class implementation + /// + TPCANBasic = class + public + class var + /// + /// Undefined/default value for a PCAN bus + /// + const PCAN_NONEBUS: TPCANHandle = $00; + + /// + /// PCAN-ISA interface, channel 1 + /// + const PCAN_ISABUS1: TPCANHandle = $21; + /// + /// PCAN-ISA interface, channel 2 + /// + const PCAN_ISABUS2: TPCANHandle = $22; + /// + /// PCAN-ISA interface, channel 3 + /// + const PCAN_ISABUS3: TPCANHandle = $23; + /// + /// PCAN-ISA interface, channel 4 + /// + const PCAN_ISABUS4: TPCANHandle = $24; + /// + /// PCAN-ISA interface, channel 5 + /// + const PCAN_ISABUS5: TPCANHandle = $25; + /// + /// PCAN-ISA interface, channel 6 + /// + const PCAN_ISABUS6: TPCANHandle = $26; + /// + /// PCAN-ISA interface, channel 7 + /// + const PCAN_ISABUS7: TPCANHandle = $27; + /// + /// PCAN-ISA interface, channel 8 + /// + const PCAN_ISABUS8: TPCANHandle = $28; + + /// + /// PPCAN-Dongle/LPT interface, channel 1 + /// + const PCAN_DNGBUS1: TPCANHandle = $31; + + /// + /// PCAN-PCI interface, channel 1 + /// + const PCAN_PCIBUS1: TPCANHandle = $41; + /// + /// PCAN-PCI interface, channel 2 + /// + const PCAN_PCIBUS2: TPCANHandle = $42; + /// + /// PCAN-PCI interface, channel 3 + /// + const PCAN_PCIBUS3: TPCANHandle = $43; + /// + /// PCAN-PCI interface, channel 4 + /// + const PCAN_PCIBUS4: TPCANHandle = $44; + /// + /// PCAN-PCI interface, channel 5 + /// + const PCAN_PCIBUS5: TPCANHandle = $45; + /// + /// PCAN-PCI interface, channel 6 + /// + const PCAN_PCIBUS6: TPCANHandle = $46; + /// + /// PCAN-PCI interface, channel 7 + /// + const PCAN_PCIBUS7: TPCANHandle = $47; + /// + /// PCAN-PCI interface, channel 8 + /// + const PCAN_PCIBUS8: TPCANHandle = $48; + /// + /// PCAN-PCI interface, channel 9 + /// + const PCAN_PCIBUS9: TPCANHandle = $409; + /// + /// PCAN-PCI interface, channel 10 + /// + const PCAN_PCIBUS10: TPCANHandle = $40A; + /// + /// PCAN-PCI interface, channel 11 + /// + const PCAN_PCIBUS11: TPCANHandle = $40B; + /// + /// PCAN-PCI interface, channel 12 + /// + const PCAN_PCIBUS12: TPCANHandle = $40C; + /// + /// PCAN-PCI interface, channel 13 + /// + const PCAN_PCIBUS13: TPCANHandle = $40D; + /// + /// PCAN-PCI interface, channel 14 + /// + const PCAN_PCIBUS14: TPCANHandle = $40E; + /// + /// PCAN-PCI interface, channel 15 + /// + const PCAN_PCIBUS15: TPCANHandle = $40F; + /// + /// PCAN-PCI interface, channel 16 + /// + const PCAN_PCIBUS16: TPCANHandle = $410; + + /// + /// PCAN-USB interface, channel 1 + /// + const PCAN_USBBUS1: TPCANHandle = $51; + /// + /// PCAN-USB interface, channel 2 + /// + const PCAN_USBBUS2: TPCANHandle = $52; + /// + /// PCAN-USB interface, channel 3 + /// + const PCAN_USBBUS3: TPCANHandle = $53; + /// + /// PCAN-USB interface, channel 4 + /// + const PCAN_USBBUS4: TPCANHandle = $54; + /// + /// PCAN-USB interface, channel 5 + /// + const PCAN_USBBUS5: TPCANHandle = $55; + /// + /// PCAN-USB interface, channel 6 + /// + const PCAN_USBBUS6: TPCANHandle = $56; + /// + /// PCAN-USB interface, channel 7 + /// + const PCAN_USBBUS7: TPCANHandle = $57; + /// + /// PCAN-USB interface, channel 8 + /// + const PCAN_USBBUS8: TPCANHandle = $58; + /// + /// PCAN-USB interface, channel 9 + /// + const PCAN_USBBUS9: TPCANHandle = $509; + /// + /// PCAN-USB interface, channel 10 + /// + const PCAN_USBBUS10: TPCANHandle = $50A; + /// + /// PCAN-USB interface, channel 11 + /// + const PCAN_USBBUS11: TPCANHandle = $50B; + /// + /// PCAN-USB interface, channel 12 + /// + const PCAN_USBBUS12: TPCANHandle = $50C; + /// + /// PCAN-USB interface, channel 13 + /// + const PCAN_USBBUS13: TPCANHandle = $50D; + /// + /// PCAN-USB interface, channel 14 + /// + const PCAN_USBBUS14: TPCANHandle = $50E; + /// + /// PCAN-USB interface, channel 15 + /// + const PCAN_USBBUS15: TPCANHandle = $50F; + /// + /// PCAN-USB interface, channel 16 + /// + const PCAN_USBBUS16: TPCANHandle = $510; + + /// + /// PCAN-PC Card interface, channel 1 + /// + const PCAN_PCCBUS1: TPCANHandle = $61; + /// + /// PCAN-PC Card interface, channel 2 + /// + const PCAN_PCCBUS2: TPCANHandle = $62; + + /// + /// PCAN-LAN interface, channel 1 + /// + const PCAN_LANBUS1: TPCANHandle = $801; + /// + /// PCAN-LAN interface, channel 2 + /// + const PCAN_LANBUS2: TPCANHandle = $802; + /// + /// PCAN-LAN interface, channel 3 + /// + const PCAN_LANBUS3: TPCANHandle = $803; + /// + /// PCAN-LAN interface, channel 4 + /// + const PCAN_LANBUS4: TPCANHandle = $804; + /// + /// PCAN-LAN interface, channel 5 + /// + const PCAN_LANBUS5: TPCANHandle = $805; + /// + /// PCAN-LAN interface, channel 6 + /// + const PCAN_LANBUS6: TPCANHandle = $806; + /// + /// PCAN-LAN interface, channel 7 + /// + const PCAN_LANBUS7: TPCANHandle = $807; + /// + /// PCAN-LAN interface, channel 8 + /// + const PCAN_LANBUS8: TPCANHandle = $808; + /// + /// PCAN-LAN interface, channel 9 + /// + const PCAN_LANBUS9: TPCANHandle = $809; + /// + /// PCAN-LAN interface, channel 10 + /// + const PCAN_LANBUS10: TPCANHandle = $80A; + /// + /// PCAN-LAN interface, channel 11 + /// + const PCAN_LANBUS11: TPCANHandle = $80B; + /// + /// PCAN-LAN interface, channel 12 + /// + const PCAN_LANBUS12: TPCANHandle = $80C; + /// + /// PCAN-LAN interface, channel 13 + /// + const PCAN_LANBUS13: TPCANHandle = $80D; + /// + /// PCAN-LAN interface, channel 14 + /// + const PCAN_LANBUS14: TPCANHandle = $80E; + /// + /// PCAN-LAN interface, channel 15 + /// + const PCAN_LANBUS15: TPCANHandle = $80F; + /// + /// PCAN-LAN interface, channel 16 + /// + const PCAN_LANBUS16: TPCANHandle = $810; + + /// + /// Clock frequency in Herz (80000000, 60000000, 40000000, 30000000, 24000000, 20000000) + /// + const PCAN_BR_CLOCK: String = 'f_clock'; + /// + /// Clock frequency in Megaherz (80, 60, 40, 30, 24, 20) + /// + const PCAN_BR_CLOCK_MHZ: String = 'f_clock_mhz'; + /// + /// Clock prescaler for nominal time quantum + /// + const PCAN_BR_NOM_BRP: String = 'nom_brp'; + /// + /// TSEG1 segment for nominal bit rate in time quanta + /// + const PCAN_BR_NOM_TSEG1: String = 'nom_tseg1'; + /// + /// TSEG2 segment for nominal bit rate in time quanta + /// + const PCAN_BR_NOM_TSEG2: String = 'nom_tseg2'; + /// + /// Synchronization Jump Width for nominal bit rate in time quanta + /// + const PCAN_BR_NOM_SJW: String = 'nom_sjw'; + /// + /// Sample point for nominal bit rate + /// + const PCAN_BR_NOM_SAMPLE: String = 'nom_sam'; + /// + /// Clock prescaler for highspeed data time quantum + /// + const PCAN_BR_DATA_BRP: String = 'data_brp'; + /// + /// TSEG1 segment for fast data bit rate in time quanta + /// + const PCAN_BR_DATA_TSEG1: String = 'data_tseg1'; + /// + /// TSEG2 segment for fast data bit rate in time quanta + /// + const PCAN_BR_DATA_TSEG2: String = 'data_tseg2'; + /// + /// Synchronization Jump Width for highspeed data bit rate in time quanta + /// + const PCAN_BR_DATA_SJW: String = 'data_sjw'; + /// + /// Secondary sample point delay for highspeed data bit rate in cyles + /// + const PCAN_BR_DATA_SAMPLE: String = 'data_ssp_offset'; + + /// + /// The PCAN parameter is not set (inactive) + /// + const PCAN_PARAMETER_OFF: Integer = 0; + /// + /// The PCAN parameter is set (active) + /// + const PCAN_PARAMETER_ON: Integer = 1; + /// + /// The PCAN filter is closed. No messages will be received + /// + const PCAN_FILTER_CLOSE: Integer = 0; + /// + /// The PCAN filter is fully opened. All messages will be received + /// + const PCAN_FILTER_OPEN: Integer = 1; + /// + /// The PCAN filter is custom configured. Only registered + /// messages will be received + /// + const PCAN_FILTER_CUSTOM: Integer = 2; + /// + /// The PCAN-Channel handle is illegal, or its associated hardware is not available + /// + const PCAN_CHANNEL_UNAVAILABLE: Integer = 0; + /// + /// The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) + /// + const PCAN_CHANNEL_AVAILABLE: Integer = 1; + /// + /// The PCAN-Channel handle is valid, and is already being used + /// + const PCAN_CHANNEL_OCCUPIED: Integer = 2; + /// + /// The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect + /// + const PCAN_CHANNEL_PCANVIEW: Integer = 3; + + /// + /// Logs system exceptions / errors + /// + const LOG_FUNCTION_DEFAULT: Integer = $00; + /// + /// Logs the entries to the PCAN-Basic API functions + /// + const LOG_FUNCTION_ENTRY: Integer = $01; + /// + /// Logs the parameters passed to the PCAN-Basic API functions + /// + const LOG_FUNCTION_PARAMETERS: Integer = $02; + /// + /// Logs the exits from the PCAN-Basic API functions + /// + const LOG_FUNCTION_LEAVE: Integer = $04; + /// + /// Logs the CAN messages passed to the CAN_Write function + /// + const LOG_FUNCTION_WRITE: Integer = $08; + /// + /// Logs the CAN messages received within the CAN_Read function + /// + const LOG_FUNCTION_READ: Integer = $10; + /// + /// Logs all possible information within the PCAN-Basic API functions + /// + const LOG_FUNCTION_ALL: Integer = $FFFF; + + /// + /// A single file is written until it size reaches PAN_TRACE_SIZE + /// + const TRACE_FILE_SINGLE: Integer = $00; + /// + /// Traced data is distributed in several files with size PAN_TRACE_SIZE + /// + const TRACE_FILE_SEGMENTED: Integer = $01; + /// + /// Includes the date into the name of the trace file + /// + const TRACE_FILE_DATE: Integer = $02; + /// + /// Includes the start time into the name of the trace file + /// + const TRACE_FILE_TIME: Integer = $04; + /// + /// Causes the overwriting of available traces (same name) + /// + const TRACE_FILE_OVERWRITE: Integer = $80; + + /// + /// Device supports flexible data-rate (CAN-FD) + /// + const FEATURE_FD_CAPABLE: Integer = $01; + /// + /// Device supports a delay between sending frames (FPGA based USB devices) + /// + const FEATURE_DELAY_CAPABLE: Integer = $2; + /// + /// Device supports I/O functionality for electronic circuits (USB-Chip devices) + /// + const FEATURE_IO_CAPABLE: Integer = $4; + + /// + /// The service is not running + /// + const SERVICE_STATUS_STOPPED: Integer = $01; + /// + /// The service is running + /// + const SERVICE_STATUS_RUNNING: Integer = $04; + + /// + /// Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) + /// + const LOOKUP_DEVICE_TYPE: String = 'devicetype'; + /// + /// Lookup channel by device id + /// + const LOOKUP_DEVICE_ID: String = 'deviceid'; + /// + /// Lookup channel by CAN controller 0-based index + /// + const LOOKUP_CONTROLLER_NUMBER: String = 'controllernumber'; + /// + /// Lookup channel by IP address (LAN channels only) + /// + const LOOKUP_IP_ADDRESS: String = 'ipaddress'; + + /// + /// Maximum length of the name of a device: 32 characters + terminator + /// + const MAX_LENGTH_HARDWARE_NAME: Integer = 33; + /// + /// Maximum length of a version string: 255 characters + terminator + /// + const MAX_LENGTH_VERSION_STRING: Integer = 256; + + /// + /// Initializes a PCAN Channel + /// + /// The handle of a PCAN Channel + /// The speed for the communication (BTR0BTR1 code) + /// Non-PnP: The type of hardware and operation mode + /// Non-PnP: The I/O address for the parallel port + /// Non-PnP: Interrupt number of the parallel port + /// A TPCANStatus error code + class function Initialize( + Channel: TPCANHandle; + Btr0Btr1: TPCANBaudrate; + HwType: TPCANType; + IOPort: LongWord; + Interrupt: Word + ): TPCANStatus; overload; + + /// + /// Initializes a PCAN Channel + /// + /// The handle of a PCAN Channel + /// The speed for the communication (BTR0BTR1 code) + /// A TPCANStatus error code + class function Initialize( + Channel: TPCANHandle; + Btr0Btr1: TPCANBaudrate + ): TPCANStatus; overload; + + /// + /// Initializes a FD capable PCAN Channel + /// + /// The handle of a PCAN Channel + /// The speed for the communication (FD bit rate string) + /// See PCAN_BR_* values + /// Bit rate string must follow the following construction rules: + /// * 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 + /// 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 + /// A TPCANStatus error code + class function InitializeFD( + Channel: TPCANHandle; + BitrateFD: TPCANBitrateFD + ): TPCANStatus; + + /// + /// Uninitializes one or all PCAN Channels initialized by CAN_Initialize + /// + /// Giving the TPCANHandle value "PCAN_NONEBUS", + /// uninitialize all initialized channels + /// The handle of a PCAN Channel + /// A TPCANStatus error code + class function Uninitialize( + Channel: TPCANHandle + ): TPCANStatus; + + /// + /// Resets the receive and transmit queues of the PCAN Channel + /// + /// A reset of the CAN controller is not performed + /// The handle of a PCAN Channel + /// A TPCANStatus error code + class function Reset( + Channel: TPCANHandle + ): TPCANStatus; + + /// + /// Gets the current status of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANStatus error code + class function GetStatus( + Channel: TPCANHandle + ): TPCANStatus; + + /// + /// Reads a CAN message from the receive queue of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANMsg structure buffer to store the CAN message + /// A TPCANTimestamp structure buffer to get + /// the reception time of the message + /// A TPCANStatus error code + class function Read( + Channel: TPCANHandle; + var MessageBuffer: TPCANMsg; + var TimestampBuffer: TPCANTimestamp + ):TPCANStatus; overload; + + /// + /// Reads a CAN message from the receive queue of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANMsg structure buffer to store the CAN message + /// A TPCANStatus error code + class function Read( + Channel: TPCANHandle; + var MessageBuffer: TPCANMsg + ): TPCANStatus; overload; + + /// + /// Reads a CAN message from the receive queue of a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD structure buffer to store the CAN message + /// A TPCANTimestampFD buffer to get the + /// reception time of the message + /// A TPCANStatus error code + class function ReadFD( + Channel: TPCANHandle; + var MessageBuffer: TPCANMsgFD; + var TimestampBuffer: TPCANTimestampFD + ):TPCANStatus; overload; + + /// + /// Reads a CAN message from the receive queue of a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD structure buffer to store the CAN message + /// A TPCANStatus error code + class function ReadFD( + Channel: TPCANHandle; + var MessageBuffer: TPCANMsgFD + ):TPCANStatus; overload; + + /// + /// Transmits a CAN message + /// + /// The handle of a PCAN Channel + /// A TPCANMsg buffer with the message to be sent + /// A TPCANStatus error code + class function Write( + Channel: TPCANHandle; + var MessageBuffer: TPCANMsg + ): TPCANStatus; + + /// + /// Transmits a CAN message over a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD buffer with the message to be sent + /// A TPCANStatus error code + class function WriteFD( + Channel: TPCANHandle; + var MessageBuffer: TPCANMsgFD + ): TPCANStatus; + + /// + /// Configures the reception filter + /// + /// 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 + /// The handle of a PCAN Channel + /// The lowest CAN ID to be received + /// The highest CAN ID to be received + /// Message type, Standard (11-bit identifier) or + /// Extended (29-bit identifier) + /// A TPCANStatus error code + class function FilterMessages( + Channel: TPCANHandle; + FromID: LongWord; + ToID: LongWord; + Mode: TPCANMode + ): TPCANStatus; + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + class function GetValue( + Channel: TPCANHandle; + Parameter: TPCANParameter; + NumericBuffer: PLongWord; + BufferLength: LongWord + ): TPCANStatus; overload; + + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + class function GetValue( + Channel: TPCANHandle; + Parameter: TPCANParameter; + NumericBuffer: PUInt64; + BufferLength: LongWord + ): TPCANStatus; overload; + + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + class function GetValue( + Channel: TPCANHandle; + Parameter: TPCANParameter; + StringBuffer: PAnsiChar; + BufferLength: LongWord + ): TPCANStatus; overload; + + class function GetValue( + Channel: TPCANHandle; + Parameter: TPCANParameter; + ChannelsBuffer: PTPCANChannelInformation; + BufferLength: LongWord + ): TPCANStatus; overload; + + /// + /// Configures or sets a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to set + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + class function SetValue( + Channel: TPCANHandle; + Parameter: TPCANParameter; + NumericBuffer: PLongWord; + BufferLength: LongWord + ): TPCANStatus; overload; + + /// + /// Configures or sets a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to set + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + class function SetValue( + Channel: TPCANHandle; + Parameter: TPCANParameter; + NumericBuffer: PUInt64; + BufferLength: LongWord + ): TPCANStatus; overload; + + /// + /// Configures or sets a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to set + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + class function SetValue( + Channel: TPCANHandle; + Parameter: TPCANParameter; + StringBuffer: PAnsiChar; + BufferLength: LongWord + ): TPCANStatus; overload; + + /// + /// Returns a descriptive text of a given TPCANStatus error + /// code, in any desired language + /// + /// The current languages available for translation are: + /// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), + /// Italian (0x10) and French (0x0C) + /// A TPCANStatus error code + /// Indicates a 'Primary language ID' + /// Buffer for the text (must be at least 256 in length) + /// A TPCANStatus error code + class function GetErrorText( + Error: TPCANStatus; + Language: Word; + StringBuffer: PAnsiChar + ): TPCANStatus; + + /// + /// Finds a PCAN-Basic channel that matches with the given parameters + /// + /// A comma separated string contained pairs of + /// parameter-name/value to be matched within a PCAN-Basic channel + /// Buffer for returning the PCAN-basic channel, + /// when found + /// A TPCANStatus error code + class function LookUpChannel( + Parameters: PAnsiChar; + FoundChannel: PTPCANHandle + ): TPCANStatus; + end; + +implementation + +uses SysUtils; + +const DLL_Name = 'PCANBASIC.DLL'; + +function CAN_Initialize(Channel: TPCANHandle; Btr0Btr1: TPCANBaudrate; HwType: TPCANType; IOPort: LongWord; Interrupt: Word): TPCANStatus; stdcall; +external DLL_Name; +function CAN_InitializeFD(Channel: TPCANHandle; BitrateFD: TPCANBitrateFD): TPCANStatus; stdcall; +external DLL_Name; +function CAN_Uninitialize(Channel: TPCANHandle): TPCANStatus; stdcall; +external DLL_Name; +function CAN_Reset(Channel: TPCANHandle): TPCANStatus; stdcall; +external DLL_Name; +function CAN_GetStatus(Channel: TPCANHandle): TPCANStatus; stdcall; +external DLL_Name; +function CAN_Read(Channel: TPCANHandle; var MessageBuffer: TPCANMsg; TimestampBuffer: PTPCANTimestamp):TPCANStatus; overload; stdcall; +external DLL_Name; +function CAN_ReadFD(Channel: TPCANHandle; var MessageBuffer: TPCANMsgFD; TimestampBuffer: PUInt64):TPCANStatus; overload; stdcall; +external DLL_Name; +function CAN_Write(Channel: TPCANHandle; var MessageBuffer: TPCANMsg): TPCANStatus; stdcall; +external DLL_Name; +function CAN_WriteFD(Channel: TPCANHandle; var MessageBuffer: TPCANMsgFD): TPCANStatus; stdcall; +external DLL_Name; +function CAN_FilterMessages(Channel: TPCANHandle; FromID: LongWord; ToID: LongWord; Mode: TPCANMode): TPCANStatus; stdcall; +external DLL_Name; +function CAN_GetValue(Channel: TPCANHandle; Parameter: TPCANParameter; Buffer: Pointer; BufferLength: LongWord): TPCANStatus; stdcall; +external DLL_Name; +function CAN_SetValue(Channel: TPCANHandle; Parameter: TPCANParameter; Buffer: Pointer; BufferLength: LongWord): TPCANStatus; stdcall; +external DLL_Name; +function CAN_GetErrorText(Error: TPCANStatus; Language: Word; StringBuffer: PAnsiChar): TPCANStatus; stdcall; +external DLL_Name; +function CAN_LookUpChannel(Parameters: PAnsiChar; FoundChannel: PTPCANHandle): TPCANStatus; stdcall; +external DLL_Name; + +class function TPCANBasic.Initialize(Channel: TPCANHandle; Btr0Btr1: TPCANBaudrate; HwType: TPCANType; IOPort: LongWord; Interrupt: Word): TPCANStatus; +begin + Result:= CAN_Initialize(Channel,Btr0Btr1,HwType,IOPort,Interrupt); +end; + +class function TPCANBasic.Initialize(Channel: TPCANHandle; Btr0Btr1: TPCANBaudrate): TPCANStatus; +begin + Result:= CAN_Initialize(Channel,Btr0Btr1,PCAN_TYPE_ISA, 0,0); +end; + +class function TPCANBasic.InitializeFD(Channel: TPCANHandle; BitrateFD: TPCANBitrateFD): TPCANStatus; +begin + Result:= CAN_InitializeFD(Channel,BitrateFD); +end; + +class function TPCANBasic.Uninitialize(Channel: TPCANHandle): TPCANStatus; +begin + Result:= CAN_Uninitialize(Channel); +end; + +class function TPCANBasic.Reset(Channel: TPCANHandle): TPCANStatus; +begin + Result:= CAN_Reset(Channel); +end; + +class function TPCANBasic.GetStatus(Channel: TPCANHandle): TPCANStatus; +begin + Result:= CAN_GetStatus(Channel); +end; + +class function TPCANBasic.Read(Channel: TPCANHandle; var MessageBuffer: TPCANMsg; var TimestampBuffer: TPCANTimestamp):TPCANStatus; +begin + Result:= CAN_Read(Channel, MessageBuffer, @TimestampBuffer); +end; + +class function TPCANBasic.Read(Channel: TPCANHandle; var MessageBuffer: TPCANMsg):TPCANStatus; +begin + Result:= CAN_Read(Channel, MessageBuffer, nil); +end; + +class function TPCANBasic.ReadFD(Channel: TPCANHandle; var MessageBuffer: TPCANMsgFD; var TimestampBuffer: TPCANTimestampFD):TPCANStatus; +begin + Result:= CAN_ReadFD(Channel, MessageBuffer, @TimestampBuffer); +end; + +class function TPCANBasic.ReadFD(Channel: TPCANHandle; var MessageBuffer: TPCANMsgFD):TPCANStatus; +begin + Result:= CAN_ReadFD(Channel, MessageBuffer, nil); +end; + +class function TPCANBasic.Write(Channel: TPCANHandle; var MessageBuffer: TPCANMsg): TPCANStatus; +begin + Result:= CAN_Write(Channel, MessageBuffer); +end; + +class function TPCANBasic.WriteFD(Channel: TPCANHandle; var MessageBuffer: TPCANMsgFD): TPCANStatus; +begin + Result:= CAN_WriteFD(Channel, MessageBuffer); +end; + +class function TPCANBasic.FilterMessages(Channel: TPCANHandle; FromID: LongWord; ToID: LongWord; Mode: TPCANMode): TPCANStatus; +begin + Result:= CAN_FilterMessages(Channel, FromID,ToID,Mode); +end; + +class function TPCANBasic.GetValue(Channel: TPCANHandle; Parameter: TPCANParameter; NumericBuffer: PLongWord; BufferLength: LongWord): TPCANStatus; +begin + Result:= CAN_GetValue(Channel, Parameter, NumericBuffer, BufferLength); +end; + +class function TPCANBasic.GetValue(Channel: TPCANHandle; Parameter: TPCANParameter; NumericBuffer: PUInt64; BufferLength: LongWord): TPCANStatus; +begin + Result:= CAN_GetValue(Channel, Parameter, NumericBuffer, BufferLength); +end; + +class function TPCANBasic.GetValue(Channel: TPCANHandle; Parameter: TPCANParameter; StringBuffer: PAnsiChar; BufferLength: LongWord): TPCANStatus; +begin + Result:= CAN_GetValue(Channel, Parameter, StringBuffer, BufferLength); +end; + +class function TPCANBasic.GetValue(Channel: TPCANHandle; Parameter: TPCANParameter; ChannelsBuffer: PTPCANChannelInformation; BufferLength: LongWord): TPCANStatus; +begin + Result:= CAN_GetValue(Channel, Parameter, ChannelsBuffer, BufferLength); +end; + +class function TPCANBasic.SetValue(Channel: TPCANHandle; Parameter: TPCANParameter; NumericBuffer: PLongWord; BufferLength: LongWord): TPCANStatus; +begin + Result:= CAN_SetValue(Channel, Parameter, NumericBuffer, BufferLength); +end; + +class function TPCANBasic.SetValue(Channel: TPCANHandle; Parameter: TPCANParameter; NumericBuffer: PUInt64; BufferLength: LongWord): TPCANStatus; +begin + Result:= CAN_SetValue(Channel, Parameter, NumericBuffer, BufferLength); +end; + +class function TPCANBasic.SetValue(Channel: TPCANHandle; Parameter: TPCANParameter; StringBuffer: PAnsiChar; BufferLength: LongWord): TPCANStatus; +begin + Result:= CAN_SetValue(Channel, Parameter, StringBuffer, BufferLength); +end; + +class function TPCANBasic.GetErrorText(Error: TPCANStatus; Language: Word; StringBuffer: PAnsiChar): TPCANStatus; +begin + Result:= CAN_GetErrorText(Error, Language, StringBuffer); +end; + +class function TPCANBasic.LookUpChannel(Parameters: PAnsiChar; FoundChannel: PTPCANHandle): TPCANStatus; +begin + Result:= CAN_LookUpChannel(Parameters, FoundChannel); +end; + +end. \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Include/PCANBasic.py b/PCAN API/PCAN-Basic API/Include/PCANBasic.py new file mode 100644 index 0000000..a141c09 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Include/PCANBasic.py @@ -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 diff --git a/PCAN API/PCAN-Basic API/Include/PCANBasic.vb b/PCAN API/PCAN-Basic API/Include/PCANBasic.vb new file mode 100644 index 0000000..fc15f62 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Include/PCANBasic.vb @@ -0,0 +1,1501 @@ +' PCANBasic.cs +' +' ~~~~~~~~~~~~ +' +' PCAN-Basic API +' +' ~~~~~~~~~~~~ +' +' ------------------------------------------------------------------ +' Author : Keneth Wagner +' Last change: 2022-07-06 +' +' Language: VB .NET +' ------------------------------------------------------------------ +' +' Copyright (C) 1999-2022 PEAK-System Technik GmbH, Darmstadt +' more Info at http://www.peak-system.com +' +Imports System +Imports System.Text +Imports System.Runtime.InteropServices + +Imports TPCANHandle = System.UInt16 +Imports TPCANBitrateFD = System.String +Imports TPCANTimestampFD = System.UInt64 + +Namespace Peak.Can.Basic +#Region "Enumerations" + ''' + ''' Represents a PCAN status/error code + ''' + _ + Public Enum TPCANStatus As UInt32 + ''' + ''' No error + ''' + PCAN_ERROR_OK = &H0 + ''' + ''' Transmit buffer in CAN controller is full + ''' + PCAN_ERROR_XMTFULL = &H1 + ''' + ''' CAN controller was read too late + ''' + PCAN_ERROR_OVERRUN = &H2 + ''' + ''' Bus error: an error counter reached the 'light' limit + ''' + PCAN_ERROR_BUSLIGHT = &H4 + ''' + ''' Bus error: an error counter reached the 'heavy' limit + ''' + PCAN_ERROR_BUSHEAVY = &H8 + ''' + ''' Bus error: an error counter reached the 'warning' limit + ''' + PCAN_ERROR_BUSWARNING = PCAN_ERROR_BUSHEAVY + ''' + ''' Bus error: the CAN controller is error passive + ''' + PCAN_ERROR_BUSPASSIVE = &H40000 + ''' + ''' Bus error: the CAN controller is in bus-off state + ''' + PCAN_ERROR_BUSOFF = &H10 + ''' + ''' Mask for all bus errors + ''' + PCAN_ERROR_ANYBUSERR = (PCAN_ERROR_BUSWARNING Or PCAN_ERROR_BUSLIGHT Or PCAN_ERROR_BUSHEAVY Or PCAN_ERROR_BUSOFF Or PCAN_ERROR_BUSPASSIVE) + ''' + ''' Receive queue is empty + ''' + PCAN_ERROR_QRCVEMPTY = &H20 + ''' + ''' Receive queue was read too late + ''' + PCAN_ERROR_QOVERRUN = &H40 + ''' + ''' Transmit queue is full + ''' + PCAN_ERROR_QXMTFULL = &H80 + ''' + ''' Test of the CAN controller hardware registers failed (no hardware found) + ''' + PCAN_ERROR_REGTEST = &H100 + ''' + ''' Driver not loaded + ''' + PCAN_ERROR_NODRIVER = &H200 + ''' + ''' Hardware already in use by a Net + ''' + PCAN_ERROR_HWINUSE = &H400 + ''' + ''' A Client is already connected to the Net + ''' + PCAN_ERROR_NETINUSE = &H800 + ''' + ''' Hardware handle is invalid + ''' + PCAN_ERROR_ILLHW = &H1400 + ''' + ''' Net handle is invalid + ''' + PCAN_ERROR_ILLNET = &H1800 + ''' + ''' Client handle is invalid + ''' + PCAN_ERROR_ILLCLIENT = &H1C00 + ''' + ''' Mask for all handle errors + ''' + PCAN_ERROR_ILLHANDLE = (PCAN_ERROR_ILLHW Or PCAN_ERROR_ILLNET Or PCAN_ERROR_ILLCLIENT) + ''' + ''' Resource (FIFO, Client, timeout) cannot be created + ''' + PCAN_ERROR_RESOURCE = &H2000 + ''' + ''' Invalid parameter + ''' + PCAN_ERROR_ILLPARAMTYPE = &H4000 + ''' + ''' Invalid parameter value + ''' + PCAN_ERROR_ILLPARAMVAL = &H8000 + ''' + ''' Unknown error + ''' + PCAN_ERROR_UNKNOWN = &H10000 + ''' + ''' Invalid data, function, or action. + ''' + PCAN_ERROR_ILLDATA = &H20000 + ''' + ''' Driver object state is wrong for the attempted operation + ''' + PCAN_ERROR_ILLMODE = &H80000 + ''' + ''' An operation was successfully carried out, however, irregularities were registered + ''' + PCAN_ERROR_CAUTION = &H2000000 + ''' + ''' Channel is not initialized + ''' Value was changed from 0x40000 to 0x4000000 + ''' + PCAN_ERROR_INITIALIZE = &H4000000 + ''' + ''' Invalid operation + ''' Value was changed from 0x80000 to 0x8000000 + ''' + PCAN_ERROR_ILLOPERATION = &H8000000 + End Enum + + ''' + ''' Represents a PCAN device + ''' + Public Enum TPCANDevice As Byte + ''' + ''' Undefined, unknown or not selected PCAN device value + ''' + PCAN_NONE = 0 + ''' + ''' PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API + ''' + PCAN_PEAKCAN = 1 + ''' + ''' PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus + ''' + PCAN_ISA = 2 + ''' + ''' PCAN-Dongle + ''' + PCAN_DNG = 3 + ''' + ''' PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express + ''' + PCAN_PCI = 4 + ''' + ''' PCAN-USB and PCAN-USB Pro + ''' + PCAN_USB = 5 + ''' + ''' PCAN-PC Card + ''' + PCAN_PCC = 6 + ''' + ''' PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API + ''' + PCAN_VIRTUAL = 7 + ''' + ''' PCAN Gateway devices + ''' + PCAN_LAN = 8 + End Enum + + ''' + ''' Represents a PCAN parameter to be read or set + ''' + Public Enum TPCANParameter As Byte + ''' + ''' Device identifier parameter + ''' + PCAN_DEVICE_ID = 1 + ''' + ''' DEPRECATED. Use PCAN_DEVICE_ID instead + ''' + + PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID + ''' + ''' 5-Volt power parameter + ''' + PCAN_5VOLTS_POWER = 2 + ''' + ''' PCAN receive event handler parameter + ''' + PCAN_RECEIVE_EVENT = 3 + ''' + ''' PCAN message filter parameter + ''' + PCAN_MESSAGE_FILTER = 4 + ''' + ''' PCAN-Basic API version parameter + ''' + PCAN_API_VERSION = 5 + ''' + ''' PCAN device channel version parameter + ''' + PCAN_CHANNEL_VERSION = 6 + ''' + ''' PCAN Reset-On-Busoff parameter + ''' + PCAN_BUSOFF_AUTORESET = 7 + ''' + ''' PCAN Listen-Only parameter + ''' + PCAN_LISTEN_ONLY = 8 + ''' + ''' Directory path for log files + ''' + PCAN_LOG_LOCATION = 9 + ''' + ''' Debug-Log activation status + ''' + PCAN_LOG_STATUS = 10 + ''' + ''' Configuration of the debugged information (LOG_FUNCTION_***) + ''' + PCAN_LOG_CONFIGURE = 11 + ''' + ''' Custom insertion of text into the log file + ''' + PCAN_LOG_TEXT = 12 + ''' + ''' Availability status of a PCAN-Channel + ''' + PCAN_CHANNEL_CONDITION = 13 + ''' + ''' PCAN hardware name parameter + ''' + PCAN_HARDWARE_NAME = 14 + ''' + ''' Message reception status of a PCAN-Channel + ''' + PCAN_RECEIVE_STATUS = 15 + ''' + ''' CAN-Controller number of a PCAN-Channel + ''' + PCAN_CONTROLLER_NUMBER = 16 + ''' + ''' Directory path for PCAN trace files + ''' + PCAN_TRACE_LOCATION = 17 + ''' + ''' CAN tracing activation status + ''' + PCAN_TRACE_STATUS = 18 + ''' + ''' Configuration of the maximum file size of a CAN trace + ''' + PCAN_TRACE_SIZE = 19 + ''' + ''' Configuration of the trace file storing mode (TRACE_FILE_***) + ''' + PCAN_TRACE_CONFIGURE = 20 + ''' + ''' Physical identification of a USB based PCAN-Channel by blinking its associated LED + ''' + PCAN_CHANNEL_IDENTIFYING = 21 + ''' + ''' Capabilities of a PCAN device (FEATURE_***) + ''' + PCAN_CHANNEL_FEATURES = 22 + ''' + ''' Using of an existing bit rate (PCAN-View connected to a channel) + ''' + PCAN_BITRATE_ADAPTING = 23 + ''' + ''' Configured bit rate as Btr0Btr1 value + ''' + PCAN_BITRATE_INFO = 24 + ''' + ''' Configured bit rate as TPCANBitrateFD string + ''' + PCAN_BITRATE_INFO_FD = 25 + ''' + ''' Configured nominal CAN Bus speed as Bits per seconds + ''' + PCAN_BUSSPEED_NOMINAL = 26 + ''' + ''' Configured CAN data speed as Bits per seconds + ''' + PCAN_BUSSPEED_DATA = 27 + ''' + ''' Remote address of a LAN channel as string in IPv4 format + ''' + PCAN_IP_ADDRESS = 28 + ''' + ''' Status of the Virtual PCAN-Gateway Service + ''' + PCAN_LAN_SERVICE_STATUS = 29 + ''' + ''' Status messages reception status within a PCAN-Channel + ''' + PCAN_ALLOW_STATUS_FRAMES = 30 + ''' + ''' RTR messages reception status within a PCAN-Channel + ''' + PCAN_ALLOW_RTR_FRAMES = 31 + ''' + ''' Error messages reception status within a PCAN-Channel + ''' + PCAN_ALLOW_ERROR_FRAMES = 32 + ''' + ''' Delay, in microseconds, between sending frames + ''' + PCAN_INTERFRAME_DELAY = 33 + ''' + ''' Filter over code and mask patterns for 11-Bit messages + ''' + PCAN_ACCEPTANCE_FILTER_11BIT = 34 + ''' + ''' Filter over code and mask patterns for 29-Bit messages + ''' + PCAN_ACCEPTANCE_FILTER_29BIT = 35 + ''' + ''' Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive + ''' + PCAN_IO_DIGITAL_CONFIGURATION = 36 + ''' + ''' Value assigned to a 32 digital I/O pins of a PCAN-USB Chip + ''' + PCAN_IO_DIGITAL_VALUE = 37 + ''' + ''' 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_SET = 38 + ''' + ''' Clear multiple digital I/O pins to 0 + ''' + PCAN_IO_DIGITAL_CLEAR = 39 + ''' + ''' Get value of a single analog input pin + ''' + PCAN_IO_ANALOG_VALUE = 40 + ''' + ''' Get the version of the firmware used by the device associated with a PCAN-Channel + ''' + PCAN_FIRMWARE_VERSION = 41 + ''' + ''' Get the amount of PCAN channels attached to a system + ''' + PCAN_ATTACHED_CHANNELS_COUNT = 42 + ''' + ''' Get information about PCAN channels attached to a system + ''' + PCAN_ATTACHED_CHANNELS = 43 + ''' + ''' Echo messages reception status within a PCAN-Channel + ''' + PCAN_ALLOW_ECHO_FRAMES = 44 + ''' + ''' Get the part number associated to a device + ''' + PCAN_DEVICE_PART_NUMBER = 45 + End Enum + + ''' + ''' Represents the type of a PCAN message + ''' + _ + Public Enum TPCANMessageType As Byte + ''' + ''' The PCAN message is a CAN Standard Frame (11-bit identifier) + ''' + PCAN_MESSAGE_STANDARD = &H0 + ''' + ''' The PCAN message is a CAN Remote-Transfer-Request Frame + ''' + PCAN_MESSAGE_RTR = &H1 + ''' + ''' The PCAN message is a CAN Extended Frame (29-bit identifier) + ''' + PCAN_MESSAGE_EXTENDED = &H2 + ''' + ''' The PCAN message represents a FD frame in terms of CiA Specs + ''' + PCAN_MESSAGE_FD = &H4 + ''' + ''' The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) + ''' + PCAN_MESSAGE_BRS = &H8 + ''' + ''' The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) + ''' + PCAN_MESSAGE_ESI = &H10 + ''' + ''' The PCAN message represents an echo CAN Frame + ''' + PCAN_MESSAGE_ECHO = &H20 + ''' + ''' The PCAN message represents an error frame + ''' + PCAN_MESSAGE_ERRFRAME = &H40 + ''' + ''' The PCAN message represents a PCAN status message + ''' + PCAN_MESSAGE_STATUS = &H80 + End Enum + + ''' + ''' Represents a PCAN filter mode + ''' + Public Enum TPCANMode As Byte + ''' + ''' Mode is Standard (11-bit identifier) + ''' + PCAN_MODE_STANDARD = TPCANMessageType.PCAN_MESSAGE_STANDARD + ''' + ''' Mode is Extended (29-bit identifier) + ''' + PCAN_MODE_EXTENDED = TPCANMessageType.PCAN_MESSAGE_EXTENDED + End Enum + + ''' + ''' Represents a PCAN Baud rate register value + ''' + Public Enum TPCANBaudrate As UInt16 + ''' + ''' 1 MBit/s + ''' + PCAN_BAUD_1M = &H14 + ''' + ''' 800 kBit/s + ''' + PCAN_BAUD_800K = &H16 + ''' + ''' 500 kBit/s + ''' + PCAN_BAUD_500K = &H1C + ''' + ''' 250 kBit/s + ''' + PCAN_BAUD_250K = &H11C + ''' + ''' 125 kBit/s + ''' + PCAN_BAUD_125K = &H31C + ''' + ''' 100 kBit/s + ''' + PCAN_BAUD_100K = &H432F + ''' + ''' 95,238 kBit/s + ''' + PCAN_BAUD_95K = &HC34E + ''' + ''' 83,333 kBit/s + ''' + PCAN_BAUD_83K = &H852B + ''' + ''' 50 kBit/s + ''' + PCAN_BAUD_50K = &H472F + ''' + ''' 47,619 kBit/s + ''' + PCAN_BAUD_47K = &H1414 + ''' + ''' 33,333 kBit/s + ''' + PCAN_BAUD_33K = &H8B2F + ''' + ''' 20 kBit/s + ''' + PCAN_BAUD_20K = &H532F + ''' + ''' 10 kBit/s + ''' + PCAN_BAUD_10K = &H672F + ''' + ''' 5 kBit/s + ''' + PCAN_BAUD_5K = &H7F7F + End Enum + + ''' + ''' Represents the type of PCAN (Non-PnP) hardware to be initialized + ''' + Public Enum TPCANType As Byte + ''' + ''' PCAN-ISA 82C200 + ''' + PCAN_TYPE_ISA = &H1 + ''' + ''' PCAN-ISA SJA1000 + ''' + PCAN_TYPE_ISA_SJA = &H9 + ''' + ''' PHYTEC ISA + ''' + PCAN_TYPE_ISA_PHYTEC = &H4 + ''' + ''' PCAN-Dongle 82C200 + ''' + PCAN_TYPE_DNG = &H2 + ''' + ''' PCAN-Dongle EPP 82C200 + ''' + PCAN_TYPE_DNG_EPP = &H3 + ''' + ''' PCAN-Dongle SJA1000 + ''' + PCAN_TYPE_DNG_SJA = &H5 + ''' + ''' PCAN-Dongle EPP SJA1000 + ''' + PCAN_TYPE_DNG_SJA_EPP = &H6 + End Enum +#End Region + +#Region "Structures" + ''' + ''' Represents a PCAN message + ''' + Public Structure TPCANMsg + ''' + ''' 11/29-bit message identifier + ''' + Public ID As UInt32 + ''' + ''' Type of the message + ''' + _ + Public MSGTYPE As TPCANMessageType + ''' + ''' Data Length Code of the message (0..8) + ''' + Public LEN As Byte + ''' + ''' Data of the message (DATA[0]..DATA[7]) + ''' + _ + Public DATA As Byte() + End Structure + + ''' + ''' Represents a timestamp of a received PCAN message. + ''' Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow + ''' + Public Structure TPCANTimestamp + ''' + ''' Base-value: milliseconds: 0.. 2^32-1 + ''' + Public millis As UInt32 + ''' + ''' Roll-arounds of millis + ''' + Public millis_overflow As UInt16 + ''' + ''' Microseconds: 0..999 + ''' + Public micros As UInt16 + End Structure + + ''' + ''' Represents a PCAN message from a FD capable hardware + ''' + Public Structure TPCANMsgFD + ''' + ''' 11/29-bit message identifier + ''' + Public ID As UInt32 + ''' + ''' Type of the message + ''' + + Public MSGTYPE As TPCANMessageType + ''' + ''' Data Length Code of the message (0..15) + ''' + Public DLC As Byte + ''' + ''' Data of the message (DATA[0]..DATA[63]) + ''' + + Public DATA As Byte() + End Structure + + + ''' + ''' Describes an available PCAN channel + ''' + Public Structure TPCANChannelInformation + ''' + ''' PCAN channel handle + ''' + + Public channel_handle As TPCANHandle + ''' + ''' Kind of PCAN device + ''' + + Public device_type As TPCANDevice + ''' + ''' CAN-Controller number + ''' + Public controller_number As Byte + ''' + ''' Device capabilities flag (see FEATURE_*) + ''' + Public device_features As UInt32 + ''' + ''' Device name + ''' + + Public device_name As String + ''' + ''' Device number + ''' + Public device_id As UInt32 + ''' + ''' Availability status of a PCAN-Channel + ''' + Public channel_condition As UInt32 + End Structure +#End Region + +#Region "PCANBasic class" + ''' + ''' PCAN-Basic API class implementation + ''' + Public NotInheritable Class PCANBasic +#Region "PCAN-BUS Handles Definition" + ''' + ''' Undefined/default value for a PCAN bus + ''' + Public Const PCAN_NONEBUS As TPCANHandle = &H0 + + ''' + ''' PCAN-ISA interface, channel 1 + ''' + Public Const PCAN_ISABUS1 As TPCANHandle = &H21 + ''' + ''' PCAN-ISA interface, channel 2 + ''' + Public Const PCAN_ISABUS2 As TPCANHandle = &H22 + ''' + ''' PCAN-ISA interface, channel 3 + ''' + Public Const PCAN_ISABUS3 As TPCANHandle = &H23 + ''' + ''' PCAN-ISA interface, channel 4 + ''' + Public Const PCAN_ISABUS4 As TPCANHandle = &H24 + ''' + ''' PCAN-ISA interface, channel 5 + ''' + Public Const PCAN_ISABUS5 As TPCANHandle = &H25 + ''' + ''' PCAN-ISA interface, channel 6 + ''' + Public Const PCAN_ISABUS6 As TPCANHandle = &H26 + ''' + ''' PCAN-ISA interface, channel 7 + ''' + Public Const PCAN_ISABUS7 As TPCANHandle = &H27 + ''' + ''' PCAN-ISA interface, channel 8 + ''' + Public Const PCAN_ISABUS8 As TPCANHandle = &H28 + + ''' + ''' PPCAN-Dongle/LPT interface, channel 1 + ''' + Public Const PCAN_DNGBUS1 As TPCANHandle = &H31 + + ''' + ''' PCAN-PCI interface, channel 1 + ''' + Public Const PCAN_PCIBUS1 As TPCANHandle = &H41 + ''' + ''' PCAN-PCI interface, channel 2 + ''' + Public Const PCAN_PCIBUS2 As TPCANHandle = &H42 + ''' + ''' PCAN-PCI interface, channel 3 + ''' + Public Const PCAN_PCIBUS3 As TPCANHandle = &H43 + ''' + ''' PCAN-PCI interface, channel 4 + ''' + Public Const PCAN_PCIBUS4 As TPCANHandle = &H44 + ''' + ''' PCAN-PCI interface, channel 5 + ''' + Public Const PCAN_PCIBUS5 As TPCANHandle = &H45 + ''' + ''' PCAN-PCI interface, channel 6 + ''' + Public Const PCAN_PCIBUS6 As TPCANHandle = &H46 + ''' + ''' PCAN-PCI interface, channel 7 + ''' + Public Const PCAN_PCIBUS7 As TPCANHandle = &H47 + ''' + ''' PCAN-PCI interface, channel 8 + ''' + Public Const PCAN_PCIBUS8 As TPCANHandle = &H48 + ''' + ''' PCAN-PCI interface, channel 9 + ''' + Public Const PCAN_PCIBUS9 As TPCANHandle = &H409 + ''' + ''' PCAN-PCI interface, channel 10 + ''' + Public Const PCAN_PCIBUS10 As TPCANHandle = &H40A + ''' + ''' PCAN-PCI interface, channel 11 + ''' + Public Const PCAN_PCIBUS11 As TPCANHandle = &H40B + ''' + ''' PCAN-PCI interface, channel 12 + ''' + Public Const PCAN_PCIBUS12 As TPCANHandle = &H40C + ''' + ''' PCAN-PCI interface, channel 13 + ''' + Public Const PCAN_PCIBUS13 As TPCANHandle = &H40D + ''' + ''' PCAN-PCI interface, channel 14 + ''' + Public Const PCAN_PCIBUS14 As TPCANHandle = &H40E + ''' + ''' PCAN-PCI interface, channel 15 + ''' + Public Const PCAN_PCIBUS15 As TPCANHandle = &H40F + ''' + ''' PCAN-PCI interface, channel 16 + ''' + Public Const PCAN_PCIBUS16 As TPCANHandle = &H410 + + ''' + ''' PCAN-USB interface, channel 1 + ''' + Public Const PCAN_USBBUS1 As TPCANHandle = &H51 + ''' + ''' PCAN-USB interface, channel 2 + ''' + Public Const PCAN_USBBUS2 As TPCANHandle = &H52 + ''' + ''' PCAN-USB interface, channel 3 + ''' + Public Const PCAN_USBBUS3 As TPCANHandle = &H53 + ''' + ''' PCAN-USB interface, channel 4 + ''' + Public Const PCAN_USBBUS4 As TPCANHandle = &H54 + ''' + ''' PCAN-USB interface, channel 5 + ''' + Public Const PCAN_USBBUS5 As TPCANHandle = &H55 + ''' + ''' PCAN-USB interface, channel 6 + ''' + Public Const PCAN_USBBUS6 As TPCANHandle = &H56 + ''' + ''' PCAN-USB interface, channel 7 + ''' + Public Const PCAN_USBBUS7 As TPCANHandle = &H57 + ''' + ''' PCAN-USB interface, channel 8 + ''' + Public Const PCAN_USBBUS8 As TPCANHandle = &H58 + ''' + ''' PCAN-USB interface, channel 9 + ''' + Public Const PCAN_USBBUS9 As TPCANHandle = &H509 + ''' + ''' PCAN-USB interface, channel 10 + ''' + Public Const PCAN_USBBUS10 As TPCANHandle = &H50A + ''' + ''' PCAN-USB interface, channel 11 + ''' + Public Const PCAN_USBBUS11 As TPCANHandle = &H50B + ''' + ''' PCAN-USB interface, channel 12 + ''' + Public Const PCAN_USBBUS12 As TPCANHandle = &H50C + ''' + ''' PCAN-USB interface, channel 13 + ''' + Public Const PCAN_USBBUS13 As TPCANHandle = &H50D + ''' + ''' PCAN-USB interface, channel 14 + ''' + Public Const PCAN_USBBUS14 As TPCANHandle = &H50E + ''' + ''' PCAN-USB interface, channel 15 + ''' + Public Const PCAN_USBBUS15 As TPCANHandle = &H50F + ''' + ''' PCAN-USB interface, channel 16 + ''' + Public Const PCAN_USBBUS16 As TPCANHandle = &H510 + + ''' + ''' PCAN-PC Card interface, channel 1 + ''' + Public Const PCAN_PCCBUS1 As TPCANHandle = &H61 + ''' + ''' PCAN-PC Card interface, channel 2 + ''' + Public Const PCAN_PCCBUS2 As TPCANHandle = &H62 + + ''' + ''' PCAN-LAN interface, channel 1 + ''' + Public Const PCAN_LANBUS1 As TPCANHandle = &H801 + ''' + ''' PCAN-LAN interface, channel 2 + ''' + Public Const PCAN_LANBUS2 As TPCANHandle = &H802 + ''' + ''' PCAN-LAN interface, channel 3 + ''' + Public Const PCAN_LANBUS3 As TPCANHandle = &H803 + ''' + ''' PCAN-LAN interface, channel 4 + ''' + Public Const PCAN_LANBUS4 As TPCANHandle = &H804 + ''' + ''' PCAN-LAN interface, channel 5 + ''' + Public Const PCAN_LANBUS5 As TPCANHandle = &H805 + ''' + ''' PCAN-LAN interface, channel 6 + ''' + Public Const PCAN_LANBUS6 As TPCANHandle = &H806 + ''' + ''' PCAN-LAN interface, channel 7 + ''' + Public Const PCAN_LANBUS7 As TPCANHandle = &H807 + ''' + ''' PCAN-LAN interface, channel 8 + ''' + Public Const PCAN_LANBUS8 As TPCANHandle = &H808 + ''' + ''' PCAN-LAN interface, channel 9 + ''' + Public Const PCAN_LANBUS9 As TPCANHandle = &H809 + ''' + ''' PCAN-LAN interface, channel 10 + ''' + Public Const PCAN_LANBUS10 As TPCANHandle = &H80A + ''' + ''' PCAN-LAN interface, channel 11 + ''' + Public Const PCAN_LANBUS11 As TPCANHandle = &H80B + ''' + ''' PCAN-LAN interface, channel 12 + ''' + Public Const PCAN_LANBUS12 As TPCANHandle = &H80C + ''' + ''' PCAN-LAN interface, channel 13 + ''' + Public Const PCAN_LANBUS13 As TPCANHandle = &H80D + ''' + ''' PCAN-LAN interface, channel 14 + ''' + Public Const PCAN_LANBUS14 As TPCANHandle = &H80E + ''' + ''' PCAN-LAN interface, channel 15 + ''' + Public Const PCAN_LANBUS15 As TPCANHandle = &H80F + ''' + ''' PCAN-LAN interface, channel 16 + ''' + Public Const PCAN_LANBUS16 As TPCANHandle = &H810 +#End Region + +#Region "FD Bit rate parameters" + ''' + ''' Clock frequency in Herz (80000000, 60000000, 40000000, 30000000, 24000000, 20000000) + ''' + Public Const PCAN_BR_CLOCK As String = "f_clock" + ''' + ''' Clock frequency in Megaherz (80, 60, 40, 30, 24, 20) + ''' + Public Const PCAN_BR_CLOCK_MHZ As String = "f_clock_mhz" + ''' + ''' Clock prescaler for nominal time quantum + ''' + Public Const PCAN_BR_NOM_BRP As String = "nom_brp" + ''' + ''' TSEG1 segment for nominal bit rate in time quanta + ''' + Public Const PCAN_BR_NOM_TSEG1 As String = "nom_tseg1" + ''' + ''' TSEG2 segment for nominal bit rate in time quanta + ''' + Public Const PCAN_BR_NOM_TSEG2 As String = "nom_tseg2" + ''' + ''' Synchronization Jump Width for nominal bit rate in time quanta + ''' + Public Const PCAN_BR_NOM_SJW As String = "nom_sjw" + ''' + ''' Sample point for nominal bit rate + ''' + Public Const PCAN_BR_NOM_SAMPLE As String = "nom_sam" + ''' + ''' Clock prescaler for highspeed data time quantum + ''' + Public Const PCAN_BR_DATA_BRP As String = "data_brp" + ''' + ''' TSEG1 segment for fast data bit rate in time quanta + ''' + Public Const PCAN_BR_DATA_TSEG1 As String = "data_tseg1" + ''' + ''' TSEG2 segment for fast data bit rate in time quanta + ''' + Public Const PCAN_BR_DATA_TSEG2 As String = "data_tseg2" + ''' + ''' Synchronization Jump Width for highspeed data bit rate in time quanta + ''' + Public Const PCAN_BR_DATA_SJW As String = "data_sjw" + ''' + ''' Secondary sample point delay for highspeed data bit rate in cyles + ''' + Public Const PCAN_BR_DATA_SAMPLE As String = "data_ssp_offset" +#End Region + +#Region "Parameter values definition" + ''' + ''' The PCAN parameter is not set (inactive) + ''' + Public Const PCAN_PARAMETER_OFF As Integer = 0 + ''' + ''' The PCAN parameter is set (active) + ''' + Public Const PCAN_PARAMETER_ON As Integer = 1 + ''' + ''' The PCAN filter is closed. No messages will be received + ''' + Public Const PCAN_FILTER_CLOSE As Integer = 0 + ''' + ''' The PCAN filter is fully opened. All messages will be received + ''' + Public Const PCAN_FILTER_OPEN As Integer = 1 + ''' + ''' The PCAN filter is custom configured. Only registered + ''' messages will be received + ''' + Public Const PCAN_FILTER_CUSTOM As Integer = 2 + ''' + ''' The PCAN-Channel handle is illegal, or its associated hardware is not available + ''' + Public Const PCAN_CHANNEL_UNAVAILABLE As Integer = 0 + ''' + ''' The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) + ''' + Public Const PCAN_CHANNEL_AVAILABLE As Integer = 1 + ''' + ''' The PCAN-Channel handle is valid, and is already being used + ''' + Public Const PCAN_CHANNEL_OCCUPIED As Integer = 2 + ''' + ''' The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect + ''' + Public Const PCAN_CHANNEL_PCANVIEW As Integer = PCAN_CHANNEL_AVAILABLE Or PCAN_CHANNEL_OCCUPIED + + ''' + ''' Logs system exceptions / errors + ''' + Public Const LOG_FUNCTION_DEFAULT As Integer = &H0 + ''' + ''' Logs the entries to the PCAN-Basic API functions + ''' + Public Const LOG_FUNCTION_ENTRY As Integer = &H1 + ''' + ''' Logs the parameters passed to the PCAN-Basic API functions + ''' + Public Const LOG_FUNCTION_PARAMETERS As Integer = &H2 + ''' + ''' Logs the exits from the PCAN-Basic API functions + ''' + Public Const LOG_FUNCTION_LEAVE As Integer = &H4 + ''' + ''' Logs the CAN messages passed to the CAN_Write function + ''' + Public Const LOG_FUNCTION_WRITE As Integer = &H8 + ''' + ''' Logs the CAN messages received within the CAN_Read function + ''' + Public Const LOG_FUNCTION_READ As Integer = &H10 + ''' + ''' Logs all possible information within the PCAN-Basic API functions + ''' + Public Const LOG_FUNCTION_ALL As Integer = &HFFFF + + ''' + ''' A single file is written until it size reaches PAN_TRACE_SIZE + ''' + Public Const TRACE_FILE_SINGLE As Integer = &H0 + ''' + ''' Traced data is distributed in several files with size PAN_TRACE_SIZE + ''' + Public Const TRACE_FILE_SEGMENTED As Integer = &H1 + ''' + ''' Includes the date into the name of the trace file + ''' + Public Const TRACE_FILE_DATE As Integer = &H2 + ''' + ''' Includes the start time into the name of the trace file + ''' + Public Const TRACE_FILE_TIME As Integer = &H4 + ''' + ''' Causes the overwriting of available traces (same name) + ''' + Public Const TRACE_FILE_OVERWRITE As Integer = &H80 + + ''' + ''' Device supports flexible data-rate (CAN-FD) + ''' + Public Const FEATURE_FD_CAPABLE As Integer = &H1 + ''' + ''' Device supports a delay between sending frames (FPGA based USB devices) + ''' + Public Const FEATURE_DELAY_CAPABLE As Integer = &H2 + ''' + ''' Device supports I/O functionality for electronic circuits (USB-Chip devices) + ''' + Public Const FEATURE_IO_CAPABLE As Integer = &H4 + + ''' + ''' The service is not running + ''' + Public Const SERVICE_STATUS_STOPPED As Integer = &H1 + ''' + ''' The service is running + ''' + Public Const SERVICE_STATUS_RUNNING As Integer = &H4 +#End Region + +#Region "Lookup Parameters" + ''' + ''' Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) + ''' + Public Const LOOKUP_DEVICE_TYPE As String = "devicetype" + ''' + ''' Lookup channel by device id + ''' + Public Const LOOKUP_DEVICE_ID As String = "deviceid" + ''' + ''' Lookup channel by CAN controller 0-based index + ''' + Public Const LOOKUP_CONTROLLER_NUMBER As String = "controllernumber" + ''' + ''' Lookup channel by IP address (LAN channels only) + ''' + Public Const LOOKUP_IP_ADDRESS As String = "ipaddress" +#End Region + +#Region "Other Constants" + ''' + ''' Maximum length of the name of a device: 32 characters + terminator + ''' + Public Const MAX_LENGTH_HARDWARE_NAME As Integer = 33 + ''' + ''' ' Maximum length of a version string: 255 characters + terminator + ''' + Public Const MAX_LENGTH_VERSION_STRING As Integer = 256 +#End Region + +#Region "PCANBasic API Implementation" + ''' + ''' Initializes a PCAN Channel + ''' + ''' The handle of a PCAN Channel + ''' The speed for the communication (BTR0BTR1 code) + ''' Non-PnP: The type of hardware and operation mode + ''' Non-PnP: The I/O address for the parallel port + ''' Non-PnP: Interrupt number of the parallel por + ''' A TPCANStatus error code + _ + Public Shared Function Initialize( _ + _ + ByVal Channel As TPCANHandle, _ + _ + ByVal Btr0Btr1 As TPCANBaudrate, _ + _ + ByVal HwType As TPCANType, _ + ByVal IOPort As UInt32, _ + ByVal Interrupt As UInt16) As TPCANStatus + End Function + + ''' + ''' Initializes a PCAN Channel + ''' + ''' The handle of a PCAN Channel + ''' The speed for the communication (BTR0BTR1 code) + ''' A TPCANStatus error code + Public Shared Function Initialize( _ + ByVal Channel As TPCANHandle, _ + ByVal Btr0Btr1 As TPCANBaudrate) As TPCANStatus + Return Initialize(Channel, Btr0Btr1, 0, 0, 0) + End Function + + ''' + ''' Initializes a FD capable PCAN Channel + ''' + ''' The handle of a FD capable PCAN Channel + ''' The speed for the communication (FD bit rate string) + ''' See PCAN_BR_* values + ''' Bit rate string must follow the following construction rules: + ''' * 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 + ''' 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 + ''' A TPCANStatus error code + _ + Public Shared Function InitializeFD( _ + _ + ByVal Channel As TPCANHandle, _ + ByVal BitrateFD As TPCANBitrateFD) As TPCANStatus + End Function + + ''' + ''' Uninitializes one or all PCAN Channels initialized by CAN_Initialize + ''' + ''' Giving the TPCANHandle value "PCAN_NONEBUS", + ''' uninitialize all initialized channels + ''' The handle of a PCAN Channel + ''' A TPCANStatus error code + _ + Public Shared Function Uninitialize( _ + _ + ByVal Channel As TPCANHandle) As TPCANStatus + End Function + + ''' + ''' Resets the receive and transmit queues of the PCAN Channel + ''' + ''' A reset of the CAN controller is not performed + ''' The handle of a PCAN Channel + ''' A TPCANStatus error code + _ + Public Shared Function Reset( _ + _ + ByVal Channel As TPCANHandle) As TPCANStatus + End Function + + ''' + ''' Gets the current status of a PCAN Channel + ''' + ''' The handle of a PCAN Channel + ''' A TPCANStatus error code + _ + Public Shared Function GetStatus( _ + _ + ByVal Channel As TPCANHandle) As TPCANStatus + End Function + + ''' + ''' Reads a CAN message from the receive queue of a PCAN Channel + ''' + ''' The handle of a PCAN Channel + ''' A TPCANMsg structure buffer to store the CAN message + ''' A TPCANTimestamp structure buffer to get + ''' the reception time of the message + ''' A TPCANStatus error code + _ + Public Shared Function Read( _ + _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsg, _ + ByRef TimestampBuffer As TPCANTimestamp) As TPCANStatus + End Function + + _ + Private Shared Function Read( _ + _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsg, _ + ByVal BufferPointer As IntPtr) As TPCANStatus + End Function + + ''' + ''' Reads a CAN message from the receive queue of a PCAN Channel + ''' + ''' The handle of a PCAN Channel + ''' A TPCANMsg structure buffer to store the CAN message + ''' A TPCANStatus error code + Public Shared Function Read( _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsg) As TPCANStatus + Return Read(Channel, MessageBuffer, IntPtr.Zero) + End Function + + ''' + ''' Reads a CAN message from the receive queue of a FD capable PCAN Channel + ''' + ''' The handle of a FD capable PCAN Channel + ''' A TPCANMsgFD structure buffer to store the CAN message + ''' A TPCANTimestampFD buffer to get the + ''' reception time of the message + ''' A TPCANStatus error code + _ + Public Shared Function ReadFD( _ + _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsgFD, _ + ByRef TimestampBuffer As TPCANTimestampFD) As TPCANStatus + End Function + + _ + Private Shared Function ReadFD( _ + _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsgFD, _ + ByVal TimestampBuffer As IntPtr) As TPCANStatus + End Function + + ''' + ''' Reads a CAN message from the receive queue of a FD capable PCAN Channel + ''' + ''' The handle of a FD capable PCAN Channel + ''' A TPCANMsgFD structure buffer to store the CAN message + ''' A TPCANStatus error code + Public Shared Function ReadFD( _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsgFD) As TPCANStatus + Return ReadFD(Channel, MessageBuffer, IntPtr.Zero) + End Function + + ''' + ''' Transmits a CAN message + ''' + ''' The handle of a PCAN Channel + ''' A TPCANMsg buffer with the message to be sent + ''' A TPCANStatus error code + _ + Public Shared Function Write( _ + _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsg) As TPCANStatus + End Function + + ''' + ''' Transmits a CAN message over a FD capable PCAN Channel + ''' + ''' The handle of a FD capable PCAN Channel + ''' A TPCANMsgFD buffer with the message to be sent + ''' A TPCANStatus error code + _ + Public Shared Function WriteFD( _ + _ + ByVal Channel As TPCANHandle, _ + ByRef MessageBuffer As TPCANMsgFD) As TPCANStatus + End Function + + ''' + ''' Configures the reception filter + ''' + ''' 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 + ''' The handle of a PCAN Channel + ''' The lowest CAN ID to be received + ''' The highest CAN ID to be received + ''' Message type, Standard (11-bit identifier) or + ''' Extended (29-bit identifier) + ''' A TPCANStatus error code + _ + Public Shared Function FilterMessages( _ + _ + ByVal Channel As TPCANHandle, _ + ByVal FromID As UInt32, _ + ByVal ToID As UInt32, _ + _ + ByVal Mode As TPCANMode) As TPCANStatus + End Function + + ''' + ''' Retrieves a PCAN Channel value + ''' + ''' 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 handle of a PCAN Channel + ''' The TPCANParameter parameter to get + ''' Buffer for the parameter value + ''' Size in bytes of the buffer + ''' A TPCANStatus error code + _ + Public Shared Function GetValue( _ + _ + ByVal Channel As TPCANHandle, _ + _ + ByVal Parameter As TPCANParameter, _ + ByVal StringBuffer As StringBuilder, _ + ByVal BufferLength As UInt32) As TPCANStatus + End Function + + ''' + ''' Retrieves a PCAN Channel value + ''' + ''' 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 handle of a PCAN Channel + ''' The TPCANParameter parameter to get + ''' Buffer for the parameter value + ''' Size in bytes of the buffer + ''' A TPCANStatus error code + + Public Shared Function GetValue( + + ByVal Channel As TPCANHandle, + + ByVal Parameter As TPCANParameter, + ByRef NumericBuffer As UInt32, + ByVal BufferLength As UInt32) As TPCANStatus + End Function + + ''' + ''' Retrieves a PCAN Channel value + ''' + ''' 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 handle of a PCAN Channel + ''' The TPCANParameter parameter to get + ''' Buffer for the parameter value + ''' Size in bytes of the buffer + ''' A TPCANStatus error code + + Public Shared Function GetValue( + + ByVal Channel As TPCANHandle, + + ByVal Parameter As TPCANParameter, + ByRef NumericBuffer As UInt64, + ByVal BufferLength As UInt32) As TPCANStatus + End Function + + + Private Shared Function GetValue( + + ByVal Channel As TPCANHandle, + + ByVal Parameter As TPCANParameter, + + <[In], Out> ByVal ChannelsBuffer() As TPCANChannelInformation, + ByVal BufferLength As UInt32) As TPCANStatus + End Function + + ''' + ''' Retrieves a PCAN Channel value + ''' + ''' 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 handle of a PCAN Channel + ''' The TPCANParameter parameter to get + ''' Buffer for the parameter value + ''' A TPCANStatus error code + Public Shared Function GetValue( + ByVal Channel As TPCANHandle, + ByVal Parameter As TPCANParameter, + ByVal ChannelsBuffer() As TPCANChannelInformation) As TPCANStatus + If (ChannelsBuffer Is Nothing) Then + Return TPCANStatus.PCAN_ERROR_ILLPARAMVAL + End If + Return GetValue(Channel, Parameter, ChannelsBuffer, ChannelsBuffer.Length * Marshal.SizeOf(GetType(TPCANChannelInformation))) + End Function + + ''' + ''' Configures or sets a PCAN Channel value + ''' + ''' 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 handle of a PCAN Channel + ''' The TPCANParameter parameter to set + ''' Buffer with the value to be set + ''' Size in bytes of the buffer + ''' A TPCANStatus error code + + Public Shared Function SetValue( + + ByVal Channel As TPCANHandle, + + ByVal Parameter As TPCANParameter, + ByRef NumericBuffer As UInt32, + ByVal BufferLength As UInt32) As TPCANStatus + End Function + + ''' + ''' Configures or sets a PCAN Channel value + ''' + ''' 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 handle of a PCAN Channel + ''' The TPCANParameter parameter to set + ''' Buffer with the value to be set + ''' Size in bytes of the buffer + ''' A TPCANStatus error code + + Public Shared Function SetValue( + + ByVal Channel As TPCANHandle, + + ByVal Parameter As TPCANParameter, + ByRef NumericBuffer As UInt64, + ByVal BufferLength As UInt32) As TPCANStatus + End Function + + ''' + ''' Configures or sets a PCAN Channel value + ''' + ''' 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 handle of a PCAN Channel + ''' + ''' Buffer with the value to be set + ''' Size in bytes of the buffer + ''' A TPCANStatus error code + _ + Public Shared Function SetValue( _ + _ + ByVal Channel As TPCANHandle, _ + _ + ByVal Parameter As TPCANParameter, _ + _ + ByVal StringBuffer As String, _ + ByVal BufferLength As UInt32) As TPCANStatus + End Function + + ''' + ''' Returns a descriptive text of a given TPCANStatus error + ''' code, in any desired language + ''' + ''' The current languages available for translation are: + ''' Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), + ''' Italian (0x10) and French (0x0C) + ''' A TPCANStatus error code + ''' Indicates a 'Primary language ID' + ''' Buffer for the text (must be at least 256 in length) + ''' A TPCANStatus error code + + Public Shared Function GetErrorText( + + ByVal anError As TPCANStatus, + ByVal Language As UInt16, + ByVal StringBuffer As StringBuilder) As TPCANStatus + End Function + + ''' + ''' Finds a PCAN-Basic channel that matches with the given parameters + ''' + ''' A comma separated string contained pairs of + ''' parameter-name/value to be matched within a PCAN-Basic channel + ''' Buffer for returning the PCAN-Basic channel, + ''' when found + ''' A TPCANStatus error code + + Public Shared Function LookUpChannel( + ByVal Parameters As String, + ByRef FoundChannel As TPCANHandle) As TPCANStatus + End Function +#End Region + End Class +#End Region +End Namespace + + diff --git a/PCAN API/PCAN-Basic API/Include/PCANBasicCLR.h b/PCAN API/PCAN-Basic API/Include/PCANBasicCLR.h new file mode 100644 index 0000000..a9ef313 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Include/PCANBasicCLR.h @@ -0,0 +1,1510 @@ +// PCANBasicCLR.h +// +// ~~~~~~~~~~~~ +// +// PCAN-Basic API +// +// ~~~~~~~~~~~~ +// +// ------------------------------------------------------------------ +// Author : Keneth Wagner +// Last change: 2022-07-06 +// +// Language: C++/CLR +// ------------------------------------------------------------------ +// +// Copyright (C) 1999-2022 PEAK-System Technik GmbH, Darmstadt +// more Info at http://www.peak-system.com +// +using namespace System; +using namespace System::Text; +using namespace System::Runtime::InteropServices; + +//////////////////////////////////////////////////////////// +// Type definitions +//////////////////////////////////////////////////////////// +#define TPCANHandle System::UInt16 // Represents a PCAN hardware channel handle +#define TPCANBitrateFD System::String^ // Represents a bit rate String (Flexible Data rate) +#define TPCANTimestampFD System::UInt64 // Represents a timestamp in microseconds + +namespace Peak +{ + namespace Can + { + namespace Basic + { + #pragma region Other Constants + /// + /// Maximum length of the name of a device: 32 characters + terminator + /// + static const int MAX_LENGTH_HARDWARE_NAME = 33; + /// + /// Maximum length of a version string: 255 characters + terminator + /// + static const int MAX_LENGTH_VERSION_STRING = 256; + #pragma endregion + + #pragma region Enumerations + /// + /// Represents a PCAN status/error code + /// + [Flags] + public enum class TPCANStatus : UInt32 + { + /// + /// No error + /// + PCAN_ERROR_OK = 0x00000, + /// + /// Transmit buffer in CAN controller is full + /// + PCAN_ERROR_XMTFULL = 0x00001, + /// + /// CAN controller was read too late + /// + PCAN_ERROR_OVERRUN = 0x00002, + /// + /// Bus error: an error counter reached the 'light' limit + /// + PCAN_ERROR_BUSLIGHT = 0x00004, + /// + /// Bus error: an error counter reached the 'heavy' limit + /// + PCAN_ERROR_BUSHEAVY = 0x00008, + /// + /// Bus error: an error counter reached the 'warning' limit + /// + PCAN_ERROR_BUSWARNING = PCAN_ERROR_BUSHEAVY, + /// + /// Bus error: the CAN controller is error passive + /// + PCAN_ERROR_BUSPASSIVE = 0x40000, + /// + /// Bus error: the CAN controller is in bus-off state + /// + PCAN_ERROR_BUSOFF = 0x00010, + /// + /// Mask for all bus errors + /// + PCAN_ERROR_ANYBUSERR = (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE), + /// + /// Receive queue is empty + /// + PCAN_ERROR_QRCVEMPTY = 0x00020, + /// + /// Receive queue was read too late + /// + PCAN_ERROR_QOVERRUN = 0x00040, + /// + /// Transmit queue is full + /// + PCAN_ERROR_QXMTFULL = 0x00080, + /// + /// Test of the CAN controller hardware registers failed (no hardware found) + /// + PCAN_ERROR_REGTEST = 0x00100, + /// + /// Driver not loaded + /// + PCAN_ERROR_NODRIVER = 0x00200, + /// + /// Hardware already in use by a Net + /// + PCAN_ERROR_HWINUSE = 0x00400, + /// + /// A Client is already connected to the Net + /// + PCAN_ERROR_NETINUSE = 0x00800, + /// + /// Hardware handle is invalid + /// + PCAN_ERROR_ILLHW = 0x01400, + /// + /// Net handle is invalid + /// + PCAN_ERROR_ILLNET = 0x01800, + /// + /// Client handle is invalid + /// + PCAN_ERROR_ILLCLIENT = 0x01C00, + /// + /// Mask for all handle errors + /// + PCAN_ERROR_ILLHANDLE = (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT), + /// + /// Resource (FIFO, Client, timeout) cannot be created + /// + PCAN_ERROR_RESOURCE = 0x02000, + /// + /// Invalid parameter + /// + PCAN_ERROR_ILLPARAMTYPE = 0x04000, + /// + /// Invalid parameter value + /// + PCAN_ERROR_ILLPARAMVAL = 0x08000, + /// + /// Unknown error + /// + PCAN_ERROR_UNKNOWN = 0x10000, + /// + /// Invalid data, function, or action. + /// + PCAN_ERROR_ILLDATA = 0x20000, + /// + /// Driver object state is wrong for the attempted operation + /// + PCAN_ERROR_ILLMODE = 0x80000, + /// + /// An operation was successfully carried out, however, irregularities were registered + /// + PCAN_ERROR_CAUTION = 0x2000000, + /// + /// Channel is not initialized + /// Value was changed from 0x40000 to 0x4000000 + /// + PCAN_ERROR_INITIALIZE = 0x4000000, + /// + /// Invalid operation + /// Value was changed from 0x80000 to 0x8000000 + /// + PCAN_ERROR_ILLOPERATION = 0x8000000, + }; + + /// + /// Represents a PCAN device + /// + public enum class TPCANDevice : Byte + { + /// + /// Undefined, unknown or not selected PCAN device value + /// + PCAN_NONE = 0, + /// + /// PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API + /// + PCAN_PEAKCAN = 1, + /// + /// PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus + /// + PCAN_ISA = 2, + /// + /// PCAN-Dongle + /// + PCAN_DNG = 3, + /// + /// PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express + /// + PCAN_PCI = 4, + /// + /// PCAN-USB and PCAN-USB Pro + /// + PCAN_USB = 5, + /// + /// PCAN-PC Card + /// + PCAN_PCC = 6, + /// + /// PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API + /// + PCAN_VIRTUAL = 7, + /// + /// PCAN Gateway devices + /// + PCAN_LAN = 8 + }; + + /// + /// Represents a PCAN parameter to be read or set + /// + public enum class TPCANParameter : Byte + { + /// + /// Device identifier parameter + /// + PCAN_DEVICE_ID = 1, + /// + /// DEPRECATED. Use PCAN_DEVICE_ID instead + /// + [Obsolete] + PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID, + /// + /// 5-Volt power parameter + /// + PCAN_5VOLTS_POWER = 2, + /// + /// PCAN receive event handler parameter + /// + PCAN_RECEIVE_EVENT = 3, + /// + /// PCAN message filter parameter + /// + PCAN_MESSAGE_FILTER = 4, + /// + /// PCAN-Basic API version parameter + /// + PCAN_API_VERSION = 5, + /// + /// PCAN device channel version parameter + /// + PCAN_CHANNEL_VERSION = 6, + /// + /// PCAN Reset-On-Busoff parameter + /// + PCAN_BUSOFF_AUTORESET = 7, + /// + /// PCAN Listen-Only parameter + /// + PCAN_LISTEN_ONLY = 8, + /// + /// Directory path for log files + /// + PCAN_LOG_LOCATION = 9, + /// + /// Debug-Log activation status + /// + PCAN_LOG_STATUS = 10, + /// + /// Configuration of the debugged information (LOG_FUNCTION_***) + /// + PCAN_LOG_CONFIGURE = 11, + /// + /// Custom insertion of text into the log file + /// + PCAN_LOG_TEXT = 12, + /// + /// Availability status of a PCAN-Channel + /// + PCAN_CHANNEL_CONDITION = 13, + /// + /// PCAN hardware name parameter + /// + PCAN_HARDWARE_NAME = 14, + /// + /// Message reception status of a PCAN-Channel + /// + PCAN_RECEIVE_STATUS = 15, + /// + /// CAN-Controller number of a PCAN-Channel + /// + PCAN_CONTROLLER_NUMBER = 16, + /// + /// Directory path for PCAN trace files + /// + PCAN_TRACE_LOCATION = 17, + /// + /// CAN tracing activation status + /// + PCAN_TRACE_STATUS = 18, + /// + /// Configuration of the maximum file size of a CAN trace + /// + PCAN_TRACE_SIZE = 19, + /// + /// Configuration of the trace file storing mode (TRACE_FILE_***) + /// + PCAN_TRACE_CONFIGURE = 20, + /// + /// Physical identification of a USB based PCAN-Channel by blinking its associated LED + /// + PCAN_CHANNEL_IDENTIFYING = 21, + /// + /// Capabilities of a PCAN device (FEATURE_***) + /// + PCAN_CHANNEL_FEATURES = 22, + /// + /// Using of an existing bit rate (PCAN-View connected to a channel) + /// + PCAN_BITRATE_ADAPTING = 23, + /// + /// Configured bit rate as Btr0Btr1 value + /// + PCAN_BITRATE_INFO = 24, + /// + /// Configured bit rate as TPCANBitrateFD string + /// + PCAN_BITRATE_INFO_FD = 25, + /// + /// Configured nominal CAN Bus speed as Bits per seconds + /// + PCAN_BUSSPEED_NOMINAL = 26, + /// + /// Configured CAN data speed as Bits per seconds + /// + PCAN_BUSSPEED_DATA = 27, + /// + /// Remote address of a LAN channel as string in IPv4 format + /// + PCAN_IP_ADDRESS = 28, + /// + /// Status of the Virtual PCAN-Gateway Service + /// + PCAN_LAN_SERVICE_STATUS = 29, + /// + /// Status messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_STATUS_FRAMES = 30, + /// + /// RTR messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_RTR_FRAMES = 31, + /// + /// Error messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_ERROR_FRAMES = 32, + /// + /// Delay, in microseconds, between sending frames + /// + PCAN_INTERFRAME_DELAY = 33, + /// + /// Filter over code and mask patterns for 11-Bit messages + /// + PCAN_ACCEPTANCE_FILTER_11BIT = 34, + /// + /// Filter over code and mask patterns for 29-Bit messages + /// + PCAN_ACCEPTANCE_FILTER_29BIT = 35, + /// + /// Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive + /// + PCAN_IO_DIGITAL_CONFIGURATION = 36, + /// + /// Value assigned to a 32 digital I/O pins of a PCAN-USB Chip + /// + PCAN_IO_DIGITAL_VALUE = 37, + /// + /// 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_SET = 38, + /// + /// Clear multiple digital I/O pins to 0 + /// + PCAN_IO_DIGITAL_CLEAR = 39, + /// + /// Get value of a single analog input pin + /// + PCAN_IO_ANALOG_VALUE = 40, + /// + /// Get the version of the firmware used by the device associated with a PCAN-Channel + /// + PCAN_FIRMWARE_VERSION = 41, + /// + /// Get the amount of PCAN channels attached to a system + /// + PCAN_ATTACHED_CHANNELS_COUNT = 42, + /// + /// Get information about PCAN channels attached to a system + /// + PCAN_ATTACHED_CHANNELS = 43, + /// + /// Echo messages reception status within a PCAN-Channel + /// + PCAN_ALLOW_ECHO_FRAMES = 44, + /// + /// Get the part number associated to a device + /// + PCAN_DEVICE_PART_NUMBER = 45, + }; + + /// Represents the type of a PCAN message + /// + [Flags] + public enum class TPCANMessageType : Byte + { + /// + /// The PCAN message is a CAN Standard Frame (11-bit identifier) + /// + PCAN_MESSAGE_STANDARD = 0x00, + /// + /// The PCAN message is a CAN Remote-Transfer-Request Frame + /// + PCAN_MESSAGE_RTR = 0x01, + /// + /// The PCAN message is a CAN Extended Frame (29-bit identifier) + /// + PCAN_MESSAGE_EXTENDED = 0x02, + /// + /// The PCAN message represents a FD frame in terms of CiA Specs + /// + PCAN_MESSAGE_FD = 0x04, + /// + /// The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) + /// + PCAN_MESSAGE_BRS = 0x08, + /// + /// The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) + /// + PCAN_MESSAGE_ESI = 0x10, + /// + /// The PCAN message represents an echo CAN Frame + /// + PCAN_MESSAGE_ECHO = 0x20, + /// + /// The PCAN message represents an error frame + /// + PCAN_MESSAGE_ERRFRAME = 0x40, + /// + /// The PCAN message represents a PCAN status message + /// + /// + PCAN_MESSAGE_STATUS = 0x80, + }; + + /// + /// Represents a PCAN filter mode + /// + public enum class TPCANMode : Byte + { + /// + /// Mode is Standard (11-bit identifier) + /// + PCAN_MODE_STANDARD = TPCANMessageType::PCAN_MESSAGE_STANDARD, + /// + /// Mode is Extended (29-bit identifier) + /// + PCAN_MODE_EXTENDED = TPCANMessageType::PCAN_MESSAGE_EXTENDED, + }; + + /// + /// Represents a PCAN Baud rate register value + /// + public enum class TPCANBaudrate : UInt16 + { + /// + /// 1 MBit/s + /// + PCAN_BAUD_1M = 0x0014, + /// + /// 800 kBit/s + /// + PCAN_BAUD_800K = 0x0016, + /// + /// 500 kBit/s + /// + PCAN_BAUD_500K = 0x001C, + /// + /// 250 kBit/s + /// + PCAN_BAUD_250K = 0x011C, + /// + /// 125 kBit/s + /// + PCAN_BAUD_125K = 0x031C, + /// + /// 100 kBit/s + /// + PCAN_BAUD_100K = 0x432F, + /// + /// 95,238 kBit/s + /// + PCAN_BAUD_95K = 0xC34E, + /// + /// 83,333 kBit/s + /// + PCAN_BAUD_83K = 0x852B, + /// + /// 50 kBit/s + /// + PCAN_BAUD_50K = 0x472F, + /// + /// 47,619 kBit/s + /// + PCAN_BAUD_47K = 0x1414, + /// + /// 33,333 kBit/s + /// + PCAN_BAUD_33K = 0x8B2F, + /// + /// 20 kBit/s + /// + PCAN_BAUD_20K = 0x532F, + /// + /// 10 kBit/s + /// + PCAN_BAUD_10K = 0x672F, + /// + /// 5 kBit/s + /// + PCAN_BAUD_5K = 0x7F7F, + }; + + /// + /// Represents the type of PCAN (Non-PnP) hardware to be initialized + /// + public enum class TPCANType : Byte + { + /// + /// PCAN-ISA 82C200 + /// + PCAN_TYPE_ISA = 0x01, + /// + /// PCAN-ISA SJA1000 + /// + PCAN_TYPE_ISA_SJA = 0x09, + /// + /// PHYTEC ISA + /// + PCAN_TYPE_ISA_PHYTEC = 0x04, + /// + /// PCAN-Dongle 82C200 + /// + PCAN_TYPE_DNG = 0x02, + /// + /// PCAN-Dongle EPP 82C200 + /// + PCAN_TYPE_DNG_EPP = 0x03, + /// + /// PCAN-Dongle SJA1000 + /// + PCAN_TYPE_DNG_SJA = 0x05, + /// + /// PCAN-Dongle EPP SJA1000 + /// + PCAN_TYPE_DNG_SJA_EPP = 0x06, + }; + #pragma endregion + + #pragma region Strutures + /// + /// Represents a PCAN message + /// + public value struct TPCANMsg + { + /// + /// 11/29-bit message identifier + /// + UInt32 ID; + /// + /// Type of the message + /// + [MarshalAs(UnmanagedType::U1)] + TPCANMessageType MSGTYPE; + /// + /// Data Length Code of the message (0..8) + /// + Byte LEN; + /// + /// Data of the message (DATA[0]..DATA[7]) + /// + [MarshalAs(UnmanagedType::ByValArray, SizeConst = 8)] + array^ DATA; + }; + + /// + /// Represents a timestamp of a received PCAN message. + /// Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow + /// + public value struct TPCANTimestamp + { + /// + /// Base-value: milliseconds: 0.. 2^32-1 + /// + UInt32 millis; + /// + /// Roll-arounds of millis + /// + UInt16 millis_overflow; + /// + /// Microseconds: 0..999 + /// + UInt16 micros; + }; + + /// + /// Represents a PCAN message from a FD capable hardware + /// + public value struct TPCANMsgFD + { + /// + /// 11/29-bit message identifier + /// + UInt32 ID; + /// + /// Type of the message + /// + [MarshalAs(UnmanagedType::U1)] + TPCANMessageType MSGTYPE; + /// + /// Data Length Code of the message (0..15) + /// + Byte DLC; + /// + /// Data of the message (DATA[0]..DATA[63]) + /// + [MarshalAs(UnmanagedType::ByValArray, SizeConst = 64)] + array^ DATA; + }; + + /// + /// Describes an available PCAN channel + /// + public value struct TPCANChannelInformation + { + /// + /// PCAN channel handle + /// + [MarshalAs(UnmanagedType::U2)] + TPCANHandle channel_handle; + /// + /// Kind of PCAN device + /// + [MarshalAs(UnmanagedType::U1)] + TPCANDevice device_type; + /// + /// CAN-Controller number + /// + Byte controller_number; + /// + /// Device capabilities flag (see FEATURE_*) + /// + UInt32 device_features; + /// + /// Device name + /// + [MarshalAs(UnmanagedType::ByValTStr, SizeConst = MAX_LENGTH_HARDWARE_NAME)] + String^ device_name; + /// + /// Device number + /// + UInt32 device_id; + /// + /// Availability status of a PCAN-Channel + /// + UInt32 channel_condition; + }; + #pragma endregion + + #pragma region PCANBasic class + /// + /// PCAN-Basic API class implementation + /// + public ref class PCANBasic abstract sealed + { + public: + #pragma region PCAN-BUS Handles Definition + /// + /// Undefined/default value for a PCAN bus + /// + static const TPCANHandle PCAN_NONEBUS = 0x00; + + /// + /// PCAN-ISA interface, channel 1 + /// + static const TPCANHandle PCAN_ISABUS1 = 0x21; + /// + /// PCAN-ISA interface, channel 2 + /// + static const TPCANHandle PCAN_ISABUS2 = 0x22; + /// + /// PCAN-ISA interface, channel 3 + /// + static const TPCANHandle PCAN_ISABUS3 = 0x23; + /// + /// PCAN-ISA interface, channel 4 + /// + static const TPCANHandle PCAN_ISABUS4 = 0x24; + /// + /// PCAN-ISA interface, channel 5 + /// + static const TPCANHandle PCAN_ISABUS5 = 0x25; + /// + /// PCAN-ISA interface, channel 6 + /// + static const TPCANHandle PCAN_ISABUS6 = 0x26; + /// + /// PCAN-ISA interface, channel 7 + /// + static const TPCANHandle PCAN_ISABUS7 = 0x27; + /// + /// PCAN-ISA interface, channel 8 + /// + static const TPCANHandle PCAN_ISABUS8 = 0x28; + + /// + /// PPCAN-Dongle/LPT interface, channel 1 + /// + static const TPCANHandle PCAN_DNGBUS1 = 0x31; + + /// + /// PCAN-PCI interface, channel 1 + /// + static const TPCANHandle PCAN_PCIBUS1 = 0x41; + /// + /// PCAN-PCI interface, channel 2 + /// + static const TPCANHandle PCAN_PCIBUS2 = 0x42; + /// + /// PCAN-PCI interface, channel 3 + /// + static const TPCANHandle PCAN_PCIBUS3 = 0x43; + /// + /// PCAN-PCI interface, channel 4 + /// + static const TPCANHandle PCAN_PCIBUS4 = 0x44; + /// + /// PCAN-PCI interface, channel 5 + /// + static const TPCANHandle PCAN_PCIBUS5 = 0x45; + /// + /// PCAN-PCI interface, channel 6 + /// + static const TPCANHandle PCAN_PCIBUS6 = 0x46; + /// + /// PCAN-PCI interface, channel 7 + /// + static const TPCANHandle PCAN_PCIBUS7 = 0x47; + /// + /// PCAN-PCI interface, channel 8 + /// + static const TPCANHandle PCAN_PCIBUS8 = 0x48; + /// + /// PCAN-PCI interface, channel 9 + /// + static const TPCANHandle PCAN_PCIBUS9 = 0x409; + /// + /// PCAN-PCI interface, channel 10 + /// + static const TPCANHandle PCAN_PCIBUS10 = 0x40A; + /// + /// PCAN-PCI interface, channel 11 + /// + static const TPCANHandle PCAN_PCIBUS11 = 0x40B; + /// + /// PCAN-PCI interface, channel 12 + /// + static const TPCANHandle PCAN_PCIBUS12 = 0x40C; + /// + /// PCAN-PCI interface, channel 13 + /// + static const TPCANHandle PCAN_PCIBUS13 = 0x40D; + /// + /// PCAN-PCI interface, channel 14 + /// + static const TPCANHandle PCAN_PCIBUS14 = 0x40E; + /// + /// PCAN-PCI interface, channel 15 + /// + static const TPCANHandle PCAN_PCIBUS15 = 0x40F; + /// + /// PCAN-PCI interface, channel 16 + /// + static const TPCANHandle PCAN_PCIBUS16 = 0x410; + + /// + /// PCAN-USB interface, channel 1 + /// + static const TPCANHandle PCAN_USBBUS1 = 0x51; + /// + /// PCAN-USB interface, channel 2 + /// + static const TPCANHandle PCAN_USBBUS2 = 0x52; + /// + /// PCAN-USB interface, channel 3 + /// + static const TPCANHandle PCAN_USBBUS3 = 0x53; + /// + /// PCAN-USB interface, channel 4 + /// + static const TPCANHandle PCAN_USBBUS4 = 0x54; + /// + /// PCAN-USB interface, channel 5 + /// + static const TPCANHandle PCAN_USBBUS5 = 0x55; + /// + /// PCAN-USB interface, channel 6 + /// + static const TPCANHandle PCAN_USBBUS6 = 0x56; + /// + /// PCAN-USB interface, channel 7 + /// + static const TPCANHandle PCAN_USBBUS7 = 0x57; + /// + /// PCAN-USB interface, channel 8 + /// + static const TPCANHandle PCAN_USBBUS8 = 0x58; + /// + /// PCAN-USB interface, channel 9 + /// + static const TPCANHandle PCAN_USBBUS9 = 0x509; + /// + /// PCAN-USB interface, channel 10 + /// + static const TPCANHandle PCAN_USBBUS10 = 0x50A; + /// + /// PCAN-USB interface, channel 11 + /// + static const TPCANHandle PCAN_USBBUS11 = 0x50B; + /// + /// PCAN-USB interface, channel 12 + /// + static const TPCANHandle PCAN_USBBUS12 = 0x50C; + /// + /// PCAN-USB interface, channel 13 + /// + static const TPCANHandle PCAN_USBBUS13 = 0x50D; + /// + /// PCAN-USB interface, channel 14 + /// + static const TPCANHandle PCAN_USBBUS14 = 0x50E; + /// + /// PCAN-USB interface, channel 15 + /// + static const TPCANHandle PCAN_USBBUS15 = 0x50F; + /// + /// PCAN-USB interface, channel 16 + /// + static const TPCANHandle PCAN_USBBUS16 = 0x510; + + /// + /// PCAN-PC Card interface, channel 1 + /// + static const TPCANHandle PCAN_PCCBUS1 = 0x61; + /// + /// PCAN-PC Card interface, channel 2 + /// + static const TPCANHandle PCAN_PCCBUS2 = 0x62; + + /// + /// PCAN-LAN interface, channel 1 + /// + static const TPCANHandle PCAN_LANBUS1 = 0x801; + /// + /// PCAN-LAN interface, channel 2 + /// + static const TPCANHandle PCAN_LANBUS2 = 0x802; + /// + /// PCAN-LAN interface, channel 3 + /// + static const TPCANHandle PCAN_LANBUS3 = 0x803; + /// + /// PCAN-LAN interface, channel 4 + /// + static const TPCANHandle PCAN_LANBUS4 = 0x804; + /// + /// PCAN-LAN interface, channel 5 + /// + static const TPCANHandle PCAN_LANBUS5 = 0x805; + /// + /// PCAN-LAN interface, channel 6 + /// + static const TPCANHandle PCAN_LANBUS6 = 0x806; + /// + /// PCAN-LAN interface, channel 7 + /// + static const TPCANHandle PCAN_LANBUS7 = 0x807; + /// + /// PCAN-LAN interface, channel 8 + /// + static const TPCANHandle PCAN_LANBUS8 = 0x808; + /// + /// PCAN-LAN interface, channel 9 + /// + static const TPCANHandle PCAN_LANBUS9 = 0x809; + /// + /// PCAN-LAN interface, channel 10 + /// + static const TPCANHandle PCAN_LANBUS10 = 0x80A; + /// + /// PCAN-LAN interface, channel 11 + /// + static const TPCANHandle PCAN_LANBUS11 = 0x80B; + /// + /// PCAN-LAN interface, channel 12 + /// + static const TPCANHandle PCAN_LANBUS12 = 0x80C; + /// + /// PCAN-LAN interface, channel 13 + /// + static const TPCANHandle PCAN_LANBUS13 = 0x80D; + /// + /// PCAN-LAN interface, channel 14 + /// + static const TPCANHandle PCAN_LANBUS14 = 0x80E; + /// + /// PCAN-LAN interface, channel 15 + /// + static const TPCANHandle PCAN_LANBUS15 = 0x80F; + /// + /// PCAN-LAN interface, channel 16 + /// + static const TPCANHandle PCAN_LANBUS16 = 0x810; + #pragma endregion + + #pragma region FD Bit rate definition + /// + /// Clock frequency in Herz (80000000, 60000000, 40000000, 30000000, 24000000, 20000000) + /// + static const String^ PCAN_BR_CLOCK = "f_clock"; + /// + /// Clock frequency in Megaherz (80, 60, 40, 30, 24, 20) + /// + static const String^ PCAN_BR_CLOCK_MHZ = "f_clock_mhz"; + /// + /// Clock prescaler for nominal time quantum + /// + static const String^ PCAN_BR_NOM_BRP = "nom_brp"; + /// + /// TSEG1 segment for nominal bit rate in time quanta + /// + static const String^ PCAN_BR_NOM_TSEG1 = "nom_tseg1"; + /// + /// TSEG2 segment for nominal bit rate in time quanta + /// + static const String^ PCAN_BR_NOM_TSEG2 = "nom_tseg2"; + /// + /// Synchronization Jump Width for nominal bit rate in time quanta + /// + static const String^ PCAN_BR_NOM_SJW = "nom_sjw"; + /// + /// Sample point for nominal bit rate + /// + static const String^ PCAN_BR_NOM_SAMPLE = "nom_sam"; + /// + /// Clock prescaler for highspeed data time quantum + /// + static const String^ PCAN_BR_DATA_BRP = "data_brp"; + /// + /// TSEG1 segment for fast data bit rate in time quanta + /// + static const String^ PCAN_BR_DATA_TSEG1 = "data_tseg1"; + /// + /// TSEG2 segment for fast data bit rate in time quanta + /// + static const String^ PCAN_BR_DATA_TSEG2 = "data_tseg2"; + /// + /// Synchronization Jump Width for highspeed data bit rate in time quanta + /// + static const String^ PCAN_BR_DATA_SJW = "data_sjw"; + /// + /// Secondary sample point delay for highspeed data bit rate in cyles + /// + static const String^ PCAN_BR_DATA_SAMPLE = "data_ssp_offset"; + #pragma endregion + + #pragma region Parameter values definition + /// + /// The PCAN parameter is not set (inactive) + /// + static const int PCAN_PARAMETER_OFF = 0; + /// + /// The PCAN parameter is set (active) + /// + static const int PCAN_PARAMETER_ON = 1; + /// + /// The PCAN filter is closed. No messages will be received + /// + static const int PCAN_FILTER_CLOSE = 0; + /// + /// The PCAN filter is fully opened. All messages will be received + /// + static const int PCAN_FILTER_OPEN = 1; + /// + /// The PCAN filter is custom configured. Only registered + /// messages will be received + /// + static const int PCAN_FILTER_CUSTOM = 2; + /// + /// The PCAN-Channel handle is illegal, or its associated hardware is not available + /// + static const int PCAN_CHANNEL_UNAVAILABLE = 0; + /// + /// The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) + /// + static const int PCAN_CHANNEL_AVAILABLE = 1; + /// + /// The PCAN-Channel handle is valid, and is already being used + /// + static const int PCAN_CHANNEL_OCCUPIED = 2; + /// + /// The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect + /// + static const int PCAN_CHANNEL_PCANVIEW = PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED; + + /// + /// Logs system exceptions / errors + /// + static const int LOG_FUNCTION_DEFAULT = 0x00; + /// + /// Logs the entries to the PCAN-Basic API functions + /// + static const int LOG_FUNCTION_ENTRY = 0x01; + /// + /// Logs the parameters passed to the PCAN-Basic API functions + /// + static const int LOG_FUNCTION_PARAMETERS = 0x02; + /// + /// Logs the exits from the PCAN-Basic API functions + /// + static const int LOG_FUNCTION_LEAVE = 0x04; + /// + /// Logs the CAN messages passed to the CAN_Write function + /// + static const int LOG_FUNCTION_WRITE = 0x08; + /// + /// Logs the CAN messages received within the CAN_Read function + /// + static const int LOG_FUNCTION_READ = 0x10; + /// + /// Logs all possible information within the PCAN-Basic API functions + /// + static const int LOG_FUNCTION_ALL = 0xFFFF; + + /// + /// A single file is written until it size reaches PAN_TRACE_SIZE + /// + static const int TRACE_FILE_SINGLE = 0x00; + /// + /// Traced data is distributed in several files with size PAN_TRACE_SIZE + /// + static const int TRACE_FILE_SEGMENTED = 0x01; + /// + /// Includes the date into the name of the trace file + /// + static const int TRACE_FILE_DATE = 0x02; + /// + /// Includes the start time into the name of the trace file + /// + static const int TRACE_FILE_TIME = 0x04; + /// + /// Causes the overwriting of available traces (same name) + /// + static const int TRACE_FILE_OVERWRITE = 0x80; + + /// + /// Device supports flexible data-rate (CAN-FD) + /// + static const int FEATURE_FD_CAPABLE = 0x01; + /// + /// Device supports a delay between sending frames (FPGA based USB devices) + /// + static const int FEATURE_DELAY_CAPABLE = 0x02; + /// + /// Device supports I/O functionality for electronic circuits (USB-Chip devices) + /// + static const int FEATURE_IO_CAPABLE = 0x04; + + /// The service is not running + /// + /// + static const int SERVICE_STATUS_STOPPED = 0x01; + /// + /// The service is running + /// + static const int SERVICE_STATUS_RUNNING = 0x04; + #pragma endregion + + #pragma region Lookup Parameters + /// + /// Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) + /// + static const String^ LOOKUP_DEVICE_TYPE = "devicetype"; + /// + /// Lookup channel by device id + /// + static const String^ LOOKUP_DEVICE_ID = "deviceid"; + /// + /// Lookup channel by CAN controller 0-based index + /// + static const String^ LOOKUP_CONTROLLER_NUMBER = "controllernumber"; + /// + /// Lookup channel by IP address (LAN channels only) + /// + static const String^ LOOKUP_IP_ADDRESS = "ipaddress"; + #pragma endregion + + #pragma region PCANBasic API Implementation + /// + /// Initializes a PCAN Channel + /// + /// The handle of a PCAN Channel + /// The speed for the communication (BTR0BTR1 code) + /// Non-PnP: The type of hardware and operation mode + /// Non-PnP: The I/O address for the parallel port + /// Non-PnP: Interrupt number of the parallel por + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Initialize")] + static TPCANStatus Initialize( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U2)] + TPCANBaudrate Btr0Btr1, + [MarshalAs(UnmanagedType::U1)] + TPCANType HwType, + UInt32 IOPort, + UInt16 Interrupt); + + /// + /// Initializes a PCAN Channel + /// + /// The handle of a PCAN Channel + /// The speed for the communication (BTR0BTR1 code) + /// A TPCANStatus error code + static TPCANStatus Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1) + { + return Initialize(Channel, Btr0Btr1, (TPCANType)0, 0, 0); + } + + /// + /// Initializes a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// The speed for the communication (FD bit rate string) + /// See PCAN_BR_* values + /// Bit rate string must follow the following construction rules: + /// * 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 + /// 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 + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_InitializeFD")] + static TPCANStatus InitializeFD( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + /// + /// Uninitializes one or all PCAN Channels initialized by CAN_Initialize + /// + /// Giving the TPCANHandle value "PCAN_NONEBUS", + /// uninitialize all initialized channels + /// The handle of a PCAN Channel + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Uninitialize")] + static TPCANStatus Uninitialize( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel); + + /// + /// Resets the receive and transmit queues of the PCAN Channel + /// + /// A reset of the CAN controller is not performed + /// The handle of a PCAN Channel + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Reset")] + static TPCANStatus Reset( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel); + + /// + /// Gets the current status of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetStatus")] + static TPCANStatus GetStatus( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel); + + /// + /// Reads a CAN message from the receive queue of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANMsg structure buffer to store the CAN message + /// A TPCANTimestamp structure buffer to get + /// the reception time of the message + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")] + static TPCANStatus Read( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + TPCANMsg %MessageBuffer, + TPCANTimestamp %TimestampBuffer); + + private: + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")] + static TPCANStatus Read( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + TPCANMsg %MessageBuffer, + IntPtr bufferPointer); + + public: + /// + /// Reads a CAN message from the receive queue of a PCAN Channel + /// + /// The handle of a PCAN Channel + /// A TPCANMsg structure buffer to store the CAN message + /// A TPCANStatus error code + static TPCANStatus Read( + TPCANHandle Channel, + TPCANMsg %MessageBuffer) + { + return Read(Channel, MessageBuffer, IntPtr::Zero); + } + + /// + /// Reads a CAN message from the receive queue of a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD structure buffer to store the CAN message + /// A TPCANTimestampFD buffer to get the + /// reception time of the message + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_ReadFD")] + static TPCANStatus ReadFD( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + TPCANMsgFD %MessageBuffer, + TPCANTimestampFD %TimestampBuffer); + + private: + [DllImport("PCANBasic.dll", EntryPoint = "CAN_ReadFD")] + static TPCANStatus ReadFD( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + TPCANMsgFD %MessageBuffer, + IntPtr bufferPointer); + + public: + /// + /// Reads a CAN message from the receive queue of a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD structure buffer to store the CAN message + /// A TPCANTimestampFD buffer to get the + /// reception time of the message + /// A TPCANStatus error code + static TPCANStatus ReadFD( + TPCANHandle Channel, + TPCANMsgFD %MessageBuffer) + { + return ReadFD(Channel, MessageBuffer, IntPtr::Zero); + } + + /// + /// Transmits a CAN message + /// + /// The handle of a PCAN Channel + /// A TPCANMsg buffer with the message to be sent + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_Write")] + static TPCANStatus Write( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + TPCANMsg %MessageBuffer); + + /// + /// Transmits a CAN message over a FD capable PCAN Channel + /// + /// The handle of a FD capable PCAN Channel + /// A TPCANMsgFD buffer with the message to be sent + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_WriteFD")] + static TPCANStatus WriteFD( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + TPCANMsgFD %MessageBuffer); + + /// + /// Configures the reception filter + /// + /// 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 + /// The handle of a PCAN Channel + /// The lowest CAN ID to be received + /// The highest CAN ID to be received + /// Message type, Standard (11-bit identifier) or + /// Extended (29-bit identifier) + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_FilterMessages")] + static TPCANStatus FilterMessages( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + UInt32 FromID, + UInt32 ToID, + [MarshalAs(UnmanagedType::U1)] + TPCANMode Mode); + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + static TPCANStatus GetValue( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U1)] + TPCANParameter Parameter, + StringBuilder^ StringBuffer, + UInt32 BufferLength); + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + static TPCANStatus GetValue( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U1)] + TPCANParameter Parameter, + UInt32 %NumericBuffer, + UInt32 BufferLength); + + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + static TPCANStatus GetValue( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U1)] + TPCANParameter Parameter, + UInt64 %NumericBuffer, + UInt32 BufferLength); + + private: + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")] + static TPCANStatus GetValue( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U1)] + TPCANParameter Parameter, + [MarshalAs(UnmanagedType::LPArray, SizeParamIndex=3)] + [In, Out]array ^ChannelBuffer, + UInt32 BufferLength); + public: + /// + /// Retrieves a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to get + /// Buffer for the parameter value + /// A TPCANStatus error code + static TPCANStatus GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + array ^ChannelsBuffer) + { + if(ChannelsBuffer == nullptr) + return TPCANStatus::PCAN_ERROR_ILLPARAMVAL; + return GetValue(Channel, Parameter, ChannelsBuffer, ChannelsBuffer->Length * Marshal::SizeOf(TPCANChannelInformation::typeid)); + } + + /// + /// Configures a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to set + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")] + static TPCANStatus SetValue( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U1)] + TPCANParameter Parameter, + UInt32% NumericBuffer, + UInt32 BufferLength); + + /// + /// Configures a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// The TPCANParameter parameter to set + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")] + static TPCANStatus SetValue( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U1)] + TPCANParameter Parameter, + UInt64% NumericBuffer, + UInt32 BufferLength); + + /// + /// Configures a PCAN Channel value + /// + /// 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 handle of a PCAN Channel + /// + /// Buffer with the value to be set + /// Size in bytes of the buffer + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")] + static TPCANStatus SetValue( + [MarshalAs(UnmanagedType::U2)] + TPCANHandle Channel, + [MarshalAs(UnmanagedType::U1)] + TPCANParameter Parameter, + [MarshalAs(UnmanagedType::LPStr,SizeParamIndex=3)] + String^ StringBuffer, + UInt32 BufferLength); + + /// + /// Returns a descriptive text of a given TPCANStatus error + /// code, in any desired language + /// + /// The current languages available for translation are: + /// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), + /// Italian (0x10) and French (0x0C) + /// A TPCANStatus error code + /// Indicates a 'Primary language ID' + /// Buffer for the text (must be at least 256 in length) + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetErrorText")] + static TPCANStatus GetErrorText( + [MarshalAs(UnmanagedType::U4)] + TPCANStatus Error, + UInt16 Language, + StringBuilder^ StringBuffer); + + /// + /// Finds a PCAN-Basic channel that matches with the given parameters + /// + /// A comma separated string contained pairs of + /// parameter-name/value to be matched within a PCAN-Basic channel + /// Buffer for returning the PCAN-Basic channel, + /// when found + /// A TPCANStatus error code + [DllImport("PCANBasic.dll", EntryPoint = "CAN_LookUpChannel")] + static TPCANStatus LookUpChannel( + String^ Parameters, + TPCANHandle% FoundChannel); + #pragma endregion + }; + #pragma endregion + } + } +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/LiesMich.txt b/PCAN API/PCAN-Basic API/LiesMich.txt new file mode 100644 index 0000000..82d5bf6 --- /dev/null +++ b/PCAN API/PCAN-Basic API/LiesMich.txt @@ -0,0 +1,157 @@ +=============================================================================== +LiesMich.txt + +PCAN-Basic V4.6.2.753 +Copyright (c) 2022 PEAK-System Technik GmbH Darmstadt +Alle Rechte vorbehalten. +=============================================================================== + +Maximieren Sie das Editor-Fenster, um diese Datei leichter lesen zu können. + + +Inhalt: +------- + * Einleitung + * Systemvoraussetzungen + * Bedingungen zur Verwendung dieser Dateien + * Inhalt des Verzeichnisses + * Inbetriebnahme von PCAN-Hardware + * PEAK-System Technik GmbH kontaktieren + + +Einleitung +---------- +Das PCAN-System der Firma PEAK-System Technik GmbH besteht aus einer Sammlung +von Windows Gerätetreibern. Diese sorgen für die Echtzeit-Anbindung von +Windows-Applikationen an alle CAN-Busse, die mittels PCAN-Hardware an den +PC angeschlossen sind. + +PCAN-Basic ist eine einfache Programmier-Schnittstelle zum PCAN-System. Über +eine Interface-DLL wird die Verbindung eigener Applikationen an die +Gerätetreiber und die PCAN-Hardware ermöglicht, um eine CAN-Kommunikation zu +betreiben. + +Die mitgelieferten Treiber, die PCAN-Basic API und die CAN-Bus Monitor +Software "PCAN-View" sind die im Funktionsumfang reduzierten Versionen +der käuflich zu erwerbenden Software-Pakete PCAN-Developer und PCAN-Explorer. + + +Bedingungen zur Verwendung dieser Dateien +----------------------------------------- +Bitte lesen Sie die Endbenutzer-Lizenzvereinbarung der Firma PEAK-System Technik GmbH unter: +www.peak-system.com/quick/eula + +Die PEAK-System Technik GmbH räumt dem Kunden das Recht ein, die in diesem +Softwarepaket enthaltenen Dateien zu verwenden, solange dies in Verbindung mit +Hardware original von PEAK-System oder mit OEM-Hardware von PEAK-System +geschieht. Es ist ausdrücklich NICHT erlaubt, diese Dateien (auch auszugsweise) +mit Fremdhardware zu verwenden. + +Wenn Sie nicht sicher sind, ob Sie mit der verwendeten Hardware auch eine +entsprechende Lizenz erworben haben, setzen Sie sich bitte mit unserem +technischen Support in Verbindung (support@peak-system.com). + + +Systemvoraussetzungen +--------------------- +- Betriebssysteme: Windows 11 (x64/ARM64), Windows 10 (x64) + + +Inhalt des Verzeichnisses +------------------------- +LiesMich.txt + Diese Textdatei. + +ReadMe.txt + Diese Textdatei in englischer Übersetzung. + +PCANBasic_enu.chm + Die PCAN-Basic Dokumentation in englischer Sprache. + +PCANBasic_deu.chm + Die PCAN-Basic Dokumentation in deutscher Sprache. + +PCAN-Parameter_Documentation.pdf + Zusätzliche Dokumentation zu PCAN-Basic Get/Set-Parameter in englischer Sprache. + +\Include + - Enthält PCAN-Basic Header-Dateien für verschiedene Programmiersprachen und + Entwicklungsumgebungen. + +\x86 + - Enthält die 32-Bit (x86) Interface-DLL sowie eine x86-Demoanwendung (exe). + + \BB_LIB + x86 LIB-Datei für C++ Builder. + + \VC_LIB + x86 LIB-Datei für Visual C/C++. + +\x64 + - Enthält die 64-Bit (x64) Interface-DLL sowie eine x64-Demoanwendung (exe). + + \VC_LIB + x64 LIB-Datei für Visual C/C++. + +\ARM64 + - Enthält die ARM64 Interface-DLL sowie eine ARM64-Demoanwendung (exe). + + \VC_LIB + ARM64 LIB-Datei für Visual C/C++. + +\Samples + - Enthält Beispieldateien, welche die Verwendung der PCAN-Basic API in + verschiedenen Programmiersprachen und Entwicklungsumgebungen demonstrieren. + +\NuGet + - Enthält das PCAN-Basic.NET-Assembly-NuGet-Paket. + + +Inbetriebnahme von PCAN-Hardware +-------------------------------- +Informationen zur Installation von PCAN-Hardware befindet sich im +entsprechenden Hardware-Benutzerhandbuch. Diese Handbücher sind online +zugänlich unter: www.peak-system.com/quick/Dokumentation. + +Auf dem Zielsystem muss die Bibliothek PCANBasic.dll installiert sein, +um Anwendungen ausführen zu können, die diese API verwenden. Es gibt zwei +Möglichkeiten, diese Bibliothek auf einem System zu installieren: + 1. Über "Gerätetreiber-Setup" (empfohlen): Dieselbe Anwendung, die + für die Gerätetreiberinstallation verwendet wird, kann auch diese + Bibliothek installieren. Es kann unter folgendem Link heruntergeladen + werden: www.peak-system.com/quick/DrvSetup. + 2. Bibliothek manuell kopieren: Kopieren Sie die in diesem Paket + enthaltenen Bibliotheksdateien wie folgt auf das Zielsystem: + + Bei x64 Windows-Betriebssystemen: + \x86\PCANBasic.dll --> Windows\SysWOW64 + \x64\PCANBasic.dll --> Windows\System32 + + Bei ARM64 Windows-Betriebssystemen: + \x86\PCANBasic.dll --> Windows\SysWOW64 + \x64\PCANBasic.dll --> Anwendungsordner (x64 Anwendungen) + \ARM64\PCANBasic.dll --> Anwendungsordner (ARM64 Anwendungen) + + +NuGet-Paket Installation +-------------------------- +Die Durchführung einer Online- oder Offline-Installation des NuGet-Pakets für +Microsoft Visual Studio or Visual Studio Code wird in der Dokumentation der +PCAN-Basic.NET-Assembly unter https://docs.peak-system.com/API/PCAN-Basic.Net/ +im Kapitel „ Einführung\How-To's und Q&A's" erklärt. + + +PEAK-System Technik GmbH kontaktieren +------------------------------------- +Haben Sie Fragen bezüglich der Inbetriebnahme von PCAN-Hardware, oder benötigen +Sie Informationen über weitere PEAK CAN-Produkte, wenden Sie sich bitte an: + +PEAK-System Technik GmbH +Otto-Röhm-Str. 69 +64293 Darmstadt + +Tel. +49 6151 / 8173-20 +FAX +49 6151 / 8173-29 + +support@peak-system.com +http://www.peak-system.com diff --git a/PCAN API/PCAN-Basic API/NuGet/Peak.PCANBasic.NET.4.6.2.753.nupkg b/PCAN API/PCAN-Basic API/NuGet/Peak.PCANBasic.NET.4.6.2.753.nupkg new file mode 100644 index 0000000..88e7e24 Binary files /dev/null and b/PCAN API/PCAN-Basic API/NuGet/Peak.PCANBasic.NET.4.6.2.753.nupkg differ diff --git a/PCAN API/PCAN-Basic API/PCAN-Parameter_Documentation.pdf b/PCAN API/PCAN-Basic API/PCAN-Parameter_Documentation.pdf new file mode 100644 index 0000000..15b4e5e Binary files /dev/null and b/PCAN API/PCAN-Basic API/PCAN-Parameter_Documentation.pdf differ diff --git a/PCAN API/PCAN-Basic API/PCANBasic_deu.chm b/PCAN API/PCAN-Basic API/PCANBasic_deu.chm new file mode 100644 index 0000000..26117db Binary files /dev/null and b/PCAN API/PCAN-Basic API/PCANBasic_deu.chm differ diff --git a/PCAN API/PCAN-Basic API/PCANBasic_enu.chm b/PCAN API/PCAN-Basic API/PCANBasic_enu.chm new file mode 100644 index 0000000..839e9ea Binary files /dev/null and b/PCAN API/PCAN-Basic API/PCANBasic_enu.chm differ diff --git a/PCAN API/PCAN-Basic API/ReadMe.txt b/PCAN API/PCAN-Basic API/ReadMe.txt new file mode 100644 index 0000000..3d88b06 --- /dev/null +++ b/PCAN API/PCAN-Basic API/ReadMe.txt @@ -0,0 +1,165 @@ +=============================================================================== +ReadMe.txt + +PCAN-Basic V4.6.2.753 +Copyright (c) 2022 PEAK-System Technik GmbH Darmstadt, Germany +All rights reserved. +=============================================================================== + +Maximize the Notepad Window to read this file more easily. + + +Contents: +--------- + * Introduction + * System Requirements + * Rights to use these files + * Contents of this directory + * Installation of PCAN hardware + * How to contact PEAK-System Technik GmbH + * LIFE SUPPORT APPLIANCES + + +Introduction +------------ +The PCAN system of the company PEAK-System Technik GmbH consists of a +collection of Windows Device Drivers. These allow the Real-time connection of +Windows applications to all CAN busses that are physically connected to the PC +via a PCAN hardware. + +PCAN-Basic is a simple programming interface to the PCAN system. Via one +Interface DLL it is possible to connect own applications to the Device drivers +and the PCAN hardware, to communicate with the CAN busses. + +The provided drivers, the PCAN-Basic API, and the PCAN-View CAN bus Monitor +software are the feature-reduced versions of the larger software packages +PCAN-Developer or PCAN-Explorer. These can be aquired separately. + + +Rights to use these files +------------------------- +Please read the End User License Agreement of the company PEAK-System Technik GmbH at: +www.peak-system.com/quick/eula + +PEAK-System Technik GmbH grants the right to the customer to use the files in +this software package as long as this is done in connection with original +hardware by PEAK-System or OEM hardware coming from PEAK-System. It is NOT +allowed to use any of these files (even not parts) with third-party hardware. + +If you are not sure whether you have acquired an appropriate license with the +used hardware, please contact our technical support team (support@peak-system.com). + + +System Requirements +------------------- +- Operating systems: Windows 11 (x64/ARM64), Windows 10 (x64) + + +Contents of this directory +-------------------------- +ReadMe.txt + This text file. + +LiesMich.txt + This text file in German language. + +PCANBasic_enu.chm + The PCAN-Basic documentation in English. + +PCANBasic_deu.chm + The PCAN-Basic documentation in German. + +PCAN-Parameter_Documentation.pdf + Additional documentation about PCAN-Basic Get/Set parameters in English. + +\Include + - The Header files for different programming languages and development + environments. + +\x86 + - Contains the 32-bit (x86) interface DLL and an x86 demo application (exe). + + \BB_LIB + x86 LIB file for C++ Builder. + + \VC_LIB + x86 LIB file for Visual C/C++. + +\x64 + - Contains the 64-bit (x64) interface DLL and an x64 demo application (exe). + + \VC_LIB + x64 LIB file for Visual C/C++. + +\ARM64 + - Contains the ARM64 interface DLL and an ARM64 demo application (exe). + + \VC_LIB + ARM64 LIB file for Visual C/C++ + +\Samples + - Contains example files that demonstrate the use of the PCAN-Basic API in + different programming languages and development environments. + +\NuGet + - Contains the PCAN-Basic.NET assembly NuGet package. + + +Installation of PCAN hardware +----------------------------- +For information on installing PCAN hardware, please refer to the corresponding +hardware user manual. These manuals are accessible online at: +www.peak-system.com/quick/Documentation. + +The target system requires to have the PCANBasic.dll library installed in order +to be able to run applications that use this API. There are two ways to get this +library installed on a system: + 1. Via "Device Driver Setup" (recommended): The same application used for device + driver installation can also install this library. It can be downloaded using + the following link: www.peak-system.com/quick/DrvSetup. + 2. Copying the library manually: Copy the library files contained in this package + to the target system as follow: + + For x64 Windows systems: + \x86\PCANBasic.dll --> Windows\SysWOW64 + \x64\PCANBasic.dll --> Windows\System32 + + For ARM64 Windows systems: + \x86\PCANBasic.dll --> Windows\SysWOW64 + \x64\PCANBasic.dll --> Application folder (x64 applications) + \ARM64\PCANBasic.dll --> Application folder (ARM64 applications) + + +Installation of the NuGet Package +--------------------------------- +Performing an online or offline installation of the NuGet package for Microsoft +Visual Studio or Visual Studio Code is described in the documentation of the +PCAN-Basic.NET Assembly at https://docs.peak-system.com/API/PCAN-Basic.Net/, +in chapter "Introduction\How-To's and Q&A's". + + +How to contact PEAK-System Technik GmbH +--------------------------------------- +If you have any questions concerning the installation of PCAN hardware, or +require information about other PEAK CAN products, then please contact us: + +PEAK-System Technik GmbH +Otto-Roehm-Str. 69 +D-64293 Darmstadt +Germany + +Tel. +49 6151 / 8173-20 +FAX +49 6151 / 8173-29 + +support@peak-system.com +http://www.peak-system.com + + +LIFE SUPPORT APPLIANCES +----------------------- +These products are not designed for use in life support appliances, devices, +or systems where malfunction of these products can reasonably be expected to +result in personal injury. PEAK-System customers using or selling these +products for use in such applications do so at their own risk and agree to +fully indemnify PEAK-System for any damages resulting from such improper use +or sale. diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.cpp new file mode 100644 index 0000000..57b99cf --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.cpp @@ -0,0 +1,286 @@ +#include "01_LookUpChannel.h" + +LookUpChannel::LookUpChannel() +{ + ShowConfigurationHelp(); // Shows information about this sample + ShowCurrentConfiguration(); // Shows the current parameters configuration + + std::cout << "Start searching...\n"; + system("PAUSE"); + std::cout << "\n"; + + char sParameters[MAX_PATH]; + if (DeviceType != "") + sprintf_s(sParameters, sizeof(sParameters), "%s=%s", ConvertDefinesToChar((wchar_t*)LOOKUP_DEVICE_TYPE), DeviceType); + if (DeviceID != "") + { + if (sParameters != "") + sprintf_s(sParameters, sizeof(sParameters), "%s, ", sParameters); + sprintf_s(sParameters, sizeof(sParameters), "%s%s=%s", sParameters, ConvertDefinesToChar((wchar_t*)LOOKUP_DEVICE_ID), DeviceID); + } + if (ControllerNumber != "") + { + if (sParameters != "") + sprintf_s(sParameters, sizeof(sParameters), "%s, ", sParameters); + sprintf_s(sParameters, sizeof(sParameters), "%s%s=%s", sParameters, ConvertDefinesToChar((wchar_t*)LOOKUP_CONTROLLER_NUMBER), ControllerNumber); + } + if (IPAddress != "") + { + if (sParameters != "") + sprintf_s(sParameters, sizeof(sParameters), "%s, ", sParameters); + sprintf_s(sParameters, sizeof(sParameters), "%s%s=%s", sParameters, ConvertDefinesToChar((wchar_t*)LOOKUP_IP_ADDRESS), IPAddress); + } + + TPCANHandle handle; + TPCANStatus stsResult = CAN_LookUpChannel((LPSTR)sParameters, &handle); + + if (stsResult == PCAN_ERROR_OK) + { + + if (handle != PCAN_NONEBUS) + { + UINT32 iFeatures; + stsResult = CAN_GetValue(handle, PCAN_CHANNEL_FEATURES, &iFeatures, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + char buffer[MAX_PATH]; + FormatChannelName(handle, buffer, (iFeatures & FEATURE_FD_CAPABLE) == FEATURE_FD_CAPABLE); + std::cout << "The channel handle " << buffer << " was found\n"; + } + else + std::cout << "There was an issue retrieveing supported channel features\n"; + } + else + std::cout << "A handle for these lookup-criteria was not found\n"; + } + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "There was an error looking up the device, are any hardware channels attached?\n"; + ShowStatus(stsResult); + } + + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); +} +LookUpChannel::~LookUpChannel() +{ + CAN_Uninitialize(PCAN_NONEBUS); +} + +void LookUpChannel::ShowConfigurationHelp() +{ + std::cout << "=========================================================================================\n"; + std::cout << "| PCAN-Basic LookUpChannel Example |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "Following parameters are to be adjusted before launching, according to the hardware used |\n"; + std::cout << " |\n"; + std::cout << "* DeviceType: Numeric value that represents a TPCANDevice |\n"; + std::cout << "* DeviceID: Numeric value that represents the device identifier |\n"; + std::cout << "* ControllerNumber: Numeric value that represents controller number |\n"; + std::cout << "* IPAddress: String value that represents a valid Internet Protocol address |\n"; + std::cout << " |\n"; + std::cout << "For more information see 'LookUp Parameter Definition' within the documentation |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "\n"; +} + +void LookUpChannel::ShowCurrentConfiguration() +{ + std::cout << "Parameter values used\n"; + std::cout << "----------------------\n"; + std::cout << "* DeviceType: " << DeviceType << "\n"; + std::cout << "* DeviceID: " << DeviceID << "\n"; + std::cout << "* ControllerNumber: " << ControllerNumber << "\n"; + std::cout << "* IPAddress: " << IPAddress << "\n"; + std::cout << "\n"; +} + +void LookUpChannel::ShowStatus(TPCANStatus status) +{ + std::cout << "=========================================================================================\n"; + char buffer[MAX_PATH]; + GetFormattedError(status, buffer); + std::cout << buffer << "\n"; + std::cout << "=========================================================================================\n"; +} + +void LookUpChannel::FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD) +{ + TPCANDevice devDevice; + BYTE byChannel; + + // Gets the owner device and channel for a PCAN-Basic handle + if (handle < 0x100) + { + devDevice = (TPCANDevice)(handle >> 4); + byChannel = (BYTE)(handle & 0xF); + } + else + { + devDevice = (TPCANDevice)(handle >> 8); + byChannel = (BYTE)(handle & 0xFF); + } + + // Constructs the PCAN-Basic Channel name and return it + char handleBuffer[MAX_PATH]; + GetTPCANHandleName(handle, handleBuffer); + if (isFD) + sprintf_s(buffer, MAX_PATH, "%s:FD %d (%Xh)", handleBuffer, byChannel, handle); + else + sprintf_s(buffer, MAX_PATH, "%s %d (%Xh)", handleBuffer, byChannel, handle); +} + +void LookUpChannel::GetTPCANHandleName(TPCANHandle handle, LPSTR buffer) +{ + strcpy_s(buffer, MAX_PATH, "PCAN_NONE"); + switch (handle) + { + case PCAN_PCIBUS1: + case PCAN_PCIBUS2: + case PCAN_PCIBUS3: + case PCAN_PCIBUS4: + case PCAN_PCIBUS5: + case PCAN_PCIBUS6: + case PCAN_PCIBUS7: + case PCAN_PCIBUS8: + case PCAN_PCIBUS9: + case PCAN_PCIBUS10: + case PCAN_PCIBUS11: + case PCAN_PCIBUS12: + case PCAN_PCIBUS13: + case PCAN_PCIBUS14: + case PCAN_PCIBUS15: + case PCAN_PCIBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_PCI"); + break; + + case PCAN_USBBUS1: + case PCAN_USBBUS2: + case PCAN_USBBUS3: + case PCAN_USBBUS4: + case PCAN_USBBUS5: + case PCAN_USBBUS6: + case PCAN_USBBUS7: + case PCAN_USBBUS8: + case PCAN_USBBUS9: + case PCAN_USBBUS10: + case PCAN_USBBUS11: + case PCAN_USBBUS12: + case PCAN_USBBUS13: + case PCAN_USBBUS14: + case PCAN_USBBUS15: + case PCAN_USBBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_USB"); + break; + + case PCAN_LANBUS1: + case PCAN_LANBUS2: + case PCAN_LANBUS3: + case PCAN_LANBUS4: + case PCAN_LANBUS5: + case PCAN_LANBUS6: + case PCAN_LANBUS7: + case PCAN_LANBUS8: + case PCAN_LANBUS9: + case PCAN_LANBUS10: + case PCAN_LANBUS11: + case PCAN_LANBUS12: + case PCAN_LANBUS13: + case PCAN_LANBUS14: + case PCAN_LANBUS15: + case PCAN_LANBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_LAN"); + break; + + default: + strcpy_s(buffer, MAX_PATH, "UNKNOWN"); + break; + } +} + +void LookUpChannel::GetFormattedError(TPCANStatus error, LPSTR buffer) +{ + // Gets the text using the GetErrorText API function. If the function success, the translated error is returned. + // If it fails, a text describing the current error is returned. + if (CAN_GetErrorText(error, 0x09, buffer) != PCAN_ERROR_OK) + sprintf_s(buffer, MAX_PATH, "An error occurred. Error-code's text (%Xh) couldn't be retrieved", error); +} + +void LookUpChannel::ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer) +{ + switch (bitrate) + { + case PCAN_BAUD_1M: + strcpy_s(buffer, MAX_PATH, "1 MBit/sec"); + break; + case PCAN_BAUD_800K: + strcpy_s(buffer, MAX_PATH, "800 kBit/sec"); + break; + case PCAN_BAUD_500K: + strcpy_s(buffer, MAX_PATH, "500 kBit/sec"); + break; + case PCAN_BAUD_250K: + strcpy_s(buffer, MAX_PATH, "250 kBit/sec"); + break; + case PCAN_BAUD_125K: + strcpy_s(buffer, MAX_PATH, "125 kBit/sec"); + break; + case PCAN_BAUD_100K: + strcpy_s(buffer, MAX_PATH, "100 kBit/sec"); + break; + case PCAN_BAUD_95K: + strcpy_s(buffer, MAX_PATH, "95,238 kBit/sec"); + break; + case PCAN_BAUD_83K: + strcpy_s(buffer, MAX_PATH, "83,333 kBit/sec"); + break; + case PCAN_BAUD_50K: + strcpy_s(buffer, MAX_PATH, "50 kBit/sec"); + break; + case PCAN_BAUD_47K: + strcpy_s(buffer, MAX_PATH, "47,619 kBit/sec"); + break; + case PCAN_BAUD_33K: + strcpy_s(buffer, MAX_PATH, "33,333 kBit/sec"); + break; + case PCAN_BAUD_20K: + strcpy_s(buffer, MAX_PATH, "20 kBit/sec"); + break; + case PCAN_BAUD_10K: + strcpy_s(buffer, MAX_PATH, "10 kBit/sec"); + break; + case PCAN_BAUD_5K: + strcpy_s(buffer, MAX_PATH, "5 kBit/sec"); + break; + default: + strcpy_s(buffer, MAX_PATH, "Unknown Bitrate"); + break; + } +} + +char* LookUpChannel::ConvertDefinesToChar(wchar_t* define) +{ + // Convert the wchar_t string to a char* string. Record + // the length of the original string and add 1 to it to + // account for the terminating null character. + size_t origsize = wcslen(define) + 1; + size_t convertedChars = 0; + + // Allocate two bytes in the multibyte output string for every wide + // character in the input string (including a wide character + // null). Because a multibyte character can be one or two bytes, + // you should allot two bytes for each character. Having extra + // space for the new string is not an error, but having + // insufficient space is a potential security problem. + const size_t newsize = origsize * 2; + // The new string will contain a converted copy of the original + // string plus the type of string appended to it. + char* nstring = new char[newsize]; + + // Put a copy of the converted string into nstring + wcstombs_s(&convertedChars, nstring, newsize, define, _TRUNCATE); + return nstring; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.h new file mode 100644 index 0000000..7d78a22 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.h @@ -0,0 +1,86 @@ +#include"stdafx.h" +#include "PCANBasic.h" + +class LookUpChannel +{ +private: + /// + /// Sets a TPCANDevice value. The input can be numeric, in hexadecimal or decimal format, or as string denoting + /// a TPCANDevice value name. + /// + LPCSTR DeviceType = "PCAN_USB"; + /// + /// Sets value in range of a double. The input can be hexadecimal or decimal format. + /// + LPCSTR DeviceID = ""; + /// + /// Sets a zero-based index value in range of a double. The input can be hexadecimal or decimal format. + /// + LPCSTR ControllerNumber = ""; + /// + /// Sets a valid Internet Protocol address + /// + LPCSTR IPAddress = ""; + +public: + // LookUpChannel constructor + // + LookUpChannel(); + + // LookUpChannel destructor + // + ~LookUpChannel(); + +private: + /// + /// Shows/prints the configurable parameters for this sample and information about them + /// + void ShowConfigurationHelp(); + + /// + /// Shows/prints the configured paramters + /// + void ShowCurrentConfiguration(); + + /// + /// Shows formatted status + /// + /// Will be formatted + void ShowStatus(TPCANStatus status); + + /// + /// Gets the formatted text for a PCAN-Basic channel handle + /// + /// PCAN-Basic Handle to format + /// A string buffer for the channel name + /// If the channel is FD capable + void FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD); + + /// + /// Gets name of a TPCANHandle + /// + /// TPCANHandle to get name + /// A string buffer for the name of the TPCANHandle (size MAX_PATH) + void GetTPCANHandleName(TPCANHandle handle, LPSTR buffer); + + /// + /// Help Function used to get an error as text + /// + /// Error code to be translated + /// A string buffer for the translated error (size MAX_PATH) + void GetFormattedError(TPCANStatus error, LPSTR buffer); + + /// + /// Convert bitrate c_short value to readable string + /// + /// Bitrate to be converted + /// A string buffer for the converted bitrate (size MAX_PATH) + void ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer); + + /// + /// Converts PCANBasic Define (wchar_t*) to char* + /// + /// Define to be converted + /// Define as char* + char* ConvertDefinesToChar(wchar_t* define); +}; \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.sln new file mode 100644 index 0000000..d6cbf7d --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LookUpChannel", "01_LookUpChannel.vcxproj", "{DE08AE69-04BD-43EA-8602-B6D5528D690B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x64.ActiveCfg = Debug|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x64.Build.0 = Debug|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x86.ActiveCfg = Debug|Win32 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x86.Build.0 = Debug|Win32 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x64.ActiveCfg = Release|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x64.Build.0 = Release|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x86.ActiveCfg = Release|Win32 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4A9490BD-A688-47B4-8BCE-026E01EE20C2} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.vcxproj b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.vcxproj new file mode 100644 index 0000000..b35968a --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {de08ae69-04bd-43ea-8602-b6d5528d690b} + LookUpChannel + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.vcxproj.filters b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.vcxproj.filters new file mode 100644 index 0000000..abd2bea --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/01_LookUpChannel.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/PCANBasic.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/RunExample.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/RunExample.cpp new file mode 100644 index 0000000..4c34701 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/RunExample.cpp @@ -0,0 +1,6 @@ +#include "01_LookUpChannel.h" + +int main() +{ + LookUpChannel start; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/lib/x64/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/lib/x64/PCANBasic.lib new file mode 100644 index 0000000..2df8f1c Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/lib/x64/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/lib/x86/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/lib/x86/PCANBasic.lib new file mode 100644 index 0000000..7320f2b Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/lib/x86/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/stdafx.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/stdafx.cpp new file mode 100644 index 0000000..aa558e2 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PCANBasicExample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/stdafx.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/stdafx.h new file mode 100644 index 0000000..26eedce --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/stdafx.h @@ -0,0 +1,10 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once +#include +#include +#include +#include +#include "targetver.h" \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/targetver.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/targetver.h new file mode 100644 index 0000000..3d779e1 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/01_LookUpChannel/targetver.h @@ -0,0 +1,25 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.cpp new file mode 100644 index 0000000..13f85a5 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.cpp @@ -0,0 +1,761 @@ +#include "02_GetSetParameter.h" + +GetSetParameter::GetSetParameter() +{ + ShowConfigurationHelp(); // Shows information about this sample + ShowCurrentConfiguration(); // Shows the current parameters configuration + + TPCANStatus stsResult; + // Initialization of the selected channel + if (IsFD) + stsResult = CAN_InitializeFD(PcanHandle, BitrateFD); + else + stsResult = CAN_Initialize(PcanHandle, Bitrate); + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "Can not initialize. Please check the defines in the code.\n"; + ShowStatus(stsResult); + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); + return; + } + + std::cout << "Successfully initialized.\n"; + std::cout << "Get/set parameter\n"; + system("PAUSE"); + std::cout << "\n"; + + RunSelectedCommands(); + + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); +} + +GetSetParameter::~GetSetParameter() +{ + CAN_Uninitialize(PCAN_NONEBUS); +} + +void GetSetParameter::RunSelectedCommands() +{ + // Fill commands here + std::cout << "Fill \"RunSelectedCommands\"-function with parameter functions from \"Parameter commands\"-Region in the code.\n"; +} + +void GetSetParameter::GetPCAN_DEVICE_ID() +{ + UINT32 iDeviceID; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_DEVICE_ID, &iDeviceID, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_DEVICE_ID: " << iDeviceID << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_DEVICE_ID(UINT32 iDeviceID) +{ + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_DEVICE_ID, &iDeviceID, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_DEVICE_ID: " << iDeviceID << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_ATTACHED_CHANNELS() +{ + UINT32 iChannelsCount; + TPCANStatus stsResult = CAN_GetValue(PCAN_NONEBUS, PCAN_ATTACHED_CHANNELS_COUNT, &iChannelsCount, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + TPCANChannelInformation* ciChannelInformation = new TPCANChannelInformation[iChannelsCount]; + + stsResult = CAN_GetValue(PCAN_NONEBUS, PCAN_ATTACHED_CHANNELS, ciChannelInformation, iChannelsCount * sizeof(TPCANChannelInformation)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_ATTACHED_CHANNELS:\n"; + + for (int i = 0; i < (int)iChannelsCount; i++) + { + std::cout << "---------------------------\n"; + char buffer[MAX_PATH]; + GetTPCANHandleName(ciChannelInformation[i].channel_handle, buffer); + if (IsFD) + std::cout << "channel_handle: " << buffer << "BUS" << (ciChannelInformation[i].channel_handle & 0xFF) << "\n"; + else + std::cout << "channel_handle: " << buffer << "BUS" << (ciChannelInformation[i].channel_handle & 0xF) << "\n"; + std::cout << "device_type: " << ConvertDeviceTypeToString(ciChannelInformation[i].device_type) << "\n"; + std::cout << "controller_number: " << (int)ciChannelInformation[i].controller_number << "\n"; + std::cout << "device_features: " << ConvertToChannelFeatures(ciChannelInformation[i].device_features) << "\n"; + std::cout << "device_name: " << ciChannelInformation[i].device_name << "\n"; + std::cout << "device_id: " << ciChannelInformation[i].device_id << "\n"; + std::cout << "channel_condition: " << ConvertToChannelCondition(ciChannelInformation[i].channel_condition) << "\n"; + } + std::cout << "\n"; + } + delete [] ciChannelInformation; + } + if (stsResult != PCAN_ERROR_OK) + ShowStatus(stsResult); + +} + +void GetSetParameter::GetPCAN_CHANNEL_CONDITION() +{ + UINT32 iChannelCondition; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_CHANNEL_CONDITION, &iChannelCondition, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_CHANNEL_CONDITION: " << ConvertToChannelCondition(iChannelCondition) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_CHANNEL_IDENTIFYING() +{ + UINT32 iChannelIdentifying; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_CHANNEL_IDENTIFYING, &iChannelIdentifying, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_CHANNEL_IDENTIFYING: " << ConvertToParameterOnOff(iChannelIdentifying) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_CHANNEL_IDENTIFYING(bool value) +{ + UINT32 ciChannelIdentifying; + if (value) + ciChannelIdentifying = PCAN_PARAMETER_ON; + else + ciChannelIdentifying = PCAN_PARAMETER_OFF; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_CHANNEL_IDENTIFYING, &ciChannelIdentifying, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_CHANNEL_IDENTIFYING: " << ConvertToParameterOnOff(ciChannelIdentifying) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_CHANNEL_FEATURES() +{ + UINT32 iChannelFeatures; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_CHANNEL_FEATURES, &iChannelFeatures, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_CHANNEL_FEATURES: " << ConvertToChannelFeatures(iChannelFeatures) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_BITRATE_ADAPTING() +{ + UINT32 iBitrateAdapting; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_BITRATE_ADAPTING, &iBitrateAdapting, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_BITRATE_ADAPTING: " << ConvertToParameterOnOff(iBitrateAdapting) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_BITRATE_ADAPTING(bool value) +{ + UINT32 iBitrateAdapting; + + // Note: SetPCAN_BITRATE_ADAPTING requires an uninitialized channel, + // + CAN_Uninitialize(PCAN_NONEBUS); + + if (value) + iBitrateAdapting = PCAN_PARAMETER_ON; + else + iBitrateAdapting = PCAN_PARAMETER_OFF; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_BITRATE_ADAPTING, &iBitrateAdapting, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_BITRATE_ADAPTING: " << ConvertToParameterOnOff(iBitrateAdapting) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); + + // Channel will be connected again + if (IsFD) + stsResult = CAN_InitializeFD(PcanHandle, BitrateFD); + else + stsResult = CAN_Initialize(PcanHandle, Bitrate); + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "Error while re-initializing the channel.\n"; + ShowStatus(stsResult); + } +} + +void GetSetParameter::GetPCAN_ALLOW_STATUS_FRAMES() +{ + UINT32 iAllowStatusFrames; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_ALLOW_STATUS_FRAMES, &iAllowStatusFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_ALLOW_STATUS_FRAMES: " << ConvertToParameterOnOff(iAllowStatusFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_ALLOW_STATUS_FRAMES(bool value) +{ + UINT32 iAllowStatusFrames; + + if (value) + iAllowStatusFrames = PCAN_PARAMETER_ON; + else + iAllowStatusFrames = PCAN_PARAMETER_OFF; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_ALLOW_STATUS_FRAMES, &iAllowStatusFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_ALLOW_STATUS_FRAMES: " << ConvertToParameterOnOff(iAllowStatusFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_ALLOW_RTR_FRAMES() +{ + UINT32 iAllowRTRFrames; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_ALLOW_RTR_FRAMES, &iAllowRTRFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_ALLOW_RTR_FRAMES: " << ConvertToParameterOnOff(iAllowRTRFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_ALLOW_RTR_FRAMES(bool value) +{ + UINT32 iAllowRTRFrames; + + if (value) + iAllowRTRFrames = PCAN_PARAMETER_ON; + else + iAllowRTRFrames = PCAN_PARAMETER_OFF; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_ALLOW_RTR_FRAMES, &iAllowRTRFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_ALLOW_RTR_FRAMES: " << ConvertToParameterOnOff(iAllowRTRFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_ALLOW_ERROR_FRAMES() +{ + UINT32 iAllowErrorFrames; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_ALLOW_ERROR_FRAMES, &iAllowErrorFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_ALLOW_ERROR_FRAMES: " << ConvertToParameterOnOff(iAllowErrorFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_ALLOW_ERROR_FRAMES(bool value) +{ + UINT32 iAllowErrorFrames; + + if (value) + iAllowErrorFrames = PCAN_PARAMETER_ON; + else + iAllowErrorFrames = PCAN_PARAMETER_OFF; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_ALLOW_ERROR_FRAMES, &iAllowErrorFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_ALLOW_ERROR_FRAMES: " << ConvertToParameterOnOff(iAllowErrorFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_ALLOW_ECHO_FRAMES() +{ + UINT32 iAllowEchoFrames; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_ALLOW_ECHO_FRAMES, &iAllowEchoFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_ALLOW_ECHO_FRAMES: " << ConvertToParameterOnOff(iAllowEchoFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_ALLOW_ECHO_FRAMES(bool value) +{ + UINT32 iAllowEchoFrames; + + if (value) + iAllowEchoFrames = PCAN_PARAMETER_ON; + else + iAllowEchoFrames = PCAN_PARAMETER_OFF; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_ALLOW_ECHO_FRAMES, &iAllowEchoFrames, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_ALLOW_ECHO_FRAMES: " << ConvertToParameterOnOff(iAllowEchoFrames) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_ACCEPTANCE_FILTER_11BIT() +{ + UINT64 iAcceptanceFilter11Bit; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_ACCEPTANCE_FILTER_11BIT, &iAcceptanceFilter11Bit, sizeof(UINT64)); + + if (stsResult == PCAN_ERROR_OK) + { + char result[MAX_PATH]; + std::cout << "-----------------------------------------------------------------------------------------\n"; + sprintf_s(result, sizeof(result), "%I64X", iAcceptanceFilter11Bit); + std::cout << "Get PCAN_ACCEPTANCE_FILTER_11BIT: " << std::setfill('0') << std::setw(16) << std::hex << result << "h\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_ACCEPTANCE_FILTER_11BIT(UINT64 iacceptancefilter11bit) +{ + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_ACCEPTANCE_FILTER_11BIT, &iacceptancefilter11bit, sizeof(UINT64)); + + if (stsResult == PCAN_ERROR_OK) + { + char result[MAX_PATH]; + std::cout << "-----------------------------------------------------------------------------------------\n"; + sprintf_s(result, sizeof(result), "%I64X", iacceptancefilter11bit); + std::cout << "Set PCAN_ACCEPTANCE_FILTER_11BIT: " << std::setfill('0') << std::setw(16) << std::hex << result << "h\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_ACCEPTANCE_FILTER_29BIT() +{ + UINT64 iAcceptanceFilter29Bit; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_ACCEPTANCE_FILTER_29BIT, &iAcceptanceFilter29Bit, sizeof(UINT64)); + + if (stsResult == PCAN_ERROR_OK) + { + char result[MAX_PATH]; + std::cout << "-----------------------------------------------------------------------------------------\n"; + sprintf_s(result, sizeof(result), "%I64X", iAcceptanceFilter29Bit); + std::cout << "Get PCAN_ACCEPTANCE_FILTER_29BIT: " << std::setfill('0') << std::setw(16) << std::hex << result << "h\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_ACCEPTANCE_FILTER_29BIT(UINT64 iacceptancefilter29bit) +{ + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_ACCEPTANCE_FILTER_29BIT, &iacceptancefilter29bit, sizeof(UINT64)); + + if (stsResult == PCAN_ERROR_OK) + { + char result[MAX_PATH]; + std::cout << "-----------------------------------------------------------------------------------------\n"; + sprintf_s(result, sizeof(result), "%I64X", iacceptancefilter29bit); + std::cout << "Set PCAN_ACCEPTANCE_FILTER_29BIT: " << std::setfill('0') << std::setw(16) << std::hex << result << "h\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::GetPCAN_MESSAGE_FILTER() +{ + UINT32 iMessageFilter; + TPCANStatus stsResult = CAN_GetValue(PcanHandle, PCAN_MESSAGE_FILTER, &iMessageFilter, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Get PCAN_MESSAGE_FILTER: " << ConvertToFilterOpenCloseCustom(iMessageFilter) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::SetPCAN_MESSAGE_FILTER(UINT32 imessagefilter) +{ + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_MESSAGE_FILTER, &imessagefilter, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + std::cout << "-----------------------------------------------------------------------------------------\n"; + std::cout << "Set PCAN_MESSAGE_FILTER: " << ConvertToFilterOpenCloseCustom(imessagefilter) << "\n"; + std::cout << "\n"; + } + else + ShowStatus(stsResult); +} + +void GetSetParameter::ShowConfigurationHelp() +{ + std::cout << "=========================================================================================\n"; + std::cout << "| PCAN-Basic GetSetParameter Example |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "Following parameters are to be adjusted before launching, according to the hardware used |\n"; + std::cout << " |\n"; + std::cout << "* PcanHandle: Numeric value that represents the handle of the PCAN-Basic channel to use. |\n"; + std::cout << " See 'PCAN-Handle Definitions' within the documentation |\n"; + std::cout << "* IsFD: Boolean value that indicates the communication mode, CAN (false) or CAN-FD (true)|\n"; + std::cout << "* Bitrate: Numeric value that represents the BTR0/BR1 bitrate value to be used for CAN |\n"; + std::cout << " communication |\n"; + std::cout << "* BitrateFD: String value that represents the nominal/data bitrate value to be used for |\n"; + std::cout << " CAN-FD communication |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "\n"; +} + +void GetSetParameter::ShowCurrentConfiguration() +{ + std::cout << "Parameter values used\n"; + std::cout << "----------------------\n"; + char buffer[MAX_PATH]; + FormatChannelName(PcanHandle, buffer, IsFD); + std::cout << "* PCANHandle: " << buffer << "\n"; + if (IsFD) + std::cout << "* IsFD: True\n"; + else + std::cout << "* IsFD: False\n"; + ConvertBitrateToString(Bitrate, buffer); + std::cout << "* Bitrate: " << buffer << "\n"; + std::cout << "* BitrateFD: " << BitrateFD << "\n"; + std::cout << "\n"; +} + +void GetSetParameter::ShowStatus(TPCANStatus status) +{ + std::cout << "=========================================================================================\n"; + char buffer[MAX_PATH]; + GetFormattedError(status, buffer); + std::cout << buffer << "\n"; + std::cout << "=========================================================================================\n"; +} + +void GetSetParameter::FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD) +{ + TPCANDevice devDevice; + BYTE byChannel; + + // Gets the owner device and channel for a PCAN-Basic handle + if (handle < 0x100) + { + devDevice = (TPCANDevice)(handle >> 4); + byChannel = (BYTE)(handle & 0xF); + } + else + { + devDevice = (TPCANDevice)(handle >> 8); + byChannel = (BYTE)(handle & 0xFF); + } + + // Constructs the PCAN-Basic Channel name and return it + char handleBuffer[MAX_PATH]; + GetTPCANHandleName(handle, handleBuffer); + if (isFD) + sprintf_s(buffer, MAX_PATH, "%s:FD %d (%Xh)", handleBuffer, byChannel, handle); + else + sprintf_s(buffer, MAX_PATH, "%s %d (%Xh)", handleBuffer, byChannel, handle); +} + +void GetSetParameter::GetTPCANHandleName(TPCANHandle handle, LPSTR buffer) +{ + strcpy_s(buffer, MAX_PATH, "PCAN_NONE"); + switch (handle) + { + case PCAN_PCIBUS1: + case PCAN_PCIBUS2: + case PCAN_PCIBUS3: + case PCAN_PCIBUS4: + case PCAN_PCIBUS5: + case PCAN_PCIBUS6: + case PCAN_PCIBUS7: + case PCAN_PCIBUS8: + case PCAN_PCIBUS9: + case PCAN_PCIBUS10: + case PCAN_PCIBUS11: + case PCAN_PCIBUS12: + case PCAN_PCIBUS13: + case PCAN_PCIBUS14: + case PCAN_PCIBUS15: + case PCAN_PCIBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_PCI"); + break; + + case PCAN_USBBUS1: + case PCAN_USBBUS2: + case PCAN_USBBUS3: + case PCAN_USBBUS4: + case PCAN_USBBUS5: + case PCAN_USBBUS6: + case PCAN_USBBUS7: + case PCAN_USBBUS8: + case PCAN_USBBUS9: + case PCAN_USBBUS10: + case PCAN_USBBUS11: + case PCAN_USBBUS12: + case PCAN_USBBUS13: + case PCAN_USBBUS14: + case PCAN_USBBUS15: + case PCAN_USBBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_USB"); + break; + + case PCAN_LANBUS1: + case PCAN_LANBUS2: + case PCAN_LANBUS3: + case PCAN_LANBUS4: + case PCAN_LANBUS5: + case PCAN_LANBUS6: + case PCAN_LANBUS7: + case PCAN_LANBUS8: + case PCAN_LANBUS9: + case PCAN_LANBUS10: + case PCAN_LANBUS11: + case PCAN_LANBUS12: + case PCAN_LANBUS13: + case PCAN_LANBUS14: + case PCAN_LANBUS15: + case PCAN_LANBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_LAN"); + break; + + default: + strcpy_s(buffer, MAX_PATH, "UNKNOWN"); + break; + } +} + +void GetSetParameter::GetFormattedError(TPCANStatus error, LPSTR buffer) +{ + // Gets the text using the GetErrorText API function. If the function success, the translated error is returned. + // If it fails, a text describing the current error is returned. + if (CAN_GetErrorText(error, 0x09, buffer) != PCAN_ERROR_OK) + sprintf_s(buffer, MAX_PATH, "An error occurred. Error-code's text (%Xh) couldn't be retrieved", error); +} + +void GetSetParameter::ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer) +{ + switch (bitrate) + { + case PCAN_BAUD_1M: + strcpy_s(buffer, MAX_PATH, "1 MBit/sec"); + break; + case PCAN_BAUD_800K: + strcpy_s(buffer, MAX_PATH, "800 kBit/sec"); + break; + case PCAN_BAUD_500K: + strcpy_s(buffer, MAX_PATH, "500 kBit/sec"); + break; + case PCAN_BAUD_250K: + strcpy_s(buffer, MAX_PATH, "250 kBit/sec"); + break; + case PCAN_BAUD_125K: + strcpy_s(buffer, MAX_PATH, "125 kBit/sec"); + break; + case PCAN_BAUD_100K: + strcpy_s(buffer, MAX_PATH, "100 kBit/sec"); + break; + case PCAN_BAUD_95K: + strcpy_s(buffer, MAX_PATH, "95,238 kBit/sec"); + break; + case PCAN_BAUD_83K: + strcpy_s(buffer, MAX_PATH, "83,333 kBit/sec"); + break; + case PCAN_BAUD_50K: + strcpy_s(buffer, MAX_PATH, "50 kBit/sec"); + break; + case PCAN_BAUD_47K: + strcpy_s(buffer, MAX_PATH, "47,619 kBit/sec"); + break; + case PCAN_BAUD_33K: + strcpy_s(buffer, MAX_PATH, "33,333 kBit/sec"); + break; + case PCAN_BAUD_20K: + strcpy_s(buffer, MAX_PATH, "20 kBit/sec"); + break; + case PCAN_BAUD_10K: + strcpy_s(buffer, MAX_PATH, "10 kBit/sec"); + break; + case PCAN_BAUD_5K: + strcpy_s(buffer, MAX_PATH, "5 kBit/sec"); + break; + default: + strcpy_s(buffer, MAX_PATH, "Unknown Bitrate"); + break; + } +} + +std::string GetSetParameter::ConvertDeviceTypeToString(BYTE devicetype) +{ + switch (devicetype) + { + case 0: + return "PCAN_NONE"; + case 1: + return "PCAN_PEAKCAN"; + case 2: + return "PCAN_ISA"; + case 3: + return "PCAN_DNG"; + case 4: + return "PCAN_PCI"; + case 5: + return "PCAN_USB"; + case 6: + return "PCAN_PCC"; + case 7: + return "PCAN_VIRTUAL"; + case 8: + return "PCAN_LAN"; + default: + return ""; + } +} + +std::string GetSetParameter::ConvertToParameterOnOff(UINT32 value) +{ + switch (value) + { + case PCAN_PARAMETER_OFF: + return "PCAN_PARAMETER_OFF"; + case PCAN_PARAMETER_ON: + return "PCAN_PARAMETER_ON"; + default: + return "Status unknown: " + std::to_string(value); + } +} + +std::string GetSetParameter::ConvertToChannelFeatures(UINT32 value) +{ + std::string sFeatures = ""; + if ((value & FEATURE_FD_CAPABLE) == FEATURE_FD_CAPABLE) + sFeatures += "FEATURE_FD_CAPABLE"; + if ((value & FEATURE_DELAY_CAPABLE) == FEATURE_DELAY_CAPABLE) + if (sFeatures != "") + sFeatures += ", FEATURE_DELAY_CAPABLE"; + else + sFeatures += "FEATURE_DELAY_CAPABLE"; + if ((value & FEATURE_IO_CAPABLE) == FEATURE_IO_CAPABLE) + if (sFeatures != "") + sFeatures += ", FEATURE_IO_CAPABLE"; + else + sFeatures += "FEATURE_IO_CAPABLE"; + return sFeatures; +} + +std::string GetSetParameter::ConvertToChannelCondition(UINT32 value) +{ + switch (value) + { + case PCAN_CHANNEL_UNAVAILABLE: + return "PCAN_CHANNEL_UNAVAILABLE"; + case PCAN_CHANNEL_AVAILABLE: + return "PCAN_CHANNEL_AVAILABLE"; + case PCAN_CHANNEL_OCCUPIED: + return "PCAN_CHANNEL_OCCUPIED"; + case PCAN_CHANNEL_PCANVIEW: + return "PCAN_CHANNEL_PCANVIEW"; + default: + return "Status unknow: " + std::to_string(value); + } +} + +std::string GetSetParameter::ConvertToFilterOpenCloseCustom(UINT32 value) +{ + switch (value) + { + case PCAN_FILTER_CLOSE: + return "PCAN_FILTER_CLOSE"; + case PCAN_FILTER_OPEN: + return "PCAN_FILTER_OPEN"; + case PCAN_FILTER_CUSTOM: + return "PCAN_FILTER_CUSTOM"; + default: + return "Status unknown: " + std::to_string(value); + } +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.h new file mode 100644 index 0000000..44a1319 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.h @@ -0,0 +1,245 @@ +#include "stdafx.h" +#include "PCANBasic.h" + +class GetSetParameter +{ +private: + /// + /// Sets the PCANHandle (Hardware Channel) + /// + const TPCANHandle PcanHandle = PCAN_USBBUS1; + /// + /// Sets the desired connection mode (CAN = false / CAN-FD = true) + /// + const bool IsFD = false; + /// + /// Sets the bitrate for normal CAN devices + /// + const TPCANBaudrate Bitrate = PCAN_BAUD_500K; + /// + /// Sets the bitrate for CAN FD devices. + /// Example - Bitrate Nom: 1Mbit/s Data: 2Mbit/s: + /// "f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1" + /// + const TPCANBitrateFD BitrateFD = const_cast("f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1"); + +public: + // GetSetParameter constructor + // + GetSetParameter(); + + // GetSetParameter destructor + // + ~GetSetParameter(); + +private: + /// + /// Runs all commands for get or set parameters + /// + void RunSelectedCommands(); + + /// + /// Shows device identifier parameter + /// + void GetPCAN_DEVICE_ID(); + + /// + /// Sets device identifier parameter + /// + /// + void SetPCAN_DEVICE_ID(UINT32 iDeviceID); + + /// + /// Shows all information about attached channels + /// + void GetPCAN_ATTACHED_CHANNELS(); + + /// + /// Shows the status of selected PCAN-Channel + /// + void GetPCAN_CHANNEL_CONDITION(); + + /// + /// Shows the status from the status LED of the USB devices + /// + void GetPCAN_CHANNEL_IDENTIFYING(); + + /// + /// De/Activates the status LED of the USB devices + /// + /// True to turn on; False to turn off + void SetPCAN_CHANNEL_IDENTIFYING(bool value); + + /// + /// Shows information about features + /// + void GetPCAN_CHANNEL_FEATURES(); + + /// + /// Shows the status from Bitrate-Adapting mode + /// + void GetPCAN_BITRATE_ADAPTING(); + + /// + /// De/Activates the Bitrate-Adapting mode + /// + /// True to turn on; False to turn off + void SetPCAN_BITRATE_ADAPTING(bool value); + + /// + /// Shows the status from the reception of status frames + /// + void GetPCAN_ALLOW_STATUS_FRAMES(); + + /// + /// De/Activates the reception of status frames + /// + /// True to turn on; False to turn off + void SetPCAN_ALLOW_STATUS_FRAMES(bool value); + + /// + /// Shows the status from the reception of RTR frames + /// + void GetPCAN_ALLOW_RTR_FRAMES(); + + /// + /// De/Activates the reception of RTR frames + /// + /// True to turn on; False to turn off + void SetPCAN_ALLOW_RTR_FRAMES(bool value); + + /// + /// Shows the status from the reception of CAN error frames + /// + void GetPCAN_ALLOW_ERROR_FRAMES(); + + /// + /// De/Activates the reception of CAN error frames + /// + /// True to turn on; False to turn off + void SetPCAN_ALLOW_ERROR_FRAMES(bool value); + + /// + /// Shows the status from the reception of Echo frames + /// + void GetPCAN_ALLOW_ECHO_FRAMES(); + + /// + /// De/Activates the reception of Echo frames + /// + /// True to turn on; False to turn off + void SetPCAN_ALLOW_ECHO_FRAMES(bool value); + + /// + /// Shows the reception filter with a specific 11-bit acceptance code and mask + /// + void GetPCAN_ACCEPTANCE_FILTER_11BIT(); + + /// + /// Sets the reception filter with a specific 11-bit acceptance code and mask + /// + /// Acceptance code and mask + void SetPCAN_ACCEPTANCE_FILTER_11BIT(UINT64 iacceptancefilter11bit); + + /// + /// Shows the reception filter with a specific 29-bit acceptance code and mask + /// + void GetPCAN_ACCEPTANCE_FILTER_29BIT(); + + /// + /// Sets the reception filter with a specific 29-bit acceptance code and mask + /// + /// Acceptance code and mask + void SetPCAN_ACCEPTANCE_FILTER_29BIT(UINT64 iacceptancefilter29bit); + + /// + /// Shows the status of the reception filter + /// + void GetPCAN_MESSAGE_FILTER(); + + /// + /// De/Activates the reception filter + /// + /// Configure reception filter + void SetPCAN_MESSAGE_FILTER(UINT32 imessagefilter); + + /// + /// Shows/prints the configurable parameters for this sample and information about them + /// + void ShowConfigurationHelp(); + + /// + /// Shows/prints the configured paramters + /// + void ShowCurrentConfiguration(); + + /// + /// Shows formatted status + /// + /// Will be formatted + void ShowStatus(TPCANStatus status); + + /// + /// Gets the formatted text for a PCAN-Basic channel handle + /// + /// PCAN-Basic Handle to format + /// A string buffer for the channel name + /// If the channel is FD capable + void FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD); + + /// + /// Gets name of a TPCANHandle + /// + /// TPCANHandle to get name + /// A string buffer for the name of the TPCANHandle (size MAX_PATH) + void GetTPCANHandleName(TPCANHandle handle, LPSTR buffer); + + /// + /// Help Function used to get an error as text + /// + /// Error code to be translated + /// A string buffer for the translated error (size MAX_PATH) + void GetFormattedError(TPCANStatus error, LPSTR buffer); + + /// + /// Convert bitrate c_short value to readable string + /// + /// Bitrate to be converted + /// A string buffer for the converted bitrate (size MAX_PATH) + void ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer); + + /// + /// Convert BYTE value to readable string value + /// + /// + /// + std::string ConvertDeviceTypeToString(BYTE devicetype); + + /// + /// Convert uint value to readable string value + /// + /// + /// + std::string ConvertToParameterOnOff(UINT32 value); + + /// + /// Convert uint value to readable string value + /// + /// + /// + std::string ConvertToChannelFeatures(UINT32 value); + + /// + /// Convert uint value to readable string value + /// + /// + /// + std::string ConvertToChannelCondition(UINT32 value); + + /// + /// Convert uint value to readable string value + /// + /// + /// + std::string ConvertToFilterOpenCloseCustom(UINT32 value); +}; \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.sln new file mode 100644 index 0000000..ea5b9d0 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GetSetParameter", "02_GetSetParameter.vcxproj", "{4333360A-2706-409C-8FE5-018B189219F6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x64.ActiveCfg = Debug|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x64.Build.0 = Debug|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x86.ActiveCfg = Debug|Win32 + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x86.Build.0 = Debug|Win32 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x64.ActiveCfg = Release|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x64.Build.0 = Release|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x86.ActiveCfg = Release|Win32 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DF41B51B-1929-46AD-9287-082CFBC458CE} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.vcxproj b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.vcxproj new file mode 100644 index 0000000..eeac63d --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {4333360a-2706-409c-8fe5-018b189219f6} + GetSetParameter + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.vcxproj.filters b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.vcxproj.filters new file mode 100644 index 0000000..d20123b --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/02_GetSetParameter.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/PCANBasic.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/RunExample.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/RunExample.cpp new file mode 100644 index 0000000..c4faf08 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/RunExample.cpp @@ -0,0 +1,6 @@ +#include "02_GetSetParameter.h" + +int main() +{ + GetSetParameter start; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/lib/x64/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/lib/x64/PCANBasic.lib new file mode 100644 index 0000000..2df8f1c Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/lib/x64/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/lib/x86/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/lib/x86/PCANBasic.lib new file mode 100644 index 0000000..7320f2b Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/lib/x86/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/stdafx.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/stdafx.cpp new file mode 100644 index 0000000..aa558e2 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PCANBasicExample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/stdafx.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/stdafx.h new file mode 100644 index 0000000..fed5007 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/stdafx.h @@ -0,0 +1,12 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once +#include +#include +#include +#include +#include +#include +#include "targetver.h" \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/targetver.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/targetver.h new file mode 100644 index 0000000..3d779e1 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/02_GetSetParameter/targetver.h @@ -0,0 +1,25 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.cpp new file mode 100644 index 0000000..d64cab5 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.cpp @@ -0,0 +1,392 @@ +#include "03_ManualRead.h" + +ManualRead::ManualRead() +{ + ShowConfigurationHelp(); // Shows information about this sample + ShowCurrentConfiguration(); // Shows the current parameters configuration + + TPCANStatus stsResult; + // Initialization of the selected channel + if (IsFD) + stsResult = CAN_InitializeFD(PcanHandle, BitrateFD); + else + stsResult = CAN_Initialize(PcanHandle, Bitrate); + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "Can not initialize. Please check the defines in the code.\n"; + ShowStatus(stsResult); + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); + return; + } + + // Reading messages... + std::cout << "Successfully initialized.\n"; + std::cout << "Start reading...\n"; + system("PAUSE"); + do + { + system("cls"); + ReadMessages(); + std::cout << "Do you want to read again? yes[y] or any other key to close\n"; + } while (_getch() == 121); +} + +ManualRead::~ManualRead() +{ + CAN_Uninitialize(PCAN_NONEBUS); +} + +void ManualRead::ReadMessages() +{ + TPCANStatus stsResult; + + // We read at least one time the queue looking for messages. If a message is found, we look again trying to + // find more. If the queue is empty or an error occurr, we get out from the dowhile statement. + do + { + stsResult = IsFD ? ReadMessageFD() : ReadMessage(); + if (stsResult != PCAN_ERROR_OK && stsResult != PCAN_ERROR_QRCVEMPTY) + { + ShowStatus(stsResult); + return; + } + } while (!(stsResult & PCAN_ERROR_QRCVEMPTY)); +} + +TPCANStatus ManualRead::ReadMessageFD() +{ + TPCANMsgFD CANMsg; + TPCANTimestampFD CANTimeStamp; + + // We execute the "Read" function of the PCANBasic + TPCANStatus stsResult = CAN_ReadFD(PcanHandle, &CANMsg, &CANTimeStamp); + if (stsResult != PCAN_ERROR_QRCVEMPTY) + // We process the received message + ProcessMessageCanFD(CANMsg, CANTimeStamp); + + return stsResult; +} + +TPCANStatus ManualRead::ReadMessage() +{ + TPCANMsg CANMsg; + TPCANTimestamp CANTimeStamp; + + // We execute the "Read" function of the PCANBasic + TPCANStatus stsResult = CAN_Read(PcanHandle, &CANMsg, &CANTimeStamp); + if (stsResult != PCAN_ERROR_QRCVEMPTY) + // We process the received message + ProcessMessageCan(CANMsg, CANTimeStamp); + + return stsResult; +} + +void ManualRead::ProcessMessageCan(TPCANMsg msg, TPCANTimestamp itsTimeStamp) +{ + UINT64 microsTimestamp = ((UINT64)itsTimeStamp.micros + 1000 * (UINT64)itsTimeStamp.millis + 0x100000000 * 1000 * itsTimeStamp.millis_overflow); + + std::cout << "Type: " << GetMsgTypeString(msg.MSGTYPE) << "\n"; + std::cout << "ID: " << GetIdString(msg.ID, msg.MSGTYPE) << "\n"; + char result[MAX_PATH] = { 0 }; + sprintf_s(result, sizeof(result), "%i", msg.LEN); + std::cout << "Length: " << result << "\n"; + std::cout << "Time: " << GetTimeString(microsTimestamp) << "\n"; + std::cout << "Data: " << GetDataString(msg.DATA, msg.MSGTYPE, msg.LEN) << "\n"; + std::cout << "----------------------------------------------------------\n"; +} + +void ManualRead::ProcessMessageCanFD(TPCANMsgFD msg, TPCANTimestampFD itsTimeStamp) +{ + std::cout << "Type: " << GetMsgTypeString(msg.MSGTYPE) << "\n"; + std::cout << "ID: " << GetIdString(msg.ID, msg.MSGTYPE) << "\n"; + std::cout << "Length: " << GetLengthFromDLC(msg.DLC) << "\n"; + std::cout << "Time: " << GetTimeString(itsTimeStamp) << "\n"; + std::cout << "Data: " << GetDataString(msg.DATA, msg.MSGTYPE, GetLengthFromDLC(msg.DLC)) << "\n"; + std::cout << "----------------------------------------------------------\n"; +} + +void ManualRead::ShowConfigurationHelp() +{ + std::cout << "=========================================================================================\n"; + std::cout << "| PCAN-Basic ManualRead Example |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "Following parameters are to be adjusted before launching, according to the hardware used |\n"; + std::cout << " |\n"; + std::cout << "* PcanHandle: Numeric value that represents the handle of the PCAN-Basic channel to use. |\n"; + std::cout << " See 'PCAN-Handle Definitions' within the documentation |\n"; + std::cout << "* IsFD: Boolean value that indicates the communication mode, CAN (false) or CAN-FD (true)|\n"; + std::cout << "* Bitrate: Numeric value that represents the BTR0/BR1 bitrate value to be used for CAN |\n"; + std::cout << " communication |\n"; + std::cout << "* BitrateFD: String value that represents the nominal/data bitrate value to be used for |\n"; + std::cout << " CAN-FD communication |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "\n"; +} + +void ManualRead::ShowCurrentConfiguration() +{ + std::cout << "Parameter values used\n"; + std::cout << "----------------------\n"; + char buffer[MAX_PATH]; + FormatChannelName(PcanHandle, buffer, IsFD); + std::cout << "* PCANHandle: " << buffer << "\n"; + if (IsFD) + std::cout << "* IsFD: True\n"; + else + std::cout << "* IsFD: False\n"; + ConvertBitrateToString(Bitrate, buffer); + std::cout << "* Bitrate: " << buffer << "\n"; + std::cout << "* BitrateFD: " << BitrateFD << "\n"; + std::cout << "\n"; +} + +void ManualRead::ShowStatus(TPCANStatus status) +{ + std::cout << "=========================================================================================\n"; + char buffer[MAX_PATH]; + GetFormattedError(status, buffer); + std::cout << buffer << "\n"; + std::cout << "=========================================================================================\n"; +} + +void ManualRead::FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD) +{ + TPCANDevice devDevice; + BYTE byChannel; + + // Gets the owner device and channel for a PCAN-Basic handle + if (handle < 0x100) + { + devDevice = (TPCANDevice)(handle >> 4); + byChannel = (BYTE)(handle & 0xF); + } + else + { + devDevice = (TPCANDevice)(handle >> 8); + byChannel = (BYTE)(handle & 0xFF); + } + + // Constructs the PCAN-Basic Channel name and return it + char handleBuffer[MAX_PATH]; + GetTPCANHandleName(handle, handleBuffer); + if (isFD) + sprintf_s(buffer, MAX_PATH, "%s:FD %d (%Xh)", handleBuffer, byChannel, handle); + else + sprintf_s(buffer, MAX_PATH, "%s %d (%Xh)", handleBuffer, byChannel, handle); +} + +void ManualRead::GetTPCANHandleName(TPCANHandle handle, LPSTR buffer) +{ + strcpy_s(buffer, MAX_PATH, "PCAN_NONE"); + switch (handle) + { + case PCAN_PCIBUS1: + case PCAN_PCIBUS2: + case PCAN_PCIBUS3: + case PCAN_PCIBUS4: + case PCAN_PCIBUS5: + case PCAN_PCIBUS6: + case PCAN_PCIBUS7: + case PCAN_PCIBUS8: + case PCAN_PCIBUS9: + case PCAN_PCIBUS10: + case PCAN_PCIBUS11: + case PCAN_PCIBUS12: + case PCAN_PCIBUS13: + case PCAN_PCIBUS14: + case PCAN_PCIBUS15: + case PCAN_PCIBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_PCI"); + break; + + case PCAN_USBBUS1: + case PCAN_USBBUS2: + case PCAN_USBBUS3: + case PCAN_USBBUS4: + case PCAN_USBBUS5: + case PCAN_USBBUS6: + case PCAN_USBBUS7: + case PCAN_USBBUS8: + case PCAN_USBBUS9: + case PCAN_USBBUS10: + case PCAN_USBBUS11: + case PCAN_USBBUS12: + case PCAN_USBBUS13: + case PCAN_USBBUS14: + case PCAN_USBBUS15: + case PCAN_USBBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_USB"); + break; + + case PCAN_LANBUS1: + case PCAN_LANBUS2: + case PCAN_LANBUS3: + case PCAN_LANBUS4: + case PCAN_LANBUS5: + case PCAN_LANBUS6: + case PCAN_LANBUS7: + case PCAN_LANBUS8: + case PCAN_LANBUS9: + case PCAN_LANBUS10: + case PCAN_LANBUS11: + case PCAN_LANBUS12: + case PCAN_LANBUS13: + case PCAN_LANBUS14: + case PCAN_LANBUS15: + case PCAN_LANBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_LAN"); + break; + + default: + strcpy_s(buffer, MAX_PATH, "UNKNOWN"); + break; + } +} + +void ManualRead::GetFormattedError(TPCANStatus error, LPSTR buffer) +{ + // Gets the text using the GetErrorText API function. If the function success, the translated error is returned. + // If it fails, a text describing the current error is returned. + if (CAN_GetErrorText(error, 0x09, buffer) != PCAN_ERROR_OK) + sprintf_s(buffer, MAX_PATH, "An error occurred. Error-code's text (%Xh) couldn't be retrieved", error); +} + +void ManualRead::ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer) +{ + switch (bitrate) + { + case PCAN_BAUD_1M: + strcpy_s(buffer, MAX_PATH, "1 MBit/sec"); + break; + case PCAN_BAUD_800K: + strcpy_s(buffer, MAX_PATH, "800 kBit/sec"); + break; + case PCAN_BAUD_500K: + strcpy_s(buffer, MAX_PATH, "500 kBit/sec"); + break; + case PCAN_BAUD_250K: + strcpy_s(buffer, MAX_PATH, "250 kBit/sec"); + break; + case PCAN_BAUD_125K: + strcpy_s(buffer, MAX_PATH, "125 kBit/sec"); + break; + case PCAN_BAUD_100K: + strcpy_s(buffer, MAX_PATH, "100 kBit/sec"); + break; + case PCAN_BAUD_95K: + strcpy_s(buffer, MAX_PATH, "95,238 kBit/sec"); + break; + case PCAN_BAUD_83K: + strcpy_s(buffer, MAX_PATH, "83,333 kBit/sec"); + break; + case PCAN_BAUD_50K: + strcpy_s(buffer, MAX_PATH, "50 kBit/sec"); + break; + case PCAN_BAUD_47K: + strcpy_s(buffer, MAX_PATH, "47,619 kBit/sec"); + break; + case PCAN_BAUD_33K: + strcpy_s(buffer, MAX_PATH, "33,333 kBit/sec"); + break; + case PCAN_BAUD_20K: + strcpy_s(buffer, MAX_PATH, "20 kBit/sec"); + break; + case PCAN_BAUD_10K: + strcpy_s(buffer, MAX_PATH, "10 kBit/sec"); + break; + case PCAN_BAUD_5K: + strcpy_s(buffer, MAX_PATH, "5 kBit/sec"); + break; + default: + strcpy_s(buffer, MAX_PATH, "Unknown Bitrate"); + break; + } +} + +std::string ManualRead::GetMsgTypeString(TPCANMessageType msgType) +{ + if ((msgType & PCAN_MESSAGE_STATUS) == PCAN_MESSAGE_STATUS) + return "STATUS"; + + if ((msgType & PCAN_MESSAGE_ERRFRAME) == PCAN_MESSAGE_ERRFRAME) + return "ERROR"; + + std::string strTemp; + if ((msgType & PCAN_MESSAGE_EXTENDED) == PCAN_MESSAGE_EXTENDED) + strTemp = "EXT"; + else + strTemp = "STD"; + + if ((msgType & PCAN_MESSAGE_RTR) == PCAN_MESSAGE_RTR) + strTemp = (strTemp + "/RTR"); + else + if (msgType > PCAN_MESSAGE_EXTENDED) + { + strTemp = (strTemp + " [ "); + if (msgType & PCAN_MESSAGE_FD) + strTemp = (strTemp + " FD"); + if (msgType & PCAN_MESSAGE_BRS) + strTemp = (strTemp + " BRS"); + if (msgType & PCAN_MESSAGE_ESI) + strTemp = (strTemp + " ESI"); + strTemp = (strTemp + " ]"); + } + + return strTemp; +} + +std::string ManualRead::GetIdString(UINT32 id, TPCANMessageType msgType) +{ + char result[MAX_PATH] = { 0 }; + if ((msgType & PCAN_MESSAGE_EXTENDED) == PCAN_MESSAGE_EXTENDED) + { + sprintf_s(result, sizeof(result), "%08Xh", id); + return result; + } + sprintf_s(result, sizeof(result), "%03Xh", id); + return result; +} + +int ManualRead::GetLengthFromDLC(BYTE dlc) +{ + switch (dlc) + { + case 9: return 12; + case 10: return 16; + case 11: return 20; + case 12: return 24; + case 13: return 32; + case 14: return 48; + case 15: return 64; + default: return dlc; + } +} + +std::string ManualRead::GetTimeString(TPCANTimestampFD time) +{ + char result[MAX_PATH] = { 0 }; + double fTime = (time / 1000.0); + sprintf_s(result, sizeof(result), "%.1f", fTime); + return result; +} + +std::string ManualRead::GetDataString(BYTE data[], TPCANMessageType msgType, int dataLength) +{ + if ((msgType & PCAN_MESSAGE_RTR) == PCAN_MESSAGE_RTR) + return "Remote Request"; + else + { + char strTemp[MAX_PATH] = { 0 }; + std::string result = ""; + for (int i = 0; i < dataLength; i++) + { + sprintf_s(strTemp, sizeof(strTemp), "%02X ", data[i]); + result.append(strTemp); + } + + return result; + } +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.h new file mode 100644 index 0000000..c3f0182 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.h @@ -0,0 +1,150 @@ +#include "stdafx.h" +#include "PCANBasic.h" + +class ManualRead +{ +private: + /// + /// Sets the PCANHandle (Hardware Channel) + /// + const TPCANHandle PcanHandle = PCAN_USBBUS1; + /// + /// Sets the desired connection mode (CAN = false / CAN-FD = true) + /// + const bool IsFD = false; + /// + /// Sets the bitrate for normal CAN devices + /// + const TPCANBaudrate Bitrate = PCAN_BAUD_500K; + /// + /// Sets the bitrate for CAN FD devices. + /// Example - Bitrate Nom: 1Mbit/s Data: 2Mbit/s: + /// "f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1" + /// + const TPCANBitrateFD BitrateFD = const_cast("f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1"); + +public: + // ManualRead constructor + // + ManualRead(); + + // ManualRead destructor + // + ~ManualRead(); + +private: + /// + /// Function for reading PCAN-Basic messages + /// + void ReadMessages(); + + /// + /// Function for reading messages on CAN-FD devices + /// + /// A TPCANStatus error code + TPCANStatus ReadMessageFD(); + + /// + /// Function for reading CAN messages on normal CAN devices + /// + /// A TPCANStatus error code + TPCANStatus ReadMessage(); + + /// + /// Processes a received CAN message + /// + /// The received PCAN-Basic CAN message + /// Timestamp of the message as TPCANTimestamp structure + void ProcessMessageCan(TPCANMsg msg, TPCANTimestamp itsTimeStamp); + + /// + /// Processes a received CAN-FD message + /// + /// The received PCAN-Basic CAN-FD message + /// Timestamp of the message as microseconds (ulong) + void ProcessMessageCanFD(TPCANMsgFD msg, TPCANTimestampFD itsTimeStamp); + + /// + /// Shows/prints the configurable parameters for this sample and information about them + /// + void ShowConfigurationHelp(); + + /// + /// Shows/prints the configured paramters + /// + void ShowCurrentConfiguration(); + + /// + /// Shows formatted status + /// + /// Will be formatted + void ShowStatus(TPCANStatus status); + + /// + /// Gets the formatted text for a PCAN-Basic channel handle + /// + /// PCAN-Basic Handle to format + /// A string buffer for the channel name + /// If the channel is FD capable + void FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD); + + /// + /// Gets name of a TPCANHandle + /// + /// TPCANHandle to get name + /// A string buffer for the name of the TPCANHandle (size MAX_PATH) + void GetTPCANHandleName(TPCANHandle handle, LPSTR buffer); + + /// + /// Help Function used to get an error as text + /// + /// Error code to be translated + /// A string buffer for the translated error (size MAX_PATH) + void GetFormattedError(TPCANStatus error, LPSTR buffer); + + /// + /// Convert bitrate c_short value to readable string + /// + /// Bitrate to be converted + /// A string buffer for the converted bitrate (size MAX_PATH) + void ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer); + + /// + /// Gets the string representation of the type of a CAN message + /// + /// Type of a CAN message + /// The type of the CAN message as string + std::string GetMsgTypeString(TPCANMessageType msgType); + + /// + /// Gets the string representation of the ID of a CAN message + /// + /// Id to be parsed + /// Type flags of the message the Id belong + /// Hexadecimal representation of the ID of a CAN message + std::string GetIdString(UINT32 id, TPCANMessageType msgType); + + /// + /// Gets the data length of a CAN message + /// + /// Data length code of a CAN message + /// Data length as integer represented by the given DLC code + int GetLengthFromDLC(BYTE dlc); + + /// + /// Gets the string representation of the timestamp of a CAN message, in milliseconds + /// + /// Timestamp in microseconds + /// String representing the timestamp in milliseconds + std::string GetTimeString(TPCANTimestampFD time); + + /// + /// Gets the data of a CAN message as a string + /// + /// Array of bytes containing the data to parse + /// Type flags of the message the data belong + /// The amount of bytes to take into account wihtin the given data + /// A string with hexadecimal formatted data bytes of a CAN message + std::string GetDataString(BYTE data[], TPCANMessageType msgType, int dataLength); + +}; diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.sln new file mode 100644 index 0000000..35a8c67 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ManualRead", "03_ManualRead.vcxproj", "{AE40008D-A958-4A5A-B6A2-5D941D79EF1D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x64.ActiveCfg = Debug|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x64.Build.0 = Debug|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x86.ActiveCfg = Debug|Win32 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x86.Build.0 = Debug|Win32 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x64.ActiveCfg = Release|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x64.Build.0 = Release|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x86.ActiveCfg = Release|Win32 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6CD20D96-5C95-447F-AFD9-E6432A9C89FE} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.vcxproj b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.vcxproj new file mode 100644 index 0000000..3036e72 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {ae40008d-a958-4a5a-b6a2-5d941d79ef1d} + ManualRead + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.vcxproj.filters b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.vcxproj.filters new file mode 100644 index 0000000..db5235b --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/03_ManualRead.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/PCANBasic.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/RunExample.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/RunExample.cpp new file mode 100644 index 0000000..80f5470 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/RunExample.cpp @@ -0,0 +1,6 @@ +#include "03_ManualRead.h" + +int main() +{ + ManualRead start; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/lib/x64/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/lib/x64/PCANBasic.lib new file mode 100644 index 0000000..2df8f1c Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/lib/x64/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/lib/x86/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/lib/x86/PCANBasic.lib new file mode 100644 index 0000000..7320f2b Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/lib/x86/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/stdafx.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/stdafx.cpp new file mode 100644 index 0000000..aa558e2 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PCANBasicExample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/stdafx.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/stdafx.h new file mode 100644 index 0000000..26eedce --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/stdafx.h @@ -0,0 +1,10 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once +#include +#include +#include +#include +#include "targetver.h" \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/targetver.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/targetver.h new file mode 100644 index 0000000..3d779e1 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/03_ManualRead/targetver.h @@ -0,0 +1,25 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.cpp new file mode 100644 index 0000000..21a744b --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.cpp @@ -0,0 +1,282 @@ +#include "04_ManualWrite.h" + +ManualWrite::ManualWrite() +{ + ShowConfigurationHelp(); // Shows information about this sample + ShowCurrentConfiguration(); // Shows the current parameters configuration + + TPCANStatus stsResult; + // Initialization of the selected channel + if (IsFD) + stsResult = CAN_InitializeFD(PcanHandle, BitrateFD); + else + stsResult = CAN_Initialize(PcanHandle, Bitrate); + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "Can not initialize. Please check the defines in the code.\n"; + ShowStatus(stsResult); + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); + return; + } + + // Writing messages... + std::cout << "Successfully initialized.\n"; + std::cout << "For write: "; + system("PAUSE"); + do + { + system("cls"); + WriteMessages(); + std::cout << "Do you want to write again? yes[y] or any other key to close\n"; + } while (_getch() == 121); +} + +ManualWrite::~ManualWrite() +{ + CAN_Uninitialize(PCAN_NONEBUS); +} + +void ManualWrite::WriteMessages() +{ + TPCANStatus stsResult; + + if (IsFD) + stsResult = WriteMessageFD(); + else + stsResult = WriteMessage(); + + // Checks if the message was sent + if (stsResult != PCAN_ERROR_OK) + ShowStatus(stsResult); + else + std::cout << "Message was successfully SENT\n"; +} + +TPCANStatus ManualWrite::WriteMessage() +{ + // Sends a CAN message with extended ID, and 8 data bytes + TPCANMsg msgCanMessage; + msgCanMessage.ID = 0x100; + msgCanMessage.LEN = (BYTE)8; + msgCanMessage.MSGTYPE = PCAN_MESSAGE_EXTENDED; + for (BYTE i = 0; i < 8; i++) + { + msgCanMessage.DATA[i] = i; + } + return CAN_Write(PcanHandle, &msgCanMessage); +} + +TPCANStatus ManualWrite::WriteMessageFD() +{ + // Sends a CAN-FD message with standard ID, 64 data bytes, and bitrate switch + TPCANMsgFD msgCanMessageFD; + msgCanMessageFD.ID = 0x100; + msgCanMessageFD.DLC = 15; + msgCanMessageFD.MSGTYPE = PCAN_MESSAGE_FD | PCAN_MESSAGE_BRS; + for (BYTE i = 0; i < 64; i++) + { + msgCanMessageFD.DATA[i] = i; + } + return CAN_WriteFD(PcanHandle, &msgCanMessageFD); +} + +void ManualWrite::ShowConfigurationHelp() +{ + std::cout << "=========================================================================================\n"; + std::cout << "| PCAN-Basic ManualWrite Example |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "Following parameters are to be adjusted before launching, according to the hardware used |\n"; + std::cout << " |\n"; + std::cout << "* PcanHandle: Numeric value that represents the handle of the PCAN-Basic channel to use. |\n"; + std::cout << " See 'PCAN-Handle Definitions' within the documentation |\n"; + std::cout << "* IsFD: Boolean value that indicates the communication mode, CAN (false) or CAN-FD (true)|\n"; + std::cout << "* Bitrate: Numeric value that represents the BTR0/BR1 bitrate value to be used for CAN |\n"; + std::cout << " communication |\n"; + std::cout << "* BitrateFD: String value that represents the nominal/data bitrate value to be used for |\n"; + std::cout << " CAN-FD communication |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "\n"; +} + +void ManualWrite::ShowCurrentConfiguration() +{ + std::cout << "Parameter values used\n"; + std::cout << "----------------------\n"; + char buffer[MAX_PATH]; + FormatChannelName(PcanHandle, buffer, IsFD); + std::cout << "* PCANHandle: " << buffer << "\n"; + if (IsFD) + std::cout << "* IsFD: True\n"; + else + std::cout << "* IsFD: False\n"; + ConvertBitrateToString(Bitrate, buffer); + std::cout << "* Bitrate: " << buffer << "\n"; + std::cout << "* BitrateFD: " << BitrateFD << "\n"; + std::cout << "\n"; +} + +void ManualWrite::ShowStatus(TPCANStatus status) +{ + std::cout << "=========================================================================================\n"; + char buffer[MAX_PATH]; + GetFormattedError(status, buffer); + std::cout << buffer << "\n"; + std::cout << "=========================================================================================\n"; +} + +void ManualWrite::FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD) +{ + TPCANDevice devDevice; + BYTE byChannel; + + // Gets the owner device and channel for a PCAN-Basic handle + if (handle < 0x100) + { + devDevice = (TPCANDevice)(handle >> 4); + byChannel = (BYTE)(handle & 0xF); + } + else + { + devDevice = (TPCANDevice)(handle >> 8); + byChannel = (BYTE)(handle & 0xFF); + } + + // Constructs the PCAN-Basic Channel name and return it + char handleBuffer[MAX_PATH]; + GetTPCANHandleName(handle, handleBuffer); + if (isFD) + sprintf_s(buffer, MAX_PATH, "%s:FD %d (%Xh)", handleBuffer, byChannel, handle); + else + sprintf_s(buffer, MAX_PATH, "%s %d (%Xh)", handleBuffer, byChannel, handle); +} + +void ManualWrite::GetTPCANHandleName(TPCANHandle handle, LPSTR buffer) +{ + strcpy_s(buffer, MAX_PATH, "PCAN_NONE"); + switch (handle) + { + case PCAN_PCIBUS1: + case PCAN_PCIBUS2: + case PCAN_PCIBUS3: + case PCAN_PCIBUS4: + case PCAN_PCIBUS5: + case PCAN_PCIBUS6: + case PCAN_PCIBUS7: + case PCAN_PCIBUS8: + case PCAN_PCIBUS9: + case PCAN_PCIBUS10: + case PCAN_PCIBUS11: + case PCAN_PCIBUS12: + case PCAN_PCIBUS13: + case PCAN_PCIBUS14: + case PCAN_PCIBUS15: + case PCAN_PCIBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_PCI"); + break; + + case PCAN_USBBUS1: + case PCAN_USBBUS2: + case PCAN_USBBUS3: + case PCAN_USBBUS4: + case PCAN_USBBUS5: + case PCAN_USBBUS6: + case PCAN_USBBUS7: + case PCAN_USBBUS8: + case PCAN_USBBUS9: + case PCAN_USBBUS10: + case PCAN_USBBUS11: + case PCAN_USBBUS12: + case PCAN_USBBUS13: + case PCAN_USBBUS14: + case PCAN_USBBUS15: + case PCAN_USBBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_USB"); + break; + + case PCAN_LANBUS1: + case PCAN_LANBUS2: + case PCAN_LANBUS3: + case PCAN_LANBUS4: + case PCAN_LANBUS5: + case PCAN_LANBUS6: + case PCAN_LANBUS7: + case PCAN_LANBUS8: + case PCAN_LANBUS9: + case PCAN_LANBUS10: + case PCAN_LANBUS11: + case PCAN_LANBUS12: + case PCAN_LANBUS13: + case PCAN_LANBUS14: + case PCAN_LANBUS15: + case PCAN_LANBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_LAN"); + break; + + default: + strcpy_s(buffer, MAX_PATH, "UNKNOWN"); + break; + } +} + +void ManualWrite::GetFormattedError(TPCANStatus error, LPSTR buffer) +{ + // Gets the text using the GetErrorText API function. If the function success, the translated error is returned. + // If it fails, a text describing the current error is returned. + if (CAN_GetErrorText(error, 0x09, buffer) != PCAN_ERROR_OK) + sprintf_s(buffer, MAX_PATH, "An error occurred. Error-code's text (%Xh) couldn't be retrieved", error); +} + +void ManualWrite::ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer) +{ + switch (bitrate) + { + case PCAN_BAUD_1M: + strcpy_s(buffer, MAX_PATH, "1 MBit/sec"); + break; + case PCAN_BAUD_800K: + strcpy_s(buffer, MAX_PATH, "800 kBit/sec"); + break; + case PCAN_BAUD_500K: + strcpy_s(buffer, MAX_PATH, "500 kBit/sec"); + break; + case PCAN_BAUD_250K: + strcpy_s(buffer, MAX_PATH, "250 kBit/sec"); + break; + case PCAN_BAUD_125K: + strcpy_s(buffer, MAX_PATH, "125 kBit/sec"); + break; + case PCAN_BAUD_100K: + strcpy_s(buffer, MAX_PATH, "100 kBit/sec"); + break; + case PCAN_BAUD_95K: + strcpy_s(buffer, MAX_PATH, "95,238 kBit/sec"); + break; + case PCAN_BAUD_83K: + strcpy_s(buffer, MAX_PATH, "83,333 kBit/sec"); + break; + case PCAN_BAUD_50K: + strcpy_s(buffer, MAX_PATH, "50 kBit/sec"); + break; + case PCAN_BAUD_47K: + strcpy_s(buffer, MAX_PATH, "47,619 kBit/sec"); + break; + case PCAN_BAUD_33K: + strcpy_s(buffer, MAX_PATH, "33,333 kBit/sec"); + break; + case PCAN_BAUD_20K: + strcpy_s(buffer, MAX_PATH, "20 kBit/sec"); + break; + case PCAN_BAUD_10K: + strcpy_s(buffer, MAX_PATH, "10 kBit/sec"); + break; + case PCAN_BAUD_5K: + strcpy_s(buffer, MAX_PATH, "5 kBit/sec"); + break; + default: + strcpy_s(buffer, MAX_PATH, "Unknown Bitrate"); + break; + } +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.h new file mode 100644 index 0000000..d2fb04b --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.h @@ -0,0 +1,97 @@ +#include "stdafx.h" +#include "PCANBasic.h" + +class ManualWrite +{ +private: + /// + /// Sets the PCANHandle (Hardware Channel) + /// + const TPCANHandle PcanHandle = PCAN_USBBUS1; + /// + /// Sets the desired connection mode (CAN = false / CAN-FD = true) + /// + const bool IsFD = false; + /// + /// Sets the bitrate for normal CAN devices + /// + const TPCANBaudrate Bitrate = PCAN_BAUD_500K; + /// + /// Sets the bitrate for CAN FD devices. + /// Example - Bitrate Nom: 1Mbit/s Data: 2Mbit/s: + /// "f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1" + /// + const TPCANBitrateFD BitrateFD = const_cast("f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1"); + +public: + // ManualWrite constructor + // + ManualWrite(); + + // ManualWrite destructor + // + ~ManualWrite(); + +private: + /// + /// Function for writing PCAN-Basic messages + /// + void WriteMessages(); + + /// + /// Function for writing messages on CAN devices + /// + /// A TPCANStatus error code + TPCANStatus WriteMessage(); + + /// + /// Function for writing messages on CAN-FD devices + /// + /// A TPCANStatus error code + TPCANStatus WriteMessageFD(); + + /// + /// Shows/prints the configurable parameters for this sample and information about them + /// + void ShowConfigurationHelp(); + + /// + /// Shows/prints the configured paramters + /// + void ShowCurrentConfiguration(); + + /// + /// Shows formatted status + /// + /// Will be formatted + void ShowStatus(TPCANStatus status); + + /// + /// Gets the formatted text for a PCAN-Basic channel handle + /// + /// PCAN-Basic Handle to format + /// A string buffer for the channel name + /// If the channel is FD capable + void FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD); + + /// + /// Gets name of a TPCANHandle + /// + /// TPCANHandle to get name + /// A string buffer for the name of the TPCANHandle (size MAX_PATH) + void GetTPCANHandleName(TPCANHandle handle, LPSTR buffer); + + /// + /// Help Function used to get an error as text + /// + /// Error code to be translated + /// A string buffer for the translated error (size MAX_PATH) + void GetFormattedError(TPCANStatus error, LPSTR buffer); + + /// + /// Convert bitrate c_short value to readable string + /// + /// Bitrate to be converted + /// A string buffer for the converted bitrate (size MAX_PATH) + void ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer); +}; \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.sln new file mode 100644 index 0000000..b88cba4 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ManualWrite", "04_ManualWrite.vcxproj", "{0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x64.ActiveCfg = Debug|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x64.Build.0 = Debug|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x86.ActiveCfg = Debug|Win32 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x86.Build.0 = Debug|Win32 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x64.ActiveCfg = Release|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x64.Build.0 = Release|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x86.ActiveCfg = Release|Win32 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E99604D1-ECD8-4509-9C07-01682C0134A8} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.vcxproj b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.vcxproj new file mode 100644 index 0000000..0910acf --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {0b959a9f-f86f-4ee0-a45b-9fc1f6f89a0f} + ManualWrite + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.vcxproj.filters b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.vcxproj.filters new file mode 100644 index 0000000..100c81e --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/04_ManualWrite.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/PCANBasic.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/RunExample.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/RunExample.cpp new file mode 100644 index 0000000..5c0f1fe --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/RunExample.cpp @@ -0,0 +1,6 @@ +#include "04_ManualWrite.h" + +int main() +{ + ManualWrite start; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/lib/x64/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/lib/x64/PCANBasic.lib new file mode 100644 index 0000000..2df8f1c Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/lib/x64/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/lib/x86/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/lib/x86/PCANBasic.lib new file mode 100644 index 0000000..7320f2b Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/lib/x86/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/stdafx.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/stdafx.cpp new file mode 100644 index 0000000..aa558e2 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PCANBasicExample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/stdafx.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/stdafx.h new file mode 100644 index 0000000..26eedce --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/stdafx.h @@ -0,0 +1,10 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once +#include +#include +#include +#include +#include "targetver.h" \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/targetver.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/targetver.h new file mode 100644 index 0000000..3d779e1 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/04_ManualWrite/targetver.h @@ -0,0 +1,25 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/05_TimerRead/ReadMe.txt b/PCAN API/PCAN-Basic API/Samples/NativeC++/05_TimerRead/ReadMe.txt new file mode 100644 index 0000000..060e550 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/05_TimerRead/ReadMe.txt @@ -0,0 +1,7 @@ +No Timer class: +~~~~~~~~~~~~~~~ + +Since there is no timer class in the environemnt used for the sample project, a timer is actually implemented by using a thread. +In order to check how a thread is used, please refer to the sample project "07_ThreadRead". + +PEAK-Team \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/06_TimerWrite/ReadMe.txt b/PCAN API/PCAN-Basic API/Samples/NativeC++/06_TimerWrite/ReadMe.txt new file mode 100644 index 0000000..060e550 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/06_TimerWrite/ReadMe.txt @@ -0,0 +1,7 @@ +No Timer class: +~~~~~~~~~~~~~~~ + +Since there is no timer class in the environemnt used for the sample project, a timer is actually implemented by using a thread. +In order to check how a thread is used, please refer to the sample project "07_ThreadRead". + +PEAK-Team \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.cpp new file mode 100644 index 0000000..25900cb --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.cpp @@ -0,0 +1,402 @@ +#include "07_ThreadRead.h" + +ThreadRead::ThreadRead() +{ + ShowConfigurationHelp(); // Shows information about this sample + ShowCurrentConfiguration(); // Shows the current parameters configuration + + TPCANStatus stsResult; + // Initialization of the selected channel + if (IsFD) + stsResult = CAN_InitializeFD(PcanHandle, BitrateFD); + else + stsResult = CAN_Initialize(PcanHandle, Bitrate); + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "Can not initialize. Please check the defines in the code.\n"; + ShowStatus(stsResult); + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); + return; + } + + // Reading messages... + std::cout << "Successfully initialized.\n"; + m_ThreadRun = true; + m_ReadThread = new std::thread(&ThreadRead::ThreadExecute, this); + std::cout << "Started reading messages...\n"; + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); +} + +ThreadRead::~ThreadRead() +{ + m_ThreadRun = false; + m_ReadThread->join(); + delete m_ReadThread; + CAN_Uninitialize(PCAN_NONEBUS); +} + +void ThreadRead::ThreadExecute() +{ + while (m_ThreadRun) + { + // Sleep(1); //Use Sleep to reduce the CPU load + ReadMessages(); + } +} + +void ThreadRead::ReadMessages() +{ + TPCANStatus stsResult; + + // We read at least one time the queue looking for messages. If a message is found, we look again trying to + // find more. If the queue is empty or an error occurr, we get out from the dowhile statement. + do + { + stsResult = IsFD ? ReadMessageFD() : ReadMessage(); + if (stsResult != PCAN_ERROR_OK && stsResult != PCAN_ERROR_QRCVEMPTY) + { + ShowStatus(stsResult); + return; + } + } while (!(stsResult & PCAN_ERROR_QRCVEMPTY)); +} + +TPCANStatus ThreadRead::ReadMessageFD() +{ + TPCANMsgFD CANMsg; + TPCANTimestampFD CANTimeStamp; + + // We execute the "Read" function of the PCANBasic + TPCANStatus stsResult = CAN_ReadFD(PcanHandle, &CANMsg, &CANTimeStamp); + if (stsResult != PCAN_ERROR_QRCVEMPTY) + // We process the received message + ProcessMessageCanFD(CANMsg, CANTimeStamp); + + return stsResult; +} + +TPCANStatus ThreadRead::ReadMessage() +{ + TPCANMsg CANMsg; + TPCANTimestamp CANTimeStamp; + + // We execute the "Read" function of the PCANBasic + TPCANStatus stsResult = CAN_Read(PcanHandle, &CANMsg, &CANTimeStamp); + if (stsResult != PCAN_ERROR_QRCVEMPTY) + // We process the received message + ProcessMessageCan(CANMsg, CANTimeStamp); + + return stsResult; +} + +void ThreadRead::ProcessMessageCan(TPCANMsg msg, TPCANTimestamp itsTimeStamp) +{ + UINT64 microsTimestamp = ((UINT64)itsTimeStamp.micros + 1000 * (UINT64)itsTimeStamp.millis + 0x100000000 * 1000 * itsTimeStamp.millis_overflow); + + std::cout << "Type: " << GetMsgTypeString(msg.MSGTYPE) << "\n"; + std::cout << "ID: " << GetIdString(msg.ID, msg.MSGTYPE) << "\n"; + char result[MAX_PATH] = { 0 }; + sprintf_s(result, sizeof(result), "%i", msg.LEN); + std::cout << "Length: " << result << "\n"; + std::cout << "Time: " << GetTimeString(microsTimestamp) << "\n"; + std::cout << "Data: " << GetDataString(msg.DATA, msg.MSGTYPE, msg.LEN) << "\n"; + std::cout << "----------------------------------------------------------\n"; +} + +void ThreadRead::ProcessMessageCanFD(TPCANMsgFD msg, TPCANTimestampFD itsTimeStamp) +{ + std::cout << "Type: " << GetMsgTypeString(msg.MSGTYPE) << "\n"; + std::cout << "ID: " << GetIdString(msg.ID, msg.MSGTYPE) << "\n"; + std::cout << "Length: " << GetLengthFromDLC(msg.DLC) << "\n"; + std::cout << "Time: " << GetTimeString(itsTimeStamp) << "\n"; + std::cout << "Data: " << GetDataString(msg.DATA, msg.MSGTYPE, GetLengthFromDLC(msg.DLC)) << "\n"; + std::cout << "----------------------------------------------------------\n"; +} + +void ThreadRead::ShowConfigurationHelp() +{ + std::cout << "=========================================================================================\n"; + std::cout << "| PCAN-Basic ThreadRead Example |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "Following parameters are to be adjusted before launching, according to the hardware used |\n"; + std::cout << " |\n"; + std::cout << "* PcanHandle: Numeric value that represents the handle of the PCAN-Basic channel to use. |\n"; + std::cout << " See 'PCAN-Handle Definitions' within the documentation |\n"; + std::cout << "* IsFD: Boolean value that indicates the communication mode, CAN (false) or CAN-FD (true)|\n"; + std::cout << "* Bitrate: Numeric value that represents the BTR0/BR1 bitrate value to be used for CAN |\n"; + std::cout << " communication |\n"; + std::cout << "* BitrateFD: String value that represents the nominal/data bitrate value to be used for |\n"; + std::cout << " CAN-FD communication |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "\n"; +} + +void ThreadRead::ShowCurrentConfiguration() +{ + std::cout << "Parameter values used\n"; + std::cout << "----------------------\n"; + char buffer[MAX_PATH]; + FormatChannelName(PcanHandle, buffer, IsFD); + std::cout << "* PCANHandle: " << buffer << "\n"; + if (IsFD) + std::cout << "* IsFD: True\n"; + else + std::cout << "* IsFD: False\n"; + ConvertBitrateToString(Bitrate, buffer); + std::cout << "* Bitrate: " << buffer << "\n"; + std::cout << "* BitrateFD: " << BitrateFD << "\n"; + std::cout << "\n"; +} + +void ThreadRead::ShowStatus(TPCANStatus status) +{ + std::cout << "=========================================================================================\n"; + char buffer[MAX_PATH]; + GetFormattedError(status, buffer); + std::cout << buffer << "\n"; + std::cout << "=========================================================================================\n"; +} + +void ThreadRead::FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD) +{ + TPCANDevice devDevice; + BYTE byChannel; + + // Gets the owner device and channel for a PCAN-Basic handle + if (handle < 0x100) + { + devDevice = (TPCANDevice)(handle >> 4); + byChannel = (BYTE)(handle & 0xF); + } + else + { + devDevice = (TPCANDevice)(handle >> 8); + byChannel = (BYTE)(handle & 0xFF); + } + + // Constructs the PCAN-Basic Channel name and return it + char handleBuffer[MAX_PATH]; + GetTPCANHandleName(handle, handleBuffer); + if (isFD) + sprintf_s(buffer, MAX_PATH, "%s:FD %d (%Xh)", handleBuffer, byChannel, handle); + else + sprintf_s(buffer, MAX_PATH, "%s %d (%Xh)", handleBuffer, byChannel, handle); +} + +void ThreadRead::GetTPCANHandleName(TPCANHandle handle, LPSTR buffer) +{ + strcpy_s(buffer, MAX_PATH, "PCAN_NONE"); + switch (handle) + { + case PCAN_PCIBUS1: + case PCAN_PCIBUS2: + case PCAN_PCIBUS3: + case PCAN_PCIBUS4: + case PCAN_PCIBUS5: + case PCAN_PCIBUS6: + case PCAN_PCIBUS7: + case PCAN_PCIBUS8: + case PCAN_PCIBUS9: + case PCAN_PCIBUS10: + case PCAN_PCIBUS11: + case PCAN_PCIBUS12: + case PCAN_PCIBUS13: + case PCAN_PCIBUS14: + case PCAN_PCIBUS15: + case PCAN_PCIBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_PCI"); + break; + + case PCAN_USBBUS1: + case PCAN_USBBUS2: + case PCAN_USBBUS3: + case PCAN_USBBUS4: + case PCAN_USBBUS5: + case PCAN_USBBUS6: + case PCAN_USBBUS7: + case PCAN_USBBUS8: + case PCAN_USBBUS9: + case PCAN_USBBUS10: + case PCAN_USBBUS11: + case PCAN_USBBUS12: + case PCAN_USBBUS13: + case PCAN_USBBUS14: + case PCAN_USBBUS15: + case PCAN_USBBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_USB"); + break; + + case PCAN_LANBUS1: + case PCAN_LANBUS2: + case PCAN_LANBUS3: + case PCAN_LANBUS4: + case PCAN_LANBUS5: + case PCAN_LANBUS6: + case PCAN_LANBUS7: + case PCAN_LANBUS8: + case PCAN_LANBUS9: + case PCAN_LANBUS10: + case PCAN_LANBUS11: + case PCAN_LANBUS12: + case PCAN_LANBUS13: + case PCAN_LANBUS14: + case PCAN_LANBUS15: + case PCAN_LANBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_LAN"); + break; + + default: + strcpy_s(buffer, MAX_PATH, "UNKNOWN"); + break; + } +} + +void ThreadRead::GetFormattedError(TPCANStatus error, LPSTR buffer) +{ + // Gets the text using the GetErrorText API function. If the function success, the translated error is returned. + // If it fails, a text describing the current error is returned. + if (CAN_GetErrorText(error, 0x09, buffer) != PCAN_ERROR_OK) + sprintf_s(buffer, MAX_PATH, "An error occurred. Error-code's text (%Xh) couldn't be retrieved", error); +} + +void ThreadRead::ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer) +{ + switch (bitrate) + { + case PCAN_BAUD_1M: + strcpy_s(buffer, MAX_PATH, "1 MBit/sec"); + break; + case PCAN_BAUD_800K: + strcpy_s(buffer, MAX_PATH, "800 kBit/sec"); + break; + case PCAN_BAUD_500K: + strcpy_s(buffer, MAX_PATH, "500 kBit/sec"); + break; + case PCAN_BAUD_250K: + strcpy_s(buffer, MAX_PATH, "250 kBit/sec"); + break; + case PCAN_BAUD_125K: + strcpy_s(buffer, MAX_PATH, "125 kBit/sec"); + break; + case PCAN_BAUD_100K: + strcpy_s(buffer, MAX_PATH, "100 kBit/sec"); + break; + case PCAN_BAUD_95K: + strcpy_s(buffer, MAX_PATH, "95,238 kBit/sec"); + break; + case PCAN_BAUD_83K: + strcpy_s(buffer, MAX_PATH, "83,333 kBit/sec"); + break; + case PCAN_BAUD_50K: + strcpy_s(buffer, MAX_PATH, "50 kBit/sec"); + break; + case PCAN_BAUD_47K: + strcpy_s(buffer, MAX_PATH, "47,619 kBit/sec"); + break; + case PCAN_BAUD_33K: + strcpy_s(buffer, MAX_PATH, "33,333 kBit/sec"); + break; + case PCAN_BAUD_20K: + strcpy_s(buffer, MAX_PATH, "20 kBit/sec"); + break; + case PCAN_BAUD_10K: + strcpy_s(buffer, MAX_PATH, "10 kBit/sec"); + break; + case PCAN_BAUD_5K: + strcpy_s(buffer, MAX_PATH, "5 kBit/sec"); + break; + default: + strcpy_s(buffer, MAX_PATH, "Unknown Bitrate"); + break; + } +} + +std::string ThreadRead::GetMsgTypeString(TPCANMessageType msgType) +{ + if ((msgType & PCAN_MESSAGE_STATUS) == PCAN_MESSAGE_STATUS) + return "STATUS"; + + if ((msgType & PCAN_MESSAGE_ERRFRAME) == PCAN_MESSAGE_ERRFRAME) + return "ERROR"; + + std::string strTemp; + if ((msgType & PCAN_MESSAGE_EXTENDED) == PCAN_MESSAGE_EXTENDED) + strTemp = "EXT"; + else + strTemp = "STD"; + + if ((msgType & PCAN_MESSAGE_RTR) == PCAN_MESSAGE_RTR) + strTemp = (strTemp + "/RTR"); + else + if (msgType > PCAN_MESSAGE_EXTENDED) + { + strTemp = (strTemp + " [ "); + if (msgType & PCAN_MESSAGE_FD) + strTemp = (strTemp + " FD"); + if (msgType & PCAN_MESSAGE_BRS) + strTemp = (strTemp + " BRS"); + if (msgType & PCAN_MESSAGE_ESI) + strTemp = (strTemp + " ESI"); + strTemp = (strTemp + " ]"); + } + + return strTemp; +} + +std::string ThreadRead::GetIdString(UINT32 id, TPCANMessageType msgType) +{ + char result[MAX_PATH] = { 0 }; + if ((msgType & PCAN_MESSAGE_EXTENDED) == PCAN_MESSAGE_EXTENDED) + { + sprintf_s(result, sizeof(result), "%08Xh", id); + return result; + } + sprintf_s(result, sizeof(result), "%03Xh", id); + return result; +} + +int ThreadRead::GetLengthFromDLC(BYTE dlc) +{ + switch (dlc) + { + case 9: return 12; + case 10: return 16; + case 11: return 20; + case 12: return 24; + case 13: return 32; + case 14: return 48; + case 15: return 64; + default: return dlc; + } +} + +std::string ThreadRead::GetTimeString(TPCANTimestampFD time) +{ + char result[MAX_PATH] = { 0 }; + double fTime = (time / 1000.0); + sprintf_s(result, sizeof(result), "%.1f", fTime); + return result; +} + +std::string ThreadRead::GetDataString(BYTE data[], TPCANMessageType msgType, int dataLength) +{ + if ((msgType & PCAN_MESSAGE_RTR) == PCAN_MESSAGE_RTR) + return "Remote Request"; + else + { + char strTemp[MAX_PATH] = { 0 }; + std::string result = ""; + for (int i = 0; i < dataLength; i++) + { + sprintf_s(strTemp, sizeof(strTemp), "%02X ", data[i]); + result.append(strTemp); + } + + return result; + } +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.h new file mode 100644 index 0000000..a77ab40 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.h @@ -0,0 +1,162 @@ +#include "stdafx.h" +#include "PCANBasic.h" + +class ThreadRead +{ +private: + /// + /// Sets the PCANHandle (Hardware Channel) + /// + const TPCANHandle PcanHandle = PCAN_USBBUS1; + /// + /// Sets the desired connection mode (CAN = false / CAN-FD = true) + /// + const bool IsFD = false; + /// + /// Sets the bitrate for normal CAN devices + /// + const TPCANBaudrate Bitrate = PCAN_BAUD_500K; + /// + /// Sets the bitrate for CAN FD devices. + /// Example - Bitrate Nom: 1Mbit/s Data: 2Mbit/s: + /// "f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1" + /// + const TPCANBitrateFD BitrateFD = const_cast("f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1"); + /// + /// Thread for reading messages + /// + std::thread* m_ReadThread; + /// + /// Shows if thread run + /// + bool m_ThreadRun; + +public: + // ThreadRead constructor + // + ThreadRead(); + + // ThreadRead destructor + // + ~ThreadRead(); + +private: + /// + /// Thread function for reading messages + /// + void ThreadExecute(); + + /// + /// Function for reading PCAN-Basic messages + /// + void ReadMessages(); + + /// + /// Function for reading messages on CAN-FD devices + /// + /// A TPCANStatus error code + TPCANStatus ReadMessageFD(); + + /// + /// Function for reading CAN messages on normal CAN devices + /// + /// A TPCANStatus error code + TPCANStatus ReadMessage(); + + /// + /// Processes a received CAN message + /// + /// The received PCAN-Basic CAN message + /// Timestamp of the message as TPCANTimestamp structure + void ProcessMessageCan(TPCANMsg msg, TPCANTimestamp itsTimeStamp); + + /// + /// Processes a received CAN-FD message + /// + /// The received PCAN-Basic CAN-FD message + /// Timestamp of the message as microseconds (ulong) + void ProcessMessageCanFD(TPCANMsgFD msg, TPCANTimestampFD itsTimeStamp); + + /// + /// Shows/prints the configurable parameters for this sample and information about them + /// + void ShowConfigurationHelp(); + + /// + /// Shows/prints the configured paramters + /// + void ShowCurrentConfiguration(); + + /// + /// Shows formatted status + /// + /// Will be formatted + void ShowStatus(TPCANStatus status); + + /// + /// Gets the formatted text for a PCAN-Basic channel handle + /// + /// PCAN-Basic Handle to format + /// A string buffer for the channel name + /// If the channel is FD capable + void FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD); + + /// + /// Gets name of a TPCANHandle + /// + /// TPCANHandle to get name + /// A string buffer for the name of the TPCANHandle (size MAX_PATH) + void GetTPCANHandleName(TPCANHandle handle, LPSTR buffer); + + /// + /// Help Function used to get an error as text + /// + /// Error code to be translated + /// A string buffer for the translated error (size MAX_PATH) + void GetFormattedError(TPCANStatus error, LPSTR buffer); + + /// + /// Convert bitrate c_short value to readable string + /// + /// Bitrate to be converted + /// A string buffer for the converted bitrate (size MAX_PATH) + void ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer); + + /// + /// Gets the string representation of the type of a CAN message + /// + /// Type of a CAN message + /// The type of the CAN message as string + std::string GetMsgTypeString(TPCANMessageType msgType); + + /// + /// Gets the string representation of the ID of a CAN message + /// + /// Id to be parsed + /// Type flags of the message the Id belong + /// Hexadecimal representation of the ID of a CAN message + std::string GetIdString(UINT32 id, TPCANMessageType msgType); + + /// + /// Gets the data length of a CAN message + /// + /// Data length code of a CAN message + /// Data length as integer represented by the given DLC code + int GetLengthFromDLC(BYTE dlc); + + /// + /// Gets the string representation of the timestamp of a CAN message, in milliseconds + /// + /// Timestamp in microseconds + /// String representing the timestamp in milliseconds + std::string GetTimeString(TPCANTimestampFD time); + + /// + /// Gets the data of a CAN message as a string + /// + /// Array of bytes containing the data to parse + /// Type flags of the message the data belong + /// The amount of bytes to take into account wihtin the given data + /// A string with hexadecimal formatted data bytes of a CAN message + std::string GetDataString(BYTE data[], TPCANMessageType msgType, int dataLength); +}; \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.sln new file mode 100644 index 0000000..80d0194 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ThreadRead", "07_ThreadRead.vcxproj", "{38F5A9E9-F98B-40CC-B026-B63405CFCF09}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x64.ActiveCfg = Debug|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x64.Build.0 = Debug|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x86.ActiveCfg = Debug|Win32 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x86.Build.0 = Debug|Win32 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x64.ActiveCfg = Release|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x64.Build.0 = Release|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x86.ActiveCfg = Release|Win32 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7FE26B73-F629-4A12-884E-DDD774A8012A} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.vcxproj b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.vcxproj new file mode 100644 index 0000000..7d1146a --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {38f5a9e9-f98b-40cc-b026-b63405cfcf09} + ThreadRead + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.vcxproj.filters b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.vcxproj.filters new file mode 100644 index 0000000..c13a63c --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/07_ThreadRead.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/PCANBasic.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/RunExample.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/RunExample.cpp new file mode 100644 index 0000000..64092e3 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/RunExample.cpp @@ -0,0 +1,6 @@ +#include "07_ThreadRead.h" + +int main() +{ + ThreadRead start; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/lib/x64/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/lib/x64/PCANBasic.lib new file mode 100644 index 0000000..2df8f1c Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/lib/x64/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/lib/x86/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/lib/x86/PCANBasic.lib new file mode 100644 index 0000000..7320f2b Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/lib/x86/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/stdafx.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/stdafx.cpp new file mode 100644 index 0000000..aa558e2 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PCANBasicExample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/stdafx.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/stdafx.h new file mode 100644 index 0000000..6e8151b --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/stdafx.h @@ -0,0 +1,11 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once +#include +#include +#include +#include +#include +#include "targetver.h" \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/targetver.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/targetver.h new file mode 100644 index 0000000..3d779e1 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/07_ThreadRead/targetver.h @@ -0,0 +1,25 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.cpp new file mode 100644 index 0000000..c217f68 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.cpp @@ -0,0 +1,423 @@ +#include "08_EventDrivenRead.h" + +EventDrivenRead::EventDrivenRead() +{ + ShowConfigurationHelp(); // Shows information about this sample + ShowCurrentConfiguration(); // Shows the current parameters configuration + + TPCANStatus stsResult; + // Initialization of the selected channel + if (IsFD) + stsResult = CAN_InitializeFD(PcanHandle, BitrateFD); + else + stsResult = CAN_Initialize(PcanHandle, Bitrate); + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "Can not initialize. Please check the defines in the code.\n"; + ShowStatus(stsResult); + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); + return; + } + + // Reading messages... + std::cout << "Successfully initialized.\n"; + m_ThreadRun = true; + m_ReadThread = new std::thread(&EventDrivenRead::ThreadExecute, this); + std::cout << "Started reading messages...\n"; + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); +} + +EventDrivenRead::~EventDrivenRead() +{ + m_ThreadRun = false; + if (m_ReadThread != NULL) + { + m_ReadThread->join(); + delete m_ReadThread; + } + CAN_Uninitialize(PCAN_NONEBUS); +} + +void EventDrivenRead::ThreadExecute() +{ + // Sets the handle of the Receive-Event. + HANDLE iBuffer = CreateEvent(NULL, FALSE, FALSE, L""); + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_RECEIVE_EVENT, &iBuffer, sizeof(iBuffer)); + + if (stsResult != PCAN_ERROR_OK) + { + ShowStatus(stsResult); + return; + } + + while (m_ThreadRun) + { + // Checks for messages when an event is received + if (WaitForSingleObject(iBuffer, 50) == WAIT_OBJECT_0) + ReadMessages(); + } + + // Removes the Receive-Event again. + iBuffer = 0; + stsResult = CAN_SetValue(PcanHandle, PCAN_RECEIVE_EVENT, &iBuffer, sizeof(iBuffer)); + + if (stsResult != PCAN_ERROR_OK) + ShowStatus(stsResult); +} + +void EventDrivenRead::ReadMessages() +{ + TPCANStatus stsResult; + + // We read at least one time the queue looking for messages. If a message is found, we look again trying to + // find more. If the queue is empty or an error occurr, we get out from the dowhile statement. + do + { + stsResult = IsFD ? ReadMessageFD() : ReadMessage(); + if (stsResult != PCAN_ERROR_OK && stsResult != PCAN_ERROR_QRCVEMPTY) + { + ShowStatus(stsResult); + return; + } + } while (!(stsResult & PCAN_ERROR_QRCVEMPTY)); +} + +TPCANStatus EventDrivenRead::ReadMessageFD() +{ + TPCANMsgFD CANMsg; + TPCANTimestampFD CANTimeStamp; + + // We execute the "Read" function of the PCANBasic + TPCANStatus stsResult = CAN_ReadFD(PcanHandle, &CANMsg, &CANTimeStamp); + if (stsResult != PCAN_ERROR_QRCVEMPTY) + // We process the received message + ProcessMessageCanFD(CANMsg, CANTimeStamp); + + return stsResult; +} + +TPCANStatus EventDrivenRead::ReadMessage() +{ + TPCANMsg CANMsg; + TPCANTimestamp CANTimeStamp; + + // We execute the "Read" function of the PCANBasic + TPCANStatus stsResult = CAN_Read(PcanHandle, &CANMsg, &CANTimeStamp); + if (stsResult != PCAN_ERROR_QRCVEMPTY) + // We process the received message + ProcessMessageCan(CANMsg, CANTimeStamp); + + return stsResult; +} + +void EventDrivenRead::ProcessMessageCan(TPCANMsg msg, TPCANTimestamp itsTimeStamp) +{ + UINT64 microsTimestamp = (itsTimeStamp.micros + 1000 * itsTimeStamp.millis + 0x100000000 * 1000 * itsTimeStamp.millis_overflow); + + std::cout << "Type: " << GetMsgTypeString(msg.MSGTYPE) << "\n"; + std::cout << "ID: " << GetIdString(msg.ID, msg.MSGTYPE) << "\n"; + char result[MAX_PATH] = { 0 }; + sprintf_s(result, sizeof(result), "%i", msg.LEN); + std::cout << "Length: " << result << "\n"; + std::cout << "Time: " << GetTimeString(microsTimestamp) << "\n"; + std::cout << "Data: " << GetDataString(msg.DATA, msg.MSGTYPE, msg.LEN) << "\n"; + std::cout << "----------------------------------------------------------\n"; +} + +void EventDrivenRead::ProcessMessageCanFD(TPCANMsgFD msg, TPCANTimestampFD itsTimeStamp) +{ + std::cout << "Type: " << GetMsgTypeString(msg.MSGTYPE) << "\n"; + std::cout << "ID: " << GetIdString(msg.ID, msg.MSGTYPE) << "\n"; + std::cout << "Length: " << GetLengthFromDLC(msg.DLC) << "\n"; + std::cout << "Time: " << GetTimeString(itsTimeStamp) << "\n"; + std::cout << "Data: " << GetDataString(msg.DATA, msg.MSGTYPE, GetLengthFromDLC(msg.DLC)) << "\n"; + std::cout << "----------------------------------------------------------\n"; +} + +void EventDrivenRead::ShowConfigurationHelp() +{ + std::cout << "=========================================================================================\n"; + std::cout << "| PCAN-Basic EventDrivenRead Example |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "Following parameters are to be adjusted before launching, according to the hardware used |\n"; + std::cout << " |\n"; + std::cout << "* PcanHandle: Numeric value that represents the handle of the PCAN-Basic channel to use. |\n"; + std::cout << " See 'PCAN-Handle Definitions' within the documentation |\n"; + std::cout << "* IsFD: Boolean value that indicates the communication mode, CAN (false) or CAN-FD (true)|\n"; + std::cout << "* Bitrate: Numeric value that represents the BTR0/BR1 bitrate value to be used for CAN |\n"; + std::cout << " communication |\n"; + std::cout << "* BitrateFD: String value that represents the nominal/data bitrate value to be used for |\n"; + std::cout << " CAN-FD communication |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "\n"; +} + +void EventDrivenRead::ShowCurrentConfiguration() +{ + std::cout << "Parameter values used\n"; + std::cout << "----------------------\n"; + char buffer[MAX_PATH]; + FormatChannelName(PcanHandle, buffer, IsFD); + std::cout << "* PCANHandle: " << buffer << "\n"; + if (IsFD) + std::cout << "* IsFD: True\n"; + else + std::cout << "* IsFD: False\n"; + ConvertBitrateToString(Bitrate, buffer); + std::cout << "* Bitrate: " << buffer << "\n"; + std::cout << "* BitrateFD: " << BitrateFD << "\n"; + std::cout << "\n"; +} + +void EventDrivenRead::ShowStatus(TPCANStatus status) +{ + std::cout << "=========================================================================================\n"; + char buffer[MAX_PATH]; + GetFormattedError(status, buffer); + std::cout << buffer << "\n"; + std::cout << "=========================================================================================\n"; +} + +void EventDrivenRead::FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD) +{ + TPCANDevice devDevice; + BYTE byChannel; + + // Gets the owner device and channel for a PCAN-Basic handle + if (handle < 0x100) + { + devDevice = (TPCANDevice)(handle >> 4); + byChannel = (BYTE)(handle & 0xF); + } + else + { + devDevice = (TPCANDevice)(handle >> 8); + byChannel = (BYTE)(handle & 0xFF); + } + + // Constructs the PCAN-Basic Channel name and return it + char handleBuffer[MAX_PATH]; + GetTPCANHandleName(handle, handleBuffer); + if (isFD) + sprintf_s(buffer, MAX_PATH, "%s:FD %d (%Xh)", handleBuffer, byChannel, handle); + else + sprintf_s(buffer, MAX_PATH, "%s %d (%Xh)", handleBuffer, byChannel, handle); +} + +void EventDrivenRead::GetTPCANHandleName(TPCANHandle handle, LPSTR buffer) +{ + strcpy_s(buffer, MAX_PATH, "PCAN_NONE"); + switch (handle) + { + case PCAN_PCIBUS1: + case PCAN_PCIBUS2: + case PCAN_PCIBUS3: + case PCAN_PCIBUS4: + case PCAN_PCIBUS5: + case PCAN_PCIBUS6: + case PCAN_PCIBUS7: + case PCAN_PCIBUS8: + case PCAN_PCIBUS9: + case PCAN_PCIBUS10: + case PCAN_PCIBUS11: + case PCAN_PCIBUS12: + case PCAN_PCIBUS13: + case PCAN_PCIBUS14: + case PCAN_PCIBUS15: + case PCAN_PCIBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_PCI"); + break; + + case PCAN_USBBUS1: + case PCAN_USBBUS2: + case PCAN_USBBUS3: + case PCAN_USBBUS4: + case PCAN_USBBUS5: + case PCAN_USBBUS6: + case PCAN_USBBUS7: + case PCAN_USBBUS8: + case PCAN_USBBUS9: + case PCAN_USBBUS10: + case PCAN_USBBUS11: + case PCAN_USBBUS12: + case PCAN_USBBUS13: + case PCAN_USBBUS14: + case PCAN_USBBUS15: + case PCAN_USBBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_USB"); + break; + + case PCAN_LANBUS1: + case PCAN_LANBUS2: + case PCAN_LANBUS3: + case PCAN_LANBUS4: + case PCAN_LANBUS5: + case PCAN_LANBUS6: + case PCAN_LANBUS7: + case PCAN_LANBUS8: + case PCAN_LANBUS9: + case PCAN_LANBUS10: + case PCAN_LANBUS11: + case PCAN_LANBUS12: + case PCAN_LANBUS13: + case PCAN_LANBUS14: + case PCAN_LANBUS15: + case PCAN_LANBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_LAN"); + break; + + default: + strcpy_s(buffer, MAX_PATH, "UNKNOWN"); + break; + } +} + +void EventDrivenRead::GetFormattedError(TPCANStatus error, LPSTR buffer) +{ + // Gets the text using the GetErrorText API function. If the function success, the translated error is returned. + // If it fails, a text describing the current error is returned. + if (CAN_GetErrorText(error, 0x09, buffer) != PCAN_ERROR_OK) + sprintf_s(buffer, MAX_PATH, "An error occurred. Error-code's text (%Xh) couldn't be retrieved", error); +} + +void EventDrivenRead::ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer) +{ + switch (bitrate) + { + case PCAN_BAUD_1M: + strcpy_s(buffer, MAX_PATH, "1 MBit/sec"); + break; + case PCAN_BAUD_800K: + strcpy_s(buffer, MAX_PATH, "800 kBit/sec"); + break; + case PCAN_BAUD_500K: + strcpy_s(buffer, MAX_PATH, "500 kBit/sec"); + break; + case PCAN_BAUD_250K: + strcpy_s(buffer, MAX_PATH, "250 kBit/sec"); + break; + case PCAN_BAUD_125K: + strcpy_s(buffer, MAX_PATH, "125 kBit/sec"); + break; + case PCAN_BAUD_100K: + strcpy_s(buffer, MAX_PATH, "100 kBit/sec"); + break; + case PCAN_BAUD_95K: + strcpy_s(buffer, MAX_PATH, "95,238 kBit/sec"); + break; + case PCAN_BAUD_83K: + strcpy_s(buffer, MAX_PATH, "83,333 kBit/sec"); + break; + case PCAN_BAUD_50K: + strcpy_s(buffer, MAX_PATH, "50 kBit/sec"); + break; + case PCAN_BAUD_47K: + strcpy_s(buffer, MAX_PATH, "47,619 kBit/sec"); + break; + case PCAN_BAUD_33K: + strcpy_s(buffer, MAX_PATH, "33,333 kBit/sec"); + break; + case PCAN_BAUD_20K: + strcpy_s(buffer, MAX_PATH, "20 kBit/sec"); + break; + case PCAN_BAUD_10K: + strcpy_s(buffer, MAX_PATH, "10 kBit/sec"); + break; + case PCAN_BAUD_5K: + strcpy_s(buffer, MAX_PATH, "5 kBit/sec"); + break; + default: + strcpy_s(buffer, MAX_PATH, "Unknown Bitrate"); + break; + } +} + +std::string EventDrivenRead::GetMsgTypeString(TPCANMessageType msgType) +{ + if ((msgType & PCAN_MESSAGE_STATUS) == PCAN_MESSAGE_STATUS) + return "STATUS"; + + if ((msgType & PCAN_MESSAGE_ERRFRAME) == PCAN_MESSAGE_ERRFRAME) + return "ERROR"; + + std::string strTemp; + if ((msgType & PCAN_MESSAGE_EXTENDED) == PCAN_MESSAGE_EXTENDED) + strTemp = "EXT"; + else + strTemp = "STD"; + + if ((msgType & PCAN_MESSAGE_RTR) == PCAN_MESSAGE_RTR) + strTemp = (strTemp + "/RTR"); + else + if (msgType > PCAN_MESSAGE_EXTENDED) + { + strTemp = (strTemp + " [ "); + if (msgType & PCAN_MESSAGE_FD) + strTemp = (strTemp + " FD"); + if (msgType & PCAN_MESSAGE_BRS) + strTemp = (strTemp + " BRS"); + if (msgType & PCAN_MESSAGE_ESI) + strTemp = (strTemp + " ESI"); + strTemp = (strTemp + " ]"); + } + + return strTemp; +} + +std::string EventDrivenRead::GetIdString(UINT32 id, TPCANMessageType msgType) +{ + char result[MAX_PATH] = { 0 }; + if ((msgType & PCAN_MESSAGE_EXTENDED) == PCAN_MESSAGE_EXTENDED) + { + sprintf_s(result, sizeof(result), "%08Xh", id); + return result; + } + sprintf_s(result, sizeof(result), "%03Xh", id); + return result; +} + +int EventDrivenRead::GetLengthFromDLC(BYTE dlc) +{ + switch (dlc) + { + case 9: return 12; + case 10: return 16; + case 11: return 20; + case 12: return 24; + case 13: return 32; + case 14: return 48; + case 15: return 64; + default: return dlc; + } +} + +std::string EventDrivenRead::GetTimeString(TPCANTimestampFD time) +{ + char result[MAX_PATH] = { 0 }; + double fTime = (time / 1000.0); + sprintf_s(result, sizeof(result), "%.1f", fTime); + return result; +} + +std::string EventDrivenRead::GetDataString(BYTE data[], TPCANMessageType msgType, int dataLength) +{ + if ((msgType & PCAN_MESSAGE_RTR) == PCAN_MESSAGE_RTR) + return "Remote Request"; + else + { + char strTemp[MAX_PATH] = { 0 }; + std::string result = ""; + for (int i = 0; i < dataLength; i++) + { + sprintf_s(strTemp, sizeof(strTemp), "%02X ", data[i]); + result.append(strTemp); + } + + return result; + } +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.h new file mode 100644 index 0000000..d18a4e5 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.h @@ -0,0 +1,162 @@ +#include "stdafx.h" +#include "PCANBasic.h" + +class EventDrivenRead +{ +private: + /// + /// Sets the PCANHandle (Hardware Channel) + /// + const TPCANHandle PcanHandle = PCAN_USBBUS1; + /// + /// Sets the desired connection mode (CAN = false / CAN-FD = true) + /// + const bool IsFD = false; + /// + /// Sets the bitrate for normal CAN devices + /// + const TPCANBaudrate Bitrate = PCAN_BAUD_500K; + /// + /// Sets the bitrate for CAN FD devices. + /// Example - Bitrate Nom: 1Mbit/s Data: 2Mbit/s: + /// "f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1" + /// + const TPCANBitrateFD BitrateFD = const_cast("f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1"); + /// + /// Thread for reading messages + /// + std::thread* m_ReadThread; + /// + /// Shows if thread run + /// + bool m_ThreadRun; + +public: + // EventDrivenRead constructor + // + EventDrivenRead(); + + // EventDrivenRead destructor + // + ~EventDrivenRead(); + +private: + /// + /// Thread function for reading messages + /// + void ThreadExecute(); + + /// + /// Function for reading PCAN-Basic messages + /// + void ReadMessages(); + + /// + /// Function for reading messages on CAN-FD devices + /// + /// A TPCANStatus error code + TPCANStatus ReadMessageFD(); + + /// + /// Function for reading CAN messages on normal CAN devices + /// + /// A TPCANStatus error code + TPCANStatus ReadMessage(); + + /// + /// Processes a received CAN message + /// + /// The received PCAN-Basic CAN message + /// Timestamp of the message as TPCANTimestamp structure + void ProcessMessageCan(TPCANMsg msg, TPCANTimestamp itsTimeStamp); + + /// + /// Processes a received CAN-FD message + /// + /// The received PCAN-Basic CAN-FD message + /// Timestamp of the message as microseconds (ulong) + void ProcessMessageCanFD(TPCANMsgFD msg, TPCANTimestampFD itsTimeStamp); + + /// + /// Shows/prints the configurable parameters for this sample and information about them + /// + void ShowConfigurationHelp(); + + /// + /// Shows/prints the configured paramters + /// + void ShowCurrentConfiguration(); + + /// + /// Shows formatted status + /// + /// Will be formatted + void ShowStatus(TPCANStatus status); + + /// + /// Gets the formatted text for a PCAN-Basic channel handle + /// + /// PCAN-Basic Handle to format + /// A string buffer for the channel name + /// If the channel is FD capable + void FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD); + + /// + /// Gets name of a TPCANHandle + /// + /// TPCANHandle to get name + /// A string buffer for the name of the TPCANHandle (size MAX_PATH) + void GetTPCANHandleName(TPCANHandle handle, LPSTR buffer); + + /// + /// Help Function used to get an error as text + /// + /// Error code to be translated + /// A string buffer for the translated error (size MAX_PATH) + void GetFormattedError(TPCANStatus error, LPSTR buffer); + + /// + /// Convert bitrate c_short value to readable string + /// + /// Bitrate to be converted + /// A string buffer for the converted bitrate (size MAX_PATH) + void ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer); + + /// + /// Gets the string representation of the type of a CAN message + /// + /// Type of a CAN message + /// The type of the CAN message as string + std::string GetMsgTypeString(TPCANMessageType msgType); + + /// + /// Gets the string representation of the ID of a CAN message + /// + /// Id to be parsed + /// Type flags of the message the Id belong + /// Hexadecimal representation of the ID of a CAN message + std::string GetIdString(UINT32 id, TPCANMessageType msgType); + + /// + /// Gets the data length of a CAN message + /// + /// Data length code of a CAN message + /// Data length as integer represented by the given DLC code + int GetLengthFromDLC(BYTE dlc); + + /// + /// Gets the string representation of the timestamp of a CAN message, in milliseconds + /// + /// Timestamp in microseconds + /// String representing the timestamp in milliseconds + std::string GetTimeString(TPCANTimestampFD time); + + /// + /// Gets the data of a CAN message as a string + /// + /// Array of bytes containing the data to parse + /// Type flags of the message the data belong + /// The amount of bytes to take into account wihtin the given data + /// A string with hexadecimal formatted data bytes of a CAN message + std::string GetDataString(BYTE data[], TPCANMessageType msgType, int dataLength); +}; \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.sln new file mode 100644 index 0000000..ff091db --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EventDrivenRead", "08_EventDrivenRead.vcxproj", "{67AEB664-38BC-45D0-A90F-3C98FEDCA668}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x64.ActiveCfg = Debug|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x64.Build.0 = Debug|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x86.ActiveCfg = Debug|Win32 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x86.Build.0 = Debug|Win32 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x64.ActiveCfg = Release|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x64.Build.0 = Release|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x86.ActiveCfg = Release|Win32 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {326598E5-0D64-45B9-8773-1EDCE215504D} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.vcxproj b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.vcxproj new file mode 100644 index 0000000..b8a4640 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {67aeb664-38bc-45d0-a90f-3c98fedca668} + EventDrivenRead + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.vcxproj.filters b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.vcxproj.filters new file mode 100644 index 0000000..0240cbb --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/08_EventDrivenRead.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/PCANBasic.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/RunExample.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/RunExample.cpp new file mode 100644 index 0000000..ab835d9 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/RunExample.cpp @@ -0,0 +1,6 @@ +#include "08_EventDrivenRead.h" + +int main() +{ + EventDrivenRead start; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/lib/x64/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/lib/x64/PCANBasic.lib new file mode 100644 index 0000000..2df8f1c Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/lib/x64/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/lib/x86/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/lib/x86/PCANBasic.lib new file mode 100644 index 0000000..7320f2b Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/lib/x86/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/stdafx.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/stdafx.cpp new file mode 100644 index 0000000..c120926 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/stdafx.cpp @@ -0,0 +1,5 @@ +// stdafx.cpp : source file that includes just the standard includes +// PCANBasicExample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/stdafx.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/stdafx.h new file mode 100644 index 0000000..6e8151b --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/stdafx.h @@ -0,0 +1,11 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once +#include +#include +#include +#include +#include +#include "targetver.h" \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/targetver.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/targetver.h new file mode 100644 index 0000000..3d779e1 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/08_EventDrivenRead/targetver.h @@ -0,0 +1,25 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.cpp new file mode 100644 index 0000000..326aff6 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.cpp @@ -0,0 +1,377 @@ +#include "09_TraceFiles.h" + +TraceFiles::TraceFiles() +{ + ShowConfigurationHelp(); // Shows information about this sample + ShowCurrentConfiguration(); // Shows the current parameters configuration + + TPCANStatus stsResult; + // Initialization of the selected channel + if (IsFD) + stsResult = CAN_InitializeFD(PcanHandle, BitrateFD); + else + stsResult = CAN_Initialize(PcanHandle, Bitrate); + + if (stsResult != PCAN_ERROR_OK) + { + std::cout << "Can not initialize. Please check the defines in the code.\n"; + ShowStatus(stsResult); + std::cout << "\n"; + std::cout << "Closing...\n"; + system("PAUSE"); + return; + } + + // Trace messages. + std::cout << "Successfully initialized.\n"; + std::cout << "Starting trace: "; + system("PAUSE"); + if (ConfigureTrace()) + { + if (StartTrace()) + { + m_ThreadRun = true; + m_ReadThread = new std::thread(&TraceFiles::ThreadExecute, this); + std::cout << "Messages are being traced.\n"; + std::cout << "Stop trace and quit: "; + system("PAUSE"); + StopTrace(); + return; + } + } + std::cout << "\n"; + std::cout << "For close: "; + system("PAUSE"); +} + +TraceFiles::~TraceFiles() +{ + m_ThreadRun = false; + m_ReadThread->join(); + CAN_Uninitialize(PCAN_NONEBUS); +} + +void TraceFiles::ThreadExecute() +{ + while (m_ThreadRun) + { + Sleep(1); //Use Sleep to reduce the CPU load + ReadMessages(); + } +} + +void TraceFiles::ReadMessages() +{ + // We read at least one time the queue looking for messages. If a message is found, we look again trying to + // find more. If the queue is empty or an error occurr, we get out from the dowhile statement. + TPCANStatus stsResult; + TPCANMsgFD CANMsgFD; + TPCANMsg CANMsg; + UINT64 TimestampFD; + TPCANTimestamp Timestamp; + do + { + stsResult = IsFD ? CAN_ReadFD(PcanHandle, &CANMsgFD, &TimestampFD) : CAN_Read(PcanHandle, &CANMsg, &Timestamp); + if (stsResult != PCAN_ERROR_OK && stsResult != PCAN_ERROR_QRCVEMPTY) + { + ShowStatus(stsResult); + return; + } + } while ((!(stsResult & PCAN_ERROR_QRCVEMPTY))); +} + +void TraceFiles::StopTrace() +{ + UINT32 iStatus = PCAN_PARAMETER_OFF; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_TRACE_STATUS, &iStatus, sizeof(UINT32)); // We stop the tracing by setting the parameter. + + if (stsResult != PCAN_ERROR_OK) + ShowStatus(stsResult); +} + +bool TraceFiles::ConfigureTrace() +{ + UINT32 iSize = TraceFileSize; + + // Sets path to store files + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_TRACE_LOCATION, (void*)TracePath, sizeof(TracePath)); + + if (stsResult == PCAN_ERROR_OK) + { + // Sets the maximum size of a tracefile + stsResult = CAN_SetValue(PcanHandle, PCAN_TRACE_SIZE, &iSize, sizeof(UINT32)); + + if (stsResult == PCAN_ERROR_OK) + { + UINT32 config; + if (TraceFileSingle) + config = TRACE_FILE_SINGLE; // Creats one file + else + config = TRACE_FILE_SEGMENTED; // Creats more files + + // Activate overwriting existing tracefile + if (TraceFileOverwrite) + config = config | TRACE_FILE_OVERWRITE; + + // Adds date to tracefilename + if (TraceFileDate) + config = config | TRACE_FILE_DATE; + + // Adds time to tracefilename + if (TraceFileTime) + config = config | TRACE_FILE_TIME; + + // Sets the config + stsResult = CAN_SetValue(PcanHandle, PCAN_TRACE_CONFIGURE, &config, sizeof(int)); + + if (stsResult == PCAN_ERROR_OK) + return true; + } + } + ShowStatus(stsResult); + return false; +} + +bool TraceFiles::StartTrace() +{ + UINT32 iStatus = PCAN_PARAMETER_ON; + + TPCANStatus stsResult = CAN_SetValue(PcanHandle, PCAN_TRACE_STATUS, &iStatus, sizeof(UINT32)); // We activate the tracing by setting the parameter. + + if (stsResult != PCAN_ERROR_OK) + { + ShowStatus(stsResult); + return false; + } + return true; +} + +void TraceFiles::ShowConfigurationHelp() +{ + std::cout << "=========================================================================================\n"; + std::cout << "| PCAN-Basic TraceFiles Example |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "Following parameters are to be adjusted before launching, according to the hardware used |\n"; + std::cout << " |\n"; + std::cout << "* PcanHandle: Numeric value that represents the handle of the PCAN-Basic channel to use. |\n"; + std::cout << " See 'PCAN-Handle Definitions' within the documentation |\n"; + std::cout << "* IsFD: Boolean value that indicates the communication mode, CAN (false) or CAN-FD (true)|\n"; + std::cout << "* Bitrate: Numeric value that represents the BTR0/BR1 bitrate value to be used for CAN |\n"; + std::cout << " communication |\n"; + std::cout << "* BitrateFD: String value that represents the nominal/data bitrate value to be used for |\n"; + std::cout << " CAN-FD communication |\n"; + std::cout << "* TraceFileSingle: Boolean value that indicates if tracing ends after one file (true) or |\n"; + std::cout << " continues |\n"; + std::cout << "* TraceFileDate: Boolean value that indicates if the date will be added to filename |\n"; + std::cout << "* TraceFileTime: Boolean value that indicates if the time will be added to filename |\n"; + std::cout << "* TraceFileOverwrite: Boolean value that indicates if existing tracefiles should be |\n"; + std::cout << " overwritten |\n"; + std::cout << "* TraceFileSize: Numeric value that represents the size of a tracefile in meagabytes |\n"; + std::cout << "* TracePath: string value that represents a valid path to an existing directory |\n"; + std::cout << "* TimerInterval: The time, in milliseconds, to wait before trying to write a message |\n"; + std::cout << "=========================================================================================\n"; + std::cout << "\n"; +} + +void TraceFiles::ShowCurrentConfiguration() +{ + std::cout << "Parameter values used\n"; + std::cout << "----------------------\n"; + char buffer[MAX_PATH]; + FormatChannelName(PcanHandle, buffer, IsFD); + std::cout << "* PCANHandle: " << buffer << "\n"; + if (IsFD) + std::cout << "* IsFD: True\n"; + else + std::cout << "* IsFD: False\n"; + ConvertBitrateToString(Bitrate, buffer); + std::cout << "* Bitrate: " << buffer << "\n"; + std::cout << "* BitrateFD: " << BitrateFD << "\n"; + if (TraceFileSingle) + std::cout << "* TraceFileSingle: True\n"; + else + std::cout << "* TraceFileSingle: False\n"; + if (TraceFileDate) + std::cout << "* TraceFileDate: True\n"; + else + std::cout << "* TraceFileDate: False\n"; + if (TraceFileTime) + std::cout << "* TraceFileTime: True\n"; + else + std::cout << "* TraceFileTime: False\n"; + if (TraceFileOverwrite) + std::cout << "* TraceFileOverwrite: True\n"; + else + std::cout << "* TraceFileOverwrite: False\n"; + std::cout << "* TraceFileSize: " << TraceFileSize << " MB\n"; + if (TracePath == "") + std::cout << "* TracePath: (calling application path)" << "\n"; + else + std::cout << "* TracePath: " << TracePath << "\n"; + std::cout << "* TimerInterval: " << TimerInterval << "\n"; + std::cout << "\n"; +} + +void TraceFiles::ShowStatus(TPCANStatus status) +{ + std::cout << "=========================================================================================\n"; + char buffer[MAX_PATH]; + GetFormattedError(status, buffer); + std::cout << buffer << "\n"; + std::cout << "=========================================================================================\n"; +} + +void TraceFiles::FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD) +{ + TPCANDevice devDevice; + BYTE byChannel; + + // Gets the owner device and channel for a PCAN-Basic handle + if (handle < 0x100) + { + devDevice = (TPCANDevice)(handle >> 4); + byChannel = (BYTE)(handle & 0xF); + } + else + { + devDevice = (TPCANDevice)(handle >> 8); + byChannel = (BYTE)(handle & 0xFF); + } + + // Constructs the PCAN-Basic Channel name and return it + char handleBuffer[MAX_PATH]; + GetTPCANHandleName(handle, handleBuffer); + if (isFD) + sprintf_s(buffer, MAX_PATH, "%s:FD %d (%Xh)", handleBuffer, byChannel, handle); + else + sprintf_s(buffer, MAX_PATH, "%s %d (%Xh)", handleBuffer, byChannel, handle); +} + +void TraceFiles::GetTPCANHandleName(TPCANHandle handle, LPSTR buffer) +{ + strcpy_s(buffer, MAX_PATH, "PCAN_NONE"); + switch (handle) + { + case PCAN_PCIBUS1: + case PCAN_PCIBUS2: + case PCAN_PCIBUS3: + case PCAN_PCIBUS4: + case PCAN_PCIBUS5: + case PCAN_PCIBUS6: + case PCAN_PCIBUS7: + case PCAN_PCIBUS8: + case PCAN_PCIBUS9: + case PCAN_PCIBUS10: + case PCAN_PCIBUS11: + case PCAN_PCIBUS12: + case PCAN_PCIBUS13: + case PCAN_PCIBUS14: + case PCAN_PCIBUS15: + case PCAN_PCIBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_PCI"); + break; + + case PCAN_USBBUS1: + case PCAN_USBBUS2: + case PCAN_USBBUS3: + case PCAN_USBBUS4: + case PCAN_USBBUS5: + case PCAN_USBBUS6: + case PCAN_USBBUS7: + case PCAN_USBBUS8: + case PCAN_USBBUS9: + case PCAN_USBBUS10: + case PCAN_USBBUS11: + case PCAN_USBBUS12: + case PCAN_USBBUS13: + case PCAN_USBBUS14: + case PCAN_USBBUS15: + case PCAN_USBBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_USB"); + break; + + case PCAN_LANBUS1: + case PCAN_LANBUS2: + case PCAN_LANBUS3: + case PCAN_LANBUS4: + case PCAN_LANBUS5: + case PCAN_LANBUS6: + case PCAN_LANBUS7: + case PCAN_LANBUS8: + case PCAN_LANBUS9: + case PCAN_LANBUS10: + case PCAN_LANBUS11: + case PCAN_LANBUS12: + case PCAN_LANBUS13: + case PCAN_LANBUS14: + case PCAN_LANBUS15: + case PCAN_LANBUS16: + strcpy_s(buffer, MAX_PATH, "PCAN_LAN"); + break; + + default: + strcpy_s(buffer, MAX_PATH, "UNKNOWN"); + break; + } +} + +void TraceFiles::GetFormattedError(TPCANStatus error, LPSTR buffer) +{ + // Gets the text using the GetErrorText API function. If the function success, the translated error is returned. + // If it fails, a text describing the current error is returned. + if (CAN_GetErrorText(error, 0x09, buffer) != PCAN_ERROR_OK) + sprintf_s(buffer, MAX_PATH, "An error occurred. Error-code's text (%Xh) couldn't be retrieved", error); +} + +void TraceFiles::ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer) +{ + switch (bitrate) + { + case PCAN_BAUD_1M: + strcpy_s(buffer, MAX_PATH, "1 MBit/sec"); + break; + case PCAN_BAUD_800K: + strcpy_s(buffer, MAX_PATH, "800 kBit/sec"); + break; + case PCAN_BAUD_500K: + strcpy_s(buffer, MAX_PATH, "500 kBit/sec"); + break; + case PCAN_BAUD_250K: + strcpy_s(buffer, MAX_PATH, "250 kBit/sec"); + break; + case PCAN_BAUD_125K: + strcpy_s(buffer, MAX_PATH, "125 kBit/sec"); + break; + case PCAN_BAUD_100K: + strcpy_s(buffer, MAX_PATH, "100 kBit/sec"); + break; + case PCAN_BAUD_95K: + strcpy_s(buffer, MAX_PATH, "95,238 kBit/sec"); + break; + case PCAN_BAUD_83K: + strcpy_s(buffer, MAX_PATH, "83,333 kBit/sec"); + break; + case PCAN_BAUD_50K: + strcpy_s(buffer, MAX_PATH, "50 kBit/sec"); + break; + case PCAN_BAUD_47K: + strcpy_s(buffer, MAX_PATH, "47,619 kBit/sec"); + break; + case PCAN_BAUD_33K: + strcpy_s(buffer, MAX_PATH, "33,333 kBit/sec"); + break; + case PCAN_BAUD_20K: + strcpy_s(buffer, MAX_PATH, "20 kBit/sec"); + break; + case PCAN_BAUD_10K: + strcpy_s(buffer, MAX_PATH, "10 kBit/sec"); + break; + case PCAN_BAUD_5K: + strcpy_s(buffer, MAX_PATH, "5 kBit/sec"); + break; + default: + strcpy_s(buffer, MAX_PATH, "Unknown Bitrate"); + break; + } +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.h new file mode 100644 index 0000000..856db7b --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.h @@ -0,0 +1,153 @@ +#include "stdafx.h" +#include "PCANBasic.h" + +class TraceFiles +{ +private: + /// + /// Sets the PCANHandle (Hardware Channel) + /// + const TPCANHandle PcanHandle = PCAN_USBBUS1; + /// + /// Sets the desired connection mode (CAN = false / CAN-FD = true) + /// + const bool IsFD = false; + /// + /// Sets the bitrate for normal CAN devices + /// + const TPCANBaudrate Bitrate = PCAN_BAUD_500K; + /// + /// Sets the bitrate for CAN FD devices. + /// Example - Bitrate Nom: 1Mbit/s Data: 2Mbit/s: + /// "f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1" + /// + const TPCANBitrateFD BitrateFD = const_cast("f_clock_mhz=20, nom_brp=5, nom_tseg1=2, nom_tseg2=1, nom_sjw=1, data_brp=2, data_tseg1=3, data_tseg2=1, data_sjw=1"); + /// + /// Sets if trace continue after reaching maximum size for the first file + /// + const bool TraceFileSingle = true; + /// + /// Set if date will be add to filename + /// + const bool TraceFileDate = true; + /// + /// Set if time will be add to filename + /// + const bool TraceFileTime = true; + /// + /// Set if existing tracefile overwrites when a new trace session is started + /// + const bool TraceFileOverwrite = false; + /// + /// Sets the size (megabyte) of an tracefile + /// Example - 100 = 100 megabyte + /// Range between 1 and 100 + /// + const UINT32 TraceFileSize = 2; + /// + /// Sets a fully-qualified and valid path to an existing directory. In order to use the default path + /// (calling process path) an empty string must be set. + /// + LPCSTR TracePath = ""; + /// + /// Timerinterval (ms) for reading + /// + const int TimerInterval = 250; + /// + /// Thread for reading messages + /// + std::thread* m_ReadThread; + /// + /// Shows if thread run + /// + bool m_ThreadRun; + +public: + // TraceFiles constructor + // + TraceFiles(); + + // TraceFiles destructor + // + ~TraceFiles(); + +private: + /// + /// Thread function for reading messages + /// + void ThreadExecute(); + + /// + /// Reads PCAN-Basic messages + /// + void ReadMessages(); + + /// + /// Deactivates the tracing process + /// + void StopTrace(); + + /// + /// Configures the way how trace files are formatted + /// + /// Returns true if no error occurr + bool ConfigureTrace(); + + /// + /// Activates the tracing process + /// + /// Returns true if no error occurr + bool StartTrace(); + + /// + /// Shows/prints the configurable parameters for this sample and information about them + /// + void ShowConfigurationHelp(); + + /// + /// Shows/prints the configured paramters + /// + void ShowCurrentConfiguration(); + + /// + /// Shows formatted status + /// + /// Will be formatted + void ShowStatus(TPCANStatus status); + + /// + /// Gets the formatted text for a PCAN-Basic channel handle + /// + /// PCAN-Basic Handle to format + /// A string buffer for the channel name + /// If the channel is FD capable + void FormatChannelName(TPCANHandle handle, LPSTR buffer, bool isFD); + + /// + /// Gets name of a TPCANHandle + /// + /// TPCANHandle to get name + /// A string buffer for the name of the TPCANHandle (size MAX_PATH) + void GetTPCANHandleName(TPCANHandle handle, LPSTR buffer); + + /// + /// Help Function used to get an error as text + /// + /// Error code to be translated + /// A string buffer for the translated error (size MAX_PATH) + void GetFormattedError(TPCANStatus error, LPSTR buffer); + + /// + /// Convert bitrate c_short value to readable string + /// + /// Bitrate to be converted + /// A string buffer for the converted bitrate (size MAX_PATH) + void ConvertBitrateToString(TPCANBaudrate bitrate, LPSTR buffer); + + /// + /// Convert bool value to readable string value + /// + /// Value to be converted + /// A text with the converted Value + bool ConvertBoolToString(bool value); +}; diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.sln new file mode 100644 index 0000000..20e8379 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TraceFiles", "09_TraceFiles.vcxproj", "{C05963E2-DE52-489B-86DB-869657AF87BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x64.ActiveCfg = Debug|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x64.Build.0 = Debug|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x86.ActiveCfg = Debug|Win32 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x86.Build.0 = Debug|Win32 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x64.ActiveCfg = Release|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x64.Build.0 = Release|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x86.ActiveCfg = Release|Win32 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {03CF902D-4CEF-483B-A2AC-31170604E0A5} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.vcxproj b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.vcxproj new file mode 100644 index 0000000..c4eafe9 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {c05963e2-de52-489b-86db-869657af87ba} + TraceFiles + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.vcxproj.filters b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.vcxproj.filters new file mode 100644 index 0000000..56a5b5f --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/09_TraceFiles.vcxproj.filters @@ -0,0 +1,46 @@ + + + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/PCANBasic.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/PCANBasic.h new file mode 100644 index 0000000..2c7f4a8 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/PCANBasic.h @@ -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 +//////////////////////////////////////////////////////////// + + +/// +/// Initializes a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "The speed for the communication (BTR0BTR1 code)" +/// "Non-PnP: The type of hardware and operation mode" +/// "Non-PnP: The I/O address for the parallel port" +/// "Non-PnP: Interrupt number of the parallel port" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + + +/// +/// Initializes a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "The speed for the communication (FD bit rate string)" +/// 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 +/// +/// 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 +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + + +/// +/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize +/// +/// Giving the TPCANHandle value "PCAN_NONEBUS", +/// uninitialize all initialized channels +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Uninitialize( + TPCANHandle Channel); + + +/// +/// Resets the receive and transmit queues of the PCAN Channel +/// +/// +/// A reset of the CAN controller is not performed. +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Reset( + TPCANHandle Channel); + + +/// +/// Gets the current status of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetStatus( + TPCANHandle Channel); + + +/// +/// Reads a CAN message from the receive queue of a PCAN Channel +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg structure buffer to store the CAN message" +/// "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" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + + +/// +/// Reads a CAN message from the receive queue of a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD structure buffer to store the CAN message" +/// "A TPCANTimestampFD buffer to get +/// the reception time of the message. If this value is not desired, this parameter +/// should be passed as NULL" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD *TimestampBuffer); + + +/// +/// Transmits a CAN message +/// +/// "The handle of a PCAN Channel" +/// "A TPCANMsg buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + + +/// +/// Transmits a CAN message over a FD capable PCAN Channel +/// +/// "The handle of a FD capable PCAN Channel" +/// "A TPCANMsgFD buffer with the message to be sent" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + + +/// +/// Configures the reception filter. +/// +/// 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 +/// "The handle of a PCAN Channel" +/// "The lowest CAN ID to be received" +/// "The highest CAN ID to be received" +/// "Message type, Standard (11-bit identifier) or +/// Extended (29-bit identifier)" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + + +/// +/// Retrieves a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to get" +/// "Buffer for the parameter value" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Configures or sets a PCAN Channel value +/// +/// 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 handle of a PCAN Channel" +/// "The TPCANParameter parameter to set" +/// "Buffer with the value to be set" +/// "Size in bytes of the buffer" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/// +/// Returns a descriptive text of a given TPCANStatus error +/// code, in any desired language +/// +/// The current languages available for translation are: +/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), +/// Italian (0x10) and French (0x0C) +/// "A TPCANStatus error code" +/// "Indicates a 'Primary language ID'" +/// "Buffer for a null terminated char array" +/// "A TPCANStatus error code" +TPCANStatus __stdcall CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/// +/// Finds a PCAN-Basic channel that matches with the given parameters +/// +/// A comma separated string contained pairs of +/// parameter-name/value to be matched within a PCAN-Basic channel +/// Buffer for returning the PCAN-Basic channel, +/// when found +/// A TPCANStatus error code +TPCANStatus __stdcall CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/RunExample.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/RunExample.cpp new file mode 100644 index 0000000..986f04f --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/RunExample.cpp @@ -0,0 +1,6 @@ +#include "09_TraceFiles.h" + +int main() +{ + TraceFiles start; +} \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/lib/x64/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/lib/x64/PCANBasic.lib new file mode 100644 index 0000000..2df8f1c Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/lib/x64/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/lib/x86/PCANBasic.lib b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/lib/x86/PCANBasic.lib new file mode 100644 index 0000000..7320f2b Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/lib/x86/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/stdafx.cpp b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/stdafx.cpp new file mode 100644 index 0000000..aa558e2 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : source file that includes just the standard includes +// PCANBasicExample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/stdafx.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/stdafx.h new file mode 100644 index 0000000..424a605 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/stdafx.h @@ -0,0 +1,11 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once +#include +#include +#include +#include +#include +#include "targetver.h" \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/targetver.h b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/targetver.h new file mode 100644 index 0000000..3d779e1 --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/09_TraceFiles/targetver.h @@ -0,0 +1,25 @@ +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif + diff --git a/PCAN API/PCAN-Basic API/Samples/NativeC++/PCANBasicSamples.sln b/PCAN API/PCAN-Basic API/Samples/NativeC++/PCANBasicSamples.sln new file mode 100644 index 0000000..c1e593c --- /dev/null +++ b/PCAN API/PCAN-Basic API/Samples/NativeC++/PCANBasicSamples.sln @@ -0,0 +1,91 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31424.327 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "01_LookUpChannel", "01_LookUpChannel\01_LookUpChannel.vcxproj", "{DE08AE69-04BD-43EA-8602-B6D5528D690B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "02_GetSetParameter", "02_GetSetParameter\02_GetSetParameter.vcxproj", "{4333360A-2706-409C-8FE5-018B189219F6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "03_ManualRead", "03_ManualRead\03_ManualRead.vcxproj", "{AE40008D-A958-4A5A-B6A2-5D941D79EF1D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "04_ManualWrite", "04_ManualWrite\04_ManualWrite.vcxproj", "{0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "07_ThreadRead", "07_ThreadRead\07_ThreadRead.vcxproj", "{38F5A9E9-F98B-40CC-B026-B63405CFCF09}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "08_EventDrivenRead", "08_EventDrivenRead\08_EventDrivenRead.vcxproj", "{67AEB664-38BC-45D0-A90F-3C98FEDCA668}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "09_TraceFiles", "09_TraceFiles\09_TraceFiles.vcxproj", "{C05963E2-DE52-489B-86DB-869657AF87BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x64.ActiveCfg = Debug|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x64.Build.0 = Debug|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x86.ActiveCfg = Debug|Win32 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Debug|x86.Build.0 = Debug|Win32 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x64.ActiveCfg = Release|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x64.Build.0 = Release|x64 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x86.ActiveCfg = Release|Win32 + {DE08AE69-04BD-43EA-8602-B6D5528D690B}.Release|x86.Build.0 = Release|Win32 + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x64.ActiveCfg = Debug|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x64.Build.0 = Debug|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x86.ActiveCfg = Debug|Win32 + {4333360A-2706-409C-8FE5-018B189219F6}.Debug|x86.Build.0 = Debug|Win32 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x64.ActiveCfg = Release|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x64.Build.0 = Release|x64 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x86.ActiveCfg = Release|Win32 + {4333360A-2706-409C-8FE5-018B189219F6}.Release|x86.Build.0 = Release|Win32 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x64.ActiveCfg = Debug|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x64.Build.0 = Debug|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x86.ActiveCfg = Debug|Win32 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Debug|x86.Build.0 = Debug|Win32 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x64.ActiveCfg = Release|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x64.Build.0 = Release|x64 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x86.ActiveCfg = Release|Win32 + {AE40008D-A958-4A5A-B6A2-5D941D79EF1D}.Release|x86.Build.0 = Release|Win32 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x64.ActiveCfg = Debug|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x64.Build.0 = Debug|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x86.ActiveCfg = Debug|Win32 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Debug|x86.Build.0 = Debug|Win32 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x64.ActiveCfg = Release|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x64.Build.0 = Release|x64 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x86.ActiveCfg = Release|Win32 + {0B959A9F-F86F-4EE0-A45B-9FC1F6F89A0F}.Release|x86.Build.0 = Release|Win32 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x64.ActiveCfg = Debug|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x64.Build.0 = Debug|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x86.ActiveCfg = Debug|Win32 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Debug|x86.Build.0 = Debug|Win32 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x64.ActiveCfg = Release|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x64.Build.0 = Release|x64 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x86.ActiveCfg = Release|Win32 + {38F5A9E9-F98B-40CC-B026-B63405CFCF09}.Release|x86.Build.0 = Release|Win32 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x64.ActiveCfg = Debug|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x64.Build.0 = Debug|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x86.ActiveCfg = Debug|Win32 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Debug|x86.Build.0 = Debug|Win32 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x64.ActiveCfg = Release|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x64.Build.0 = Release|x64 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x86.ActiveCfg = Release|Win32 + {67AEB664-38BC-45D0-A90F-3C98FEDCA668}.Release|x86.Build.0 = Release|Win32 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x64.ActiveCfg = Debug|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x64.Build.0 = Debug|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x86.ActiveCfg = Debug|Win32 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Debug|x86.Build.0 = Debug|Win32 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x64.ActiveCfg = Release|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x64.Build.0 = Release|x64 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x86.ActiveCfg = Release|Win32 + {C05963E2-DE52-489B-86DB-869657AF87BA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C08FDF29-E6DC-44DC-9342-0A29863FEC52} + EndGlobalSection +EndGlobal diff --git a/PCAN API/PCAN-Basic API/Samples/Samples.zip b/PCAN API/PCAN-Basic API/Samples/Samples.zip new file mode 100644 index 0000000..2461e56 Binary files /dev/null and b/PCAN API/PCAN-Basic API/Samples/Samples.zip differ diff --git a/PCAN API/PCAN-Basic API/history_4.6.2.753.txt b/PCAN API/PCAN-Basic API/history_4.6.2.753.txt new file mode 100644 index 0000000..4caecc3 --- /dev/null +++ b/PCAN API/PCAN-Basic API/history_4.6.2.753.txt @@ -0,0 +1,11 @@ +4.6.2.753 / 2022-10-21 +- readMe/LiesMich files adjustments +- Adjustment to the resource file due to 32/64-bit +- Online documentation adjustment: link to "Versions" was not disabled (this will not be published). + +4.6.2.740 / 2022-09-29 +- Ticket #1629: .NET Beispiele konnten die Device-ID 0xFFFFFFFF nicht lesen. + +4.6.2.736 / 2022-09-23 +- PCAN-Basic.NET release +- ARM64 Libraries \ No newline at end of file diff --git a/PCAN API/PCAN-Basic API/x64/PCANBasic.dll b/PCAN API/PCAN-Basic API/x64/PCANBasic.dll new file mode 100644 index 0000000..ac33f53 Binary files /dev/null and b/PCAN API/PCAN-Basic API/x64/PCANBasic.dll differ diff --git a/PCAN API/PCAN-Basic API/x64/PCANBasicExample.exe b/PCAN API/PCAN-Basic API/x64/PCANBasicExample.exe new file mode 100644 index 0000000..0e22e7a Binary files /dev/null and b/PCAN API/PCAN-Basic API/x64/PCANBasicExample.exe differ diff --git a/PCAN API/PCAN-Basic API/x64/VC_LIB/PCANBasic.lib b/PCAN API/PCAN-Basic API/x64/VC_LIB/PCANBasic.lib new file mode 100644 index 0000000..d520adc Binary files /dev/null and b/PCAN API/PCAN-Basic API/x64/VC_LIB/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/x86/BB_LIB/PCANBasic.lib b/PCAN API/PCAN-Basic API/x86/BB_LIB/PCANBasic.lib new file mode 100644 index 0000000..148c59e Binary files /dev/null and b/PCAN API/PCAN-Basic API/x86/BB_LIB/PCANBasic.lib differ diff --git a/PCAN API/PCAN-Basic API/x86/PCANBasic.dll b/PCAN API/PCAN-Basic API/x86/PCANBasic.dll new file mode 100644 index 0000000..54d4a43 Binary files /dev/null and b/PCAN API/PCAN-Basic API/x86/PCANBasic.dll differ diff --git a/PCAN API/PCAN-Basic API/x86/PCANBasicExample.exe b/PCAN API/PCAN-Basic API/x86/PCANBasicExample.exe new file mode 100644 index 0000000..1585543 Binary files /dev/null and b/PCAN API/PCAN-Basic API/x86/PCANBasicExample.exe differ diff --git a/PCAN API/PCAN-Basic API/x86/VC_LIB/PCANBasic.lib b/PCAN API/PCAN-Basic API/x86/VC_LIB/PCANBasic.lib new file mode 100644 index 0000000..ae482c9 Binary files /dev/null and b/PCAN API/PCAN-Basic API/x86/VC_LIB/PCANBasic.lib differ