' PCAN-ISO-TP_2016.vb
'
' ~~~~~~~~~~~~
'
' PCAN-ISO-TP API
'
' ~~~~~~~~~~~~
'
' ------------------------------------------------------------------
' Author : Fabrice Vergnaud
' Last changed by: $Author: Fabrice $
' Last changed date: $Date: 2023-03-23 11:37:15 +0100 (Thu, 23 Mar 2023) $
'
' Language: VB.Net
' ------------------------------------------------------------------
'
' Copyright (C) 2020 PEAK-System Technik GmbH, Darmstadt
' more Info at http:''www.peak-system.com
'
' To use PCAN-ISO-TP_2004 and PCAN-ISO-TP_2016 together: do define PCANTP_API_COMPATIBILITY_ISO_2004"
' #Const PCANTP_API_COMPATIBILITY_ISO_2004 = 1
Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Imports Peak.Can.Basic
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Types definition
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports cantp_bitrate = System.String ' Represents a PCAN-FD bit rate String
Imports cantp_timestamp = System.UInt64 ' Timestamp
Imports cantp_pcanstatus = System.UInt32 ' Represents the PCAN error and status codes
' Reserved extra information
Imports cantp_msginfo_flag = System.UInt32
Imports cantp_msginfo_extra = System.UIntPtr
Imports cantp_isotp_info = System.UIntPtr
Namespace Peak.Can.IsoTp
#Region "Enumerations"
'''
''' Represents currently defined And supported PCANTP handle (a.k.a. channels)
'''
Public Enum cantp_handle As UInt32
'''
''' Undefined/default value for a PCAN bus
'''
PCANTP_HANDLE_NONEBUS = PCANBasic.PCAN_NONEBUS
'''
''' PCAN-ISA interface, channel 1
'''
PCANTP_HANDLE_ISABUS1 = PCANBasic.PCAN_ISABUS1
'''
''' PCAN-ISA interface, channel 2
'''
PCANTP_HANDLE_ISABUS2 = PCANBasic.PCAN_ISABUS2
'''
''' PCAN-ISA interface, channel 3
'''
PCANTP_HANDLE_ISABUS3 = PCANBasic.PCAN_ISABUS3
'''
''' PCAN-ISA interface, channel 4
'''
PCANTP_HANDLE_ISABUS4 = PCANBasic.PCAN_ISABUS4
'''
''' PCAN-ISA interface, channel 5
'''
PCANTP_HANDLE_ISABUS5 = PCANBasic.PCAN_ISABUS5
'''
''' PCAN-ISA interface, channel 6
'''
PCANTP_HANDLE_ISABUS6 = PCANBasic.PCAN_ISABUS6
'''
''' PCAN-ISA interface, channel 7
'''
PCANTP_HANDLE_ISABUS7 = PCANBasic.PCAN_ISABUS7
'''
''' PCAN-ISA interface, channel 8
'''
PCANTP_HANDLE_ISABUS8 = PCANBasic.PCAN_ISABUS8
'''
''' PCAN-Dongle/LPT interface, channel 1
'''
PCANTP_HANDLE_DNGBUS1 = PCANBasic.PCAN_DNGBUS1
'''
''' PCAN-PCI interface, channel 1
'''
PCANTP_HANDLE_PCIBUS1 = PCANBasic.PCAN_PCIBUS1
'''
''' PCAN-PCI interface, channel 2
'''
PCANTP_HANDLE_PCIBUS2 = PCANBasic.PCAN_PCIBUS2
'''
''' PCAN-PCI interface, channel 3
'''
PCANTP_HANDLE_PCIBUS3 = PCANBasic.PCAN_PCIBUS3
'''
''' PCAN-PCI interface, channel 4
'''
PCANTP_HANDLE_PCIBUS4 = PCANBasic.PCAN_PCIBUS4
'''
''' PCAN-PCI interface, channel 5
'''
PCANTP_HANDLE_PCIBUS5 = PCANBasic.PCAN_PCIBUS5
'''
''' PCAN-PCI interface, channel 6
'''
PCANTP_HANDLE_PCIBUS6 = PCANBasic.PCAN_PCIBUS6
'''
''' PCAN-PCI interface, channel 7
'''
PCANTP_HANDLE_PCIBUS7 = PCANBasic.PCAN_PCIBUS7
'''
''' PCAN-PCI interface, channel 8
'''
PCANTP_HANDLE_PCIBUS8 = PCANBasic.PCAN_PCIBUS8
'''
''' PCAN-PCI interface, channel 9
'''
PCANTP_HANDLE_PCIBUS9 = PCANBasic.PCAN_PCIBUS9
'''
''' PCAN-PCI interface, channel 10
'''
PCANTP_HANDLE_PCIBUS10 = PCANBasic.PCAN_PCIBUS10
'''
''' PCAN-PCI interface, channel 11
'''
PCANTP_HANDLE_PCIBUS11 = PCANBasic.PCAN_PCIBUS11
'''
''' PCAN-PCI interface, channel 12
'''
PCANTP_HANDLE_PCIBUS12 = PCANBasic.PCAN_PCIBUS12
'''
''' PCAN-PCI interface, channel 13
'''
PCANTP_HANDLE_PCIBUS13 = PCANBasic.PCAN_PCIBUS13
'''
''' PCAN-PCI interface, channel 14
'''
PCANTP_HANDLE_PCIBUS14 = PCANBasic.PCAN_PCIBUS14
'''
''' PCAN-PCI interface, channel 15
'''
PCANTP_HANDLE_PCIBUS15 = PCANBasic.PCAN_PCIBUS15
'''
''' PCAN-PCI interface, channel 16
'''
PCANTP_HANDLE_PCIBUS16 = PCANBasic.PCAN_PCIBUS16
'''
''' PCAN-USB interface, channel 1
'''
PCANTP_HANDLE_USBBUS1 = PCANBasic.PCAN_USBBUS1
'''
''' PCAN-USB interface, channel 2
'''
PCANTP_HANDLE_USBBUS2 = PCANBasic.PCAN_USBBUS2
'''
''' PCAN-USB interface, channel 3
'''
PCANTP_HANDLE_USBBUS3 = PCANBasic.PCAN_USBBUS3
'''
''' PCAN-USB interface, channel 4
'''
PCANTP_HANDLE_USBBUS4 = PCANBasic.PCAN_USBBUS4
'''
''' PCAN-USB interface, channel 5
'''
PCANTP_HANDLE_USBBUS5 = PCANBasic.PCAN_USBBUS5
'''
''' PCAN-USB interface, channel 6
'''
PCANTP_HANDLE_USBBUS6 = PCANBasic.PCAN_USBBUS6
'''
''' PCAN-USB interface, channel 7
'''
PCANTP_HANDLE_USBBUS7 = PCANBasic.PCAN_USBBUS7
'''
''' PCAN-USB interface, channel 8
'''
PCANTP_HANDLE_USBBUS8 = PCANBasic.PCAN_USBBUS8
'''
''' PCAN-USB interface, channel 9
'''
PCANTP_HANDLE_USBBUS9 = PCANBasic.PCAN_USBBUS9
'''
''' PCAN-USB interface, channel 10
'''
PCANTP_HANDLE_USBBUS10 = PCANBasic.PCAN_USBBUS10
'''
''' PCAN-USB interface, channel 11
'''
PCANTP_HANDLE_USBBUS11 = PCANBasic.PCAN_USBBUS11
'''
''' PCAN-USB interface, channel 12
'''
PCANTP_HANDLE_USBBUS12 = PCANBasic.PCAN_USBBUS12
'''
''' PCAN-USB interface, channel 13
'''
PCANTP_HANDLE_USBBUS13 = PCANBasic.PCAN_USBBUS13
'''
''' PCAN-USB interface, channel 14
'''
PCANTP_HANDLE_USBBUS14 = PCANBasic.PCAN_USBBUS14
'''
''' PCAN-USB interface, channel 15
'''
PCANTP_HANDLE_USBBUS15 = PCANBasic.PCAN_USBBUS15
'''
''' PCAN-USB interface, channel 16
'''
PCANTP_HANDLE_USBBUS16 = PCANBasic.PCAN_USBBUS16
'''
''' PCAN-PC Card interface, channel 1
'''
PCANTP_HANDLE_PCCBUS1 = PCANBasic.PCAN_PCCBUS1
'''
''' PCAN-PC Card interface, channel 2
'''
PCANTP_HANDLE_PCCBUS2 = PCANBasic.PCAN_PCCBUS2
'''
''' PCAN-LAN interface, channel 1
'''
PCANTP_HANDLE_LANBUS1 = PCANBasic.PCAN_LANBUS1
'''
''' PCAN-LAN interface, channel 2
'''
PCANTP_HANDLE_LANBUS2 = PCANBasic.PCAN_LANBUS2
'''
''' PCAN-LAN interface, channel 3
'''
PCANTP_HANDLE_LANBUS3 = PCANBasic.PCAN_LANBUS3
'''
''' PCAN-LAN interface, channel 4
'''
PCANTP_HANDLE_LANBUS4 = PCANBasic.PCAN_LANBUS4
'''
''' PCAN-LAN interface, channel 5
'''
PCANTP_HANDLE_LANBUS5 = PCANBasic.PCAN_LANBUS5
'''
''' PCAN-LAN interface, channel 6
'''
PCANTP_HANDLE_LANBUS6 = PCANBasic.PCAN_LANBUS6
'''
''' PCAN-LAN interface, channel 7
'''
PCANTP_HANDLE_LANBUS7 = PCANBasic.PCAN_LANBUS7
'''
''' PCAN-LAN interface, channel 8
'''
PCANTP_HANDLE_LANBUS8 = PCANBasic.PCAN_LANBUS8
'''
''' PCAN-LAN interface, channel 9
'''
PCANTP_HANDLE_LANBUS9 = PCANBasic.PCAN_LANBUS9
'''
''' PCAN-LAN interface, channel 10
'''
PCANTP_HANDLE_LANBUS10 = PCANBasic.PCAN_LANBUS10
'''
''' PCAN-LAN interface, channel 11
'''
PCANTP_HANDLE_LANBUS11 = PCANBasic.PCAN_LANBUS11
'''
''' PCAN-LAN interface, channel 12
'''
PCANTP_HANDLE_LANBUS12 = PCANBasic.PCAN_LANBUS12
'''
''' PCAN-LAN interface, channel 13
'''
PCANTP_HANDLE_LANBUS13 = PCANBasic.PCAN_LANBUS13
'''
''' PCAN-LAN interface, channel 14
'''
PCANTP_HANDLE_LANBUS14 = PCANBasic.PCAN_LANBUS14
'''
''' PCAN-LAN interface, channel 15
'''
PCANTP_HANDLE_LANBUS15 = PCANBasic.PCAN_LANBUS15
'''
''' PCAN-LAN interface, channel 16
'''
PCANTP_HANDLE_LANBUS16 = PCANBasic.PCAN_LANBUS16
End Enum
'''
''' Represents the baudrate register for the PCANTP channel
'''
Public Enum cantp_baudrate : UInt32
'''
''' Channel Baudrate 1 MBit/s
'''
PCANTP_BAUDRATE_1M = TPCANBaudrate.PCAN_BAUD_1M
'''
''' Channel Baudrate 800 kBit/s
'''
PCANTP_BAUDRATE_800K = TPCANBaudrate.PCAN_BAUD_800K
'''
''' Channel Baudrate 500 kBit/s
'''
PCANTP_BAUDRATE_500K = TPCANBaudrate.PCAN_BAUD_500K
'''
''' Channel Baudrate 250 kBit/s
'''
PCANTP_BAUDRATE_250K = TPCANBaudrate.PCAN_BAUD_250K
'''
''' Channel Baudrate 125 kBit/s
'''
PCANTP_BAUDRATE_125K = TPCANBaudrate.PCAN_BAUD_125K
'''
''' Channel Baudrate 100 kBit/s
'''
PCANTP_BAUDRATE_100K = TPCANBaudrate.PCAN_BAUD_100K
'''
''' Channel Baudrate 95,238 kBit/s
'''
PCANTP_BAUDRATE_95K = TPCANBaudrate.PCAN_BAUD_95K
'''
''' Channel Baudrate 83,333 kBit/s
'''
PCANTP_BAUDRATE_83K = TPCANBaudrate.PCAN_BAUD_83K
'''
''' Channel Baudrate 50 kBit/s
'''
PCANTP_BAUDRATE_50K = TPCANBaudrate.PCAN_BAUD_50K
'''
''' Channel Baudrate 47,619 kBit/s
'''
PCANTP_BAUDRATE_47K = TPCANBaudrate.PCAN_BAUD_47K
'''
''' Channel Baudrate 33,333 kBit/s
'''
PCANTP_BAUDRATE_33K = TPCANBaudrate.PCAN_BAUD_33K
'''
''' Channel Baudrate 20 kBit/s
'''
PCANTP_BAUDRATE_20K = TPCANBaudrate.PCAN_BAUD_20K
'''
''' Channel Baudrate 10 kBit/s
'''
PCANTP_BAUDRATE_10K = TPCANBaudrate.PCAN_BAUD_10K
'''
''' Channel Baudrate 5 kBit/s
'''
PCANTP_BAUDRATE_5K = TPCANBaudrate.PCAN_BAUD_5K
End Enum
'''
''' Type of PCAN (non plug-n-play) hardware
'''
Public Enum cantp_hwtype : UInt32
'''
''' PCAN-ISA 82C200
'''
PCANTP_HWTYPE_ISA = TPCANType.PCAN_TYPE_ISA
'''
''' PCAN-ISA SJA1000
'''
PCANTP_HWTYPE_ISA_SJA = TPCANType.PCAN_TYPE_ISA_SJA
'''
''' PHYTEC ISA
'''
PCANTP_HWTYPE_ISA_PHYTEC = TPCANType.PCAN_TYPE_ISA_PHYTEC
'''
''' PCAN-Dongle 82C200
'''
PCANTP_HWTYPE_DNG = TPCANType.PCAN_TYPE_DNG
'''
''' PCAN-Dongle EPP 82C200
'''
PCANTP_HWTYPE_DNG_EPP = TPCANType.PCAN_TYPE_DNG_EPP
'''
''' PCAN-Dongle SJA1000
'''
PCANTP_HWTYPE_DNG_SJA = TPCANType.PCAN_TYPE_DNG_SJA
'''
''' PCAN-Dongle EPP SJA1000
'''
PCANTP_HWTYPE_DNG_SJA_EPP = TPCANType.PCAN_TYPE_DNG_SJA_EPP
End Enum
'''
''' PCAN devices
'''
Public Enum cantp_device As UInt32
'''
''' Undefined, unknown Or Not selected PCAN device value
'''
PCANTP_DEVICE_NONE = TPCANDevice.PCAN_NONE
'''
''' PCAN Non-PlugAndPlay devices. Not USED WITHIN PCAN-Basic API
'''
PCANTP_DEVICE_PEAKCAN = TPCANDevice.PCAN_PEAKCAN
'''
''' PCAN-ISA, PCAN-PC/104, And PCAN-PC/104-Plus
'''
PCANTP_DEVICE_ISA = TPCANDevice.PCAN_ISA
'''
''' PCAN-Dongle
'''
PCANTP_DEVICE_DNG = TPCANDevice.PCAN_DNG
'''
''' PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, And PCAN-PCI Express
'''
PCANTP_DEVICE_PCI = TPCANDevice.PCAN_PCI
'''
''' PCAN-USB And PCAN-USB Pro
'''
PCANTP_DEVICE_USB = TPCANDevice.PCAN_USB
'''
''' PCAN-PC Card
'''
PCANTP_DEVICE_PCC = TPCANDevice.PCAN_PCC
'''
''' PCAN Virtual hardware. Not USED WITHIN PCAN-Basic API
'''
PCANTP_DEVICE_VIRTUAL = TPCANDevice.PCAN_VIRTUAL
'''
''' PCAN Gateway devices
'''
PCANTP_DEVICE_LAN = TPCANDevice.PCAN_LAN
End Enum
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Enums definition for ISO-TP API
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
''' Represents each group of errors a status can hold
'''
Public Enum cantp_statustype As UInt32
'''
''' no error
'''
PCANTP_STATUSTYPE_OK = &H0
'''
''' general error
'''
PCANTP_STATUSTYPE_ERR = &H1
'''
''' bus status
'''
PCANTP_STATUSTYPE_BUS = &H2
'''
''' network status
'''
PCANTP_STATUSTYPE_NET = &H4
'''
''' extra information
'''
PCANTP_STATUSTYPE_INFO = &H8
'''
''' encapsulated PCAN-Basic status
'''
PCANTP_STATUSTYPE_PCAN = &H10
End Enum
'''
''' Represents the network result of the communication of an ISO-TP message (used in cantp_status).
'''
Public Enum cantp_netstatus As UInt32
' ISO-TP network errors:
'''
''' No network error
'''
PCANTP_NETSTATUS_OK = &H0
'''
''' timeout occured between 2 frames transmission (sender And receiver side)
'''
PCANTP_NETSTATUS_TIMEOUT_A = &H1
'''
''' sender side timeout while waiting for flow control frame
'''
PCANTP_NETSTATUS_TIMEOUT_Bs = &H2
'''
''' receiver side timeout while waiting for consecutive frame
'''
PCANTP_NETSTATUS_TIMEOUT_Cr = &H3
'''
''' unexpected sequence number
'''
PCANTP_NETSTATUS_WRONG_SN = &H4
'''
''' invalid Or unknown FlowStatus
'''
PCANTP_NETSTATUS_INVALID_FS = &H5
'''
''' unexpected protocol data unit
'''
PCANTP_NETSTATUS_UNEXP_PDU = &H6
'''
''' reception of flow control WAIT frame that exceeds the maximum counter defined by PCANTP_PARAMETER_WFT_MAX
'''
PCANTP_NETSTATUS_WFT_OVRN = &H7
'''
''' buffer on the receiver side cannot store the data length (server side only)
'''
PCANTP_NETSTATUS_BUFFER_OVFLW = &H8
'''
''' general error
'''
PCANTP_NETSTATUS_ERROR = &H9
'''
''' message was invalid And ignored
'''
PCANTP_NETSTATUS_IGNORED = &HA
'''
''' sender side timeout while transmitting
'''
PCANTP_NETSTATUS_TIMEOUT_As = &HB
'''
''' receiver side timeout while transmitting
'''
PCANTP_NETSTATUS_TIMEOUT_Ar = &HC
' NON ISO-TP related network results
'''
''' transmit queue Is full (failed too many times)
'''
PCANTP_NETSTATUS_XMT_FULL = &HD
'''
''' CAN bus error
'''
PCANTP_NETSTATUS_BUS_ERROR = &HE
'''
''' memory allocation error
'''
PCANTP_NETSTATUS_NO_MEMORY = &HF
End Enum
'''
''' Represents the status of a CAN bus (used in cantp_status).
'''
Public Enum cantp_busstatus As UInt32
'''
''' Bus Is in active state
'''
PCANTP_BUSSTATUS_OK = &H0
'''
''' Bus error: an error counter reached the 'light' limit
'''
PCANTP_BUSSTATUS_LIGHT = &H1
'''
''' Bus error: an error counter reached the 'heavy' limit
'''
PCANTP_BUSSTATUS_HEAVY = &H2
'''
''' Bus error: an error counter reached the 'warning/heavy' limit
'''
PCANTP_BUSSTATUS_WARNING = PCANTP_BUSSTATUS_HEAVY
'''
''' Bus error: the CAN controller Is Error passive
'''
PCANTP_BUSSTATUS_PASSIVE = &H4
'''
''' Bus error: the CAN controller Is In bus-off state
'''
PCANTP_BUSSTATUS_OFF = &H8
'''
''' Mask for all bus errors
'''
PCANTP_BUSSTATUS_ANY = PCANTP_BUSSTATUS_LIGHT Or PCANTP_BUSSTATUS_HEAVY Or PCANTP_BUSSTATUS_WARNING Or PCANTP_BUSSTATUS_PASSIVE Or PCANTP_BUSSTATUS_OFF
End Enum
'''
''' Represents an general error (used in cantp_status).
'''
Public Enum cantp_errstatus As UInt32
'''
''' No error
'''
PCANTP_ERRSTATUS_OK = &H0
'''
''' Not Initialized
'''
PCANTP_ERRSTATUS_NOT_INITIALIZED = &H1
'''
''' Already Initialized
'''
PCANTP_ERRSTATUS_ALREADY_INITIALIZED = &H2
'''
''' Could Not obtain memory
'''
PCANTP_ERRSTATUS_NO_MEMORY = &H3
'''
''' Input buffer overflow
'''
PCANTP_ERRSTATUS_OVERFLOW = &H4
'''
''' No Message available
'''
PCANTP_ERRSTATUS_NO_MESSAGE = &H7
'''
''' Parameter has an invalid or unexpected type
'''
PCANTP_ERRSTATUS_PARAM_INVALID_TYPE = &H8
'''
''' Parameter has an invalid value
'''
PCANTP_ERRSTATUS_PARAM_INVALID_VALUE = &H9
'''
''' PCANTP mapping Not initialized
'''
PCANTP_ERRSTATUS_MAPPING_NOT_INITIALIZED = &HD
'''
''' PCANTP mapping parameters are invalid
'''
PCANTP_ERRSTATUS_MAPPING_INVALID = &HE
'''
''' PCANTP mapping already defined
'''
PCANTP_ERRSTATUS_MAPPING_ALREADY_INITIALIZED = &HF
'''
'''
'''
PCANTP_ERRSTATUS_PARAM_BUFFER_TOO_SMALL = &H10
'''
''' Tx queue Is full
'''
PCANTP_ERRSTATUS_QUEUE_TX_FULL = &H11
'''
''' Failed to get an access to the internal lock
'''
PCANTP_ERRSTATUS_LOCK_TIMEOUT = &H12
'''
''' Invalid cantp_handle
'''
PCANTP_ERRSTATUS_INVALID_HANDLE = &H13
'''
''' unknown/generic error
'''
PCANTP_ERRSTATUS_UNKNOWN = &HFF
End Enum
'''
''' Represents additional status information (used in cantp_status).
'''
Public Enum cantp_infostatus As UInt32
'''
''' no extra information
'''
PCANTP_INFOSTATUS_OK = &H0
'''
''' input was modified by the API
'''
PCANTP_INFOSTATUS_CAUTION_INPUT_MODIFIED = &H1
'''
''' DLC value was modified by the API
'''
PCANTP_INFOSTATUS_CAUTION_DLC_MODIFIED = &H2
'''
''' Data Length value was modified by the API
'''
PCANTP_INFOSTATUS_CAUTION_DATA_LENGTH_MODIFIED = &H4
'''
''' FD related flags value were modified by the API
'''
PCANTP_INFOSTATUS_CAUTION_FD_FLAG_MODIFIED = &H8
'''
''' Message receive queue Is full (oldest messages may be lost)
'''
PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_FULL = &H10
'''
''' Buffer Is used by another thread Or API
'''
PCANTP_INFOSTATUS_CAUTION_BUFFER_IN_USE = &H20
'''
''' Internal queue read too late (a frame was lost)
'''
PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_OVERRUN = &H30
End Enum
'''
''' Defines constants used by the next enum: cantp_status
'''
Public Enum cantp_status_offset As Byte
PCANTP_STATUS_OFFSET_BUS = 8
PCANTP_STATUS_OFFSET_NET = (PCANTP_STATUS_OFFSET_BUS + 5)
PCANTP_STATUS_OFFSET_INFO = (PCANTP_STATUS_OFFSET_NET + 5)
End Enum
'''
''' Represent the PCANTP error And status codes .
'''
''' Bits information:
''' 32| 28| 24| 20| 16| 12| 8| 4| 0|
''' | | | | | | | | |
''' 0000 0000 0000 0000 0000 0000 0000 0000
''' | | | | | [0000 0000] => PCAN-ISO-TP API errors
''' | | | | | [0 0000] => CAN Bus status
''' | | | | [00 000] => Networking message status
''' | | [0000 00] => API extra information
''' |[000 0000] => Reserved
''' [0] => PCANBasic error flag (overrides the meaning of all bits)
'''
Public Enum cantp_status As UInt32
PCANTP_STATUS_OK = cantp_errstatus.PCANTP_ERRSTATUS_OK
PCANTP_STATUS_NOT_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_NOT_INITIALIZED
PCANTP_STATUS_ALREADY_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_ALREADY_INITIALIZED
PCANTP_STATUS_NO_MEMORY = cantp_errstatus.PCANTP_ERRSTATUS_NO_MEMORY
PCANTP_STATUS_OVERFLOW = cantp_errstatus.PCANTP_ERRSTATUS_OVERFLOW
PCANTP_STATUS_NO_MESSAGE = cantp_errstatus.PCANTP_ERRSTATUS_NO_MESSAGE
PCANTP_STATUS_PARAM_INVALID_TYPE = cantp_errstatus.PCANTP_ERRSTATUS_PARAM_INVALID_TYPE
PCANTP_STATUS_PARAM_INVALID_VALUE = cantp_errstatus.PCANTP_ERRSTATUS_PARAM_INVALID_VALUE
PCANTP_STATUS_MAPPING_NOT_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_MAPPING_NOT_INITIALIZED
PCANTP_STATUS_MAPPING_INVALID = cantp_errstatus.PCANTP_ERRSTATUS_MAPPING_INVALID
PCANTP_STATUS_MAPPING_ALREADY_INITIALIZED = cantp_errstatus.PCANTP_ERRSTATUS_MAPPING_ALREADY_INITIALIZED
PCANTP_STATUS_PARAM_BUFFER_TOO_SMALL = cantp_errstatus.PCANTP_ERRSTATUS_PARAM_BUFFER_TOO_SMALL
PCANTP_STATUS_QUEUE_TX_FULL = cantp_errstatus.PCANTP_ERRSTATUS_QUEUE_TX_FULL
PCANTP_STATUS_LOCK_TIMEOUT = cantp_errstatus.PCANTP_ERRSTATUS_LOCK_TIMEOUT
PCANTP_STATUS_HANDLE_INVALID = cantp_errstatus.PCANTP_ERRSTATUS_INVALID_HANDLE
PCANTP_STATUS_UNKNOWN = cantp_errstatus.PCANTP_ERRSTATUS_UNKNOWN
#Region "Bus status flags (bits [8..11])"
'''
''' PCANTP Channel Is in BUS-LIGHT error state
'''
PCANTP_STATUS_FLAG_BUS_LIGHT = (cantp_busstatus.PCANTP_BUSSTATUS_LIGHT << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS)
'''
''' PCANTP Channel Is in BUS-HEAVY error state
'''
PCANTP_STATUS_FLAG_BUS_HEAVY = (cantp_busstatus.PCANTP_BUSSTATUS_HEAVY << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS)
'''
''' PCANTP Channel Is in BUS-HEAVY error state
'''
PCANTP_STATUS_FLAG_BUS_WARNING = PCANTP_STATUS_FLAG_BUS_HEAVY
'''
''' PCANTP Channel Is error passive state
'''
PCANTP_STATUS_FLAG_BUS_PASSIVE = (cantp_busstatus.PCANTP_BUSSTATUS_PASSIVE << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS)
'''
''' PCANTP Channel Is in BUS-OFF error state
'''
PCANTP_STATUS_FLAG_BUS_OFF = (cantp_busstatus.PCANTP_BUSSTATUS_OFF << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS)
'''
'''
'''
PCANTP_STATUS_FLAG_BUS_ANY = (cantp_busstatus.PCANTP_BUSSTATUS_ANY << cantp_status_offset.PCANTP_STATUS_OFFSET_BUS)
#End Region
#Region "Network status (bits [13..17])"
'''
''' This flag states if one of the following network errors occured with the fetched message
'''
PCANTP_STATUS_FLAG_NETWORK_RESULT = (1 << cantp_status_offset.PCANTP_STATUS_OFFSET_NET)
'''
''' timeout occured between 2 frames transmission (sender And receiver side)
'''
PCANTP_STATUS_NETWORK_TIMEOUT_A = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_A << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' sender side timeout while waiting for flow control frame
'''
PCANTP_STATUS_NETWORK_TIMEOUT_Bs = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_Bs << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' receiver side timeout while waiting for consecutive frame
'''
PCANTP_STATUS_NETWORK_TIMEOUT_Cr = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_Cr << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' unexpected sequence number
'''
PCANTP_STATUS_NETWORK_WRONG_SN = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_WRONG_SN << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' invalid Or unknown FlowStatus
'''
PCANTP_STATUS_NETWORK_INVALID_FS = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_INVALID_FS << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' unexpected protocol data unit
'''
PCANTP_STATUS_NETWORK_UNEXP_PDU = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_UNEXP_PDU << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' reception of flow control WAIT frame that exceeds the maximum counter defined by PCANTP_PARAMETER_WFT_MAX
'''
PCANTP_STATUS_NETWORK_WFT_OVRN = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_WFT_OVRN << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' buffer on the receiver side cannot store the data length (server side only)
'''
PCANTP_STATUS_NETWORK_BUFFER_OVFLW = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_BUFFER_OVFLW << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' general error
'''
PCANTP_STATUS_NETWORK_ERROR = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_ERROR << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' message was invalid And ignored
'''
PCANTP_STATUS_NETWORK_IGNORED = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_IGNORED << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
#End Region
#Region "ISO-TP extra information flags"
'''
''' Receiver side timeout while transmitting
'''
PCANTP_STATUS_NETWORK_TIMEOUT_Ar = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_Ar << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' Sender side timeout while transmitting
'''
PCANTP_STATUS_NETWORK_TIMEOUT_As = (PCANTP_STATUS_FLAG_NETWORK_RESULT Or (cantp_netstatus.PCANTP_NETSTATUS_TIMEOUT_As << (cantp_status_offset.PCANTP_STATUS_OFFSET_NET + 1)))
'''
''' input was modified
'''
PCANTP_STATUS_CAUTION_INPUT_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_INPUT_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO)
'''
''' DLC value of the input was modified
'''
PCANTP_STATUS_CAUTION_DLC_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_DLC_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO)
'''
''' Data Length value of the input was modified
'''
PCANTP_STATUS_CAUTION_DATA_LENGTH_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_DATA_LENGTH_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO)
'''
''' FD flags of the input was modified
'''
PCANTP_STATUS_CAUTION_FD_FLAG_MODIFIED = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_FD_FLAG_MODIFIED << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO)
'''
''' Receive queue Is full
'''
PCANTP_STATUS_CAUTION_RX_QUEUE_FULL = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_FULL << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO)
'''
''' Buffer Is used by another thread Or API
'''
PCANTP_STATUS_CAUTION_BUFFER_IN_USE = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_BUFFER_IN_USE << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO)
'''
''' Internal queue read too late (a frame was lost)
'''
PCANTP_STATUS_CAUTION_RX_QUEUE_OVERRUN = (cantp_infostatus.PCANTP_INFOSTATUS_CAUTION_RX_QUEUE_OVERRUN << cantp_status_offset.PCANTP_STATUS_OFFSET_INFO)
#End Region
#Region "Lower API status code: see also PCANTP_STATUS_xx macros"
'''
''' PCAN error flag, remove flag to get a usable PCAN error/status code (cf. PCANBasic API)
'''
PCANTP_STATUS_FLAG_PCAN_STATUS = &H80000000UI
#End Region
#Region "Masks To merge/retrieve different PCANTP status by type In a cantp_status"
'''
''' filter by PCANTP_STATUSTYPE_ERR type
'''
PCANTP_STATUS_MASK_ERROR = &HFFUI
'''
''' filter by PCANTP_STATUSTYPE_BUS type
'''
PCANTP_STATUS_MASK_BUS = &H1F00UI
'''
''' filter by PCANTP_STATUSTYPE_NET type
'''
PCANTP_STATUS_MASK_ISOTP_NET = &H3E000UI
'''
''' filter by PCANTP_STATUSTYPE_INFO type
'''
PCANTP_STATUS_MASK_INFO = &HFC0000UI
'''
''' filter by PCANTP_STATUSTYPE_PCAN type
'''
PCANTP_STATUS_MASK_PCAN = Not PCANTP_STATUS_FLAG_PCAN_STATUS
#End Region
End Enum
'''
''' List of parameters handled by PCAN-ISO-TP (rev. 2016)
''' Note: PCAN-Basic parameters (PCAN_PARAM_xxx) are compatible via casting.
'''
Public Enum cantp_parameter As UInt32
'''
''' PCAN-ISO-TP API version parameter
'''
PCANTP_PARAMETER_API_VERSION = &H101
'''
''' 1 BYTE data describing the condition of a channel.
'''
PCANTP_PARAMETER_CHANNEL_CONDITION = &H102
'''
''' 1 BYTE data describing the debug mode
'''
PCANTP_PARAMETER_DEBUG = &H103
'''
''' data Is pointer to a HANDLE created by CreateEvent function
'''
PCANTP_PARAMETER_RECEIVE_EVENT = &H104
'''
''' 1 BYTE data stating if unsegmented (NON-ISO-TP) CAN frames can be received
'''
PCANTP_PARAMETER_FRAME_FILTERING = &H105
'''
''' 1 BYTE data stating the default DLC to use when transmitting messages with CAN FD
'''
PCANTP_PARAMETER_CAN_TX_DL = &H106
'''
''' 1 BYTE data stating if CAN frame DLC uses padding Or Not
'''
PCANTP_PARAMETER_CAN_DATA_PADDING = &H107
'''
''' 1 BYTE data stating the value used for CAN data padding
'''
PCANTP_PARAMETER_CAN_PADDING_VALUE = &H108
'''
''' 1 BYTE data stating which revision of ISO 15765-2 to use (see PCANTP_ISO_REV_*).
'''
PCANTP_PARAMETER_ISO_REV = &H109
'''
''' 1 BYTE data stating the default priority value for normal fixed, mixed And enhanced addressing (default=6)
'''
PCANTP_PARAMETER_J1939_PRIORITY = &H10A
'''
''' 1 BYTE data stating if pending messages are displayed/hidden
'''
PCANTP_PARAMETER_MSG_PENDING = &H10B
'''
''' 1 BYTE data describing the block size parameter (BS)
'''
PCANTP_PARAMETER_BLOCK_SIZE = &H10C
'''
''' 2 BYTE data describing the transmit block size parameter (BS_TX)
'''
PCANTP_PARAMETER_BLOCK_SIZE_TX = &H10D
'''
''' 1 BYTE data describing the seperation time parameter (STmin)
'''
PCANTP_PARAMETER_SEPARATION_TIME = &H10E
'''
''' 2 BYTE data describing the transmit seperation time parameter (STmin_TX)
'''
PCANTP_PARAMETER_SEPARATION_TIME_TX = &H10F
'''
''' 4 BYTE data describing the Wait Frame Transmissions parameter.
'''
PCANTP_PARAMETER_WFT_MAX = &H110
'''
''' 4 BYTE data describing ISO-15765-2:Timeout As.
'''
PCANTP_PARAMETER_TIMEOUT_AS = &H111
'''
''' 4 BYTE data describing ISO-15765-2:Timeout Ar.
'''
PCANTP_PARAMETER_TIMEOUT_AR = &H112
'''
''' 4 BYTE data describing ISO-15765-2:Timeout Bs.
'''
PCANTP_PARAMETER_TIMEOUT_BS = &H113
'''
''' 4 BYTE data describing ISO-15765-2:Timeout Cr.
'''
PCANTP_PARAMETER_TIMEOUT_CR = &H114
'''
''' 1 BYTE data describing the tolerence to apply to all timeout as a percentage ([0..100].
'''
PCANTP_PARAMETER_TIMEOUT_TOLERANCE = &H115
'''
''' 1 BYTE data to set predefined ISO values for timeouts (see PCANTP_ISO_TIMEOUTS_*).
'''
PCANTP_PARAMETER_ISO_TIMEOUTS = &H116
'''
''' 1 BYTE data to set optimization options to improve delay between ISO-TP consecutive frames.
'''
PCANTP_PARAMETER_SELFRECEIVE_LATENCY = &H117
'''
''' 2 BYTE data describing the maximum number of messages in the Rx queue.
'''
PCANTP_PARAMETER_MAX_RX_QUEUE = &H118
'''
''' 1 BYTE data stating if messages handled by higher layer APIs are still available in this API (default=0).
'''
PCANTP_PARAMETER_KEEP_HIGHER_LAYER_MESSAGES = &H119
'''
''' 1 BYTE data stating if the white-list CAN IDs filtering mechanism Is enabled.
'''
PCANTP_PARAMETER_FILTER_CAN_ID = &H11A
'''
''' 1 BYTE data stating if the 29 bit Enhanced Diagnostic CAN identifier is supported (ISO-15765-3:2004, default is false with ISO revision 2016).
'''
PCANTP_PARAMETER_SUPPORT_29B_ENHANCED = &H11B
'''
''' 1 BYTE data stating if the 29 bit Fixed Normal addressing CAN identifier is supported (default is true).
'''
PCANTP_PARAMETER_SUPPORT_29B_FIXED_NORMAL = &H11C
'''
''' 1 BYTE data stating if the 29 bit Mixed addressing CAN identifier is supported (default is true).
'''
PCANTP_PARAMETER_SUPPORT_29B_MIXED = &H11D
'''
''' Pointer to a cantp_msg, checks if the message is valid and can be sent (ex. if a mapping is needed) and corrects input if needed.
'''
PCANTP_PARAMETER_MSG_CHECK = &H11E
'''
''' 1 BYTE data stating to clear Rx/Tx queues and CAN controller (channel is unitialized and re-initialized but settings and mappings are kept)
'''
PCANTP_PARAMETER_RESET_HARD = &H11F
'''
''' 1 BYTE data stating if network is full-duplex (default) or half-duplex
'''
PCANTP_PARAMETER_NETWORK_LAYER_DESIGN = &H120
'''
''' 1 BYTE data stating if API allows receiption PCANTP_MSGTYPE_CANINFO from lower layer APIs
'''
PCANTP_PARAMETER_ALLOW_MSGTYPE_CANINFO = &H124
'''
''' Data is a pointer to a user-defined callback triggered when a message is received.
'''
PCANTP_PARAMETER_RECEIVE_EVENT_CALLBACK = &H125
'''
''' Data is a pointer to a user-defined structure. It can be used to pass user arguments to the reception callback function.
'''
PCANTP_PARAMETER_RECEIVE_EVENT_CALLBACK_USER_CONTEXT = &H126
'''
''' PCAN hardware name parameter
'''
PCANTP_PARAMETER_HARDWARE_NAME = TPCANParameter.PCAN_HARDWARE_NAME
'''
''' PCAN-USB device identifier parameter
'''
PCANTP_PARAMETER_DEVICE_ID = TPCANParameter.PCAN_DEVICE_NUMBER
'''
''' Deprecated use PCANTP_PARAMETER_DEVICE_ID instead
'''
PCANTP_PARAMETER_DEVICE_NUMBER = TPCANParameter.PCAN_DEVICE_NUMBER
'''
''' CAN-Controller number of a PCAN-Channel
'''
PCANTP_PARAMETER_CONTROLLER_NUMBER = TPCANParameter.PCAN_CONTROLLER_NUMBER
'''
''' Capabilities of a PCAN device (FEATURE_***)
'''
PCANTP_PARAMETER_CHANNEL_FEATURES = TPCANParameter.PCAN_CHANNEL_FEATURES
End Enum
'''
''' Represents the type of a CANTP message (see field "cantp_msg.type").
'''
Public Enum cantp_msgtype As UInt32
'''
''' uninitialized message (data Is NULL)
'''
PCANTP_MSGTYPE_NONE = 0
'''
''' standard CAN frame
'''
PCANTP_MSGTYPE_CAN = 1
'''
''' CAN frame with FD support
'''
PCANTP_MSGTYPE_CANFD = 2
'''
''' ISO-TP message (ISO:15765)
'''
PCANTP_MSGTYPE_ISOTP = 4
'''
''' CAN bus information
'''
PCANTP_MSGTYPE_CANINFO = 8
'''
''' frame only: unsegmented messages
'''
PCANTP_MSGTYPE_FRAME = PCANTP_MSGTYPE_CAN Or PCANTP_MSGTYPE_CANFD
'''
''' any supported message type
'''
PCANTP_MSGTYPE_ANY = PCANTP_MSGTYPE_FRAME Or PCANTP_MSGTYPE_ISOTP Or &HFFFFFFFFUI
End Enum
'''
''' Represents the flags common to all types of cantp_msg (see field "cantp_msg.msgdata.flags").
'''
Public Enum cantp_msgflag As UInt32
'''
''' no flag
'''
PCANTP_MSGFLAG_NONE = 0
'''
''' message Is the confirmation of a transmitted message
'''
PCANTP_MSGFLAG_LOOPBACK = 1
'''
''' message Is a frame of a segmented ISO-TP message
'''
PCANTP_MSGFLAG_ISOTP_FRAME = 2
End Enum
'''
''' Represents the flags of a CAN or CAN FD frame (must be used as flags for ex. EXTENDED|FD|BRS.) (see field "cantp_msg.can_info.can_msgtype")
'''
Public Enum cantp_can_msgtype As UInt32
'''
''' The PCAN message Is a CAN Standard Frame (11-bit identifier)
'''
PCANTP_CAN_MSGTYPE_STANDARD = TPCANMessageType.PCAN_MESSAGE_STANDARD
'''
''' The PCAN message Is a CAN Remote-Transfer-Request Frame
'''
PCANTP_CAN_MSGTYPE_RTR = TPCANMessageType.PCAN_MESSAGE_RTR
'''
''' The PCAN message Is a CAN Extended Frame (29-bit identifier)
'''
PCANTP_CAN_MSGTYPE_EXTENDED = TPCANMessageType.PCAN_MESSAGE_EXTENDED
'''
''' The PCAN message represents a FD frame in terms of CiA Specs
'''
PCANTP_CAN_MSGTYPE_FD = TPCANMessageType.PCAN_MESSAGE_FD
'''
''' The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate)
'''
PCANTP_CAN_MSGTYPE_BRS = TPCANMessageType.PCAN_MESSAGE_BRS
'''
''' The PCAN message represents a FD error state indicator(CAN FD transmitter was error active)
'''
PCANTP_CAN_MSGTYPE_ESI = TPCANMessageType.PCAN_MESSAGE_ESI
'''
''' The PCAN message represents an error frame.
'''
PCANTP_CAN_MSGTYPE_ERRFRAME = TPCANMessageType.PCAN_MESSAGE_ERRFRAME
'''
''' The PCAN message represents a PCAN status message.
'''
PCANTP_CAN_MSGTYPE_STATUS = TPCANMessageType.PCAN_MESSAGE_STATUS
'''
''' Echo messages reception status within a PCAN-Channel
'''
PCANTP_CAN_MSGTYPE_ECHO = TPCANMessageType.PCAN_MESSAGE_ECHO
'''
''' Flag stating that the message is not a CAN Frame
'''
PCANTP_CAN_MSGTYPE_FLAG_INFO = (TPCANMessageType.PCAN_MESSAGE_ERRFRAME Or TPCANMessageType.PCAN_MESSAGE_STATUS)
End Enum
'''
''' Represents the type of an ISO-TP message (see field "cantp_msg.msgdata_isotp.netaddrinfo.msgtype").
'''
Public Enum cantp_isotp_msgtype As UInt32
'''
''' Unknown (non-ISO-TP) message
'''
PCANTP_ISOTP_MSGTYPE_UNKNOWN = &H0
'''
''' Diagnostic message (request Or confirmation)
'''
PCANTP_ISOTP_MSGTYPE_DIAGNOSTIC = &H1
'''
''' Remote Diagnostic message (request Or confirmation)
'''
PCANTP_ISOTP_MSGTYPE_REMOTE_DIAGNOSTIC = &H2
'''
''' Multi-Frame Message Is being received
'''
PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION_RX = &H10
'''
''' Multi-Frame Message Is being transmitted
'''
PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION_TX = &H20
'''
''' Multi-Frame Message Is being communicated (Tx Or Rx)
'''
PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION = (&H10 Or &H20)
'''
''' Mask to remove Indication flags
'''
PCANTP_ISOTP_MSGTYPE_MASK_INDICATION = &HF
End Enum
'''
''' Represents the addressing format of an ISO-TP message (see field "cantp_msg.msgdata_isotp.netaddrinfo.format").
'''
Public Enum cantp_isotp_format As UInt32
'''
''' unknown adressing format
'''
PCANTP_ISOTP_FORMAT_UNKNOWN = &HFF
'''
''' unsegmented CAN frame
'''
PCANTP_ISOTP_FORMAT_NONE = &H0
'''
''' normal adressing format from ISO 15765-2
'''
PCANTP_ISOTP_FORMAT_NORMAL = &H1
'''
''' fixed normal adressing format from ISO 15765-2
'''
PCANTP_ISOTP_FORMAT_FIXED_NORMAL = &H2
'''
''' extended adressing format from ISO 15765-2
'''
PCANTP_ISOTP_FORMAT_EXTENDED = &H3
'''
''' mixed adressing format from ISO 15765-2
'''
PCANTP_ISOTP_FORMAT_MIXED = &H4
'''
''' enhanced adressing format from ISO 15765-3
'''
PCANTP_ISOTP_FORMAT_ENHANCED = &H5
End Enum
'''
''' Represents the type of target of an ISO-TP message (see field "cantp_msg.msgdata_isotp.netaddrinfo.target_type").
'''
Public Enum cantp_isotp_addressing As UInt32
'''
''' Unknown adressing format
'''
PCANTP_ISOTP_ADDRESSING_UNKNOWN = &H0
'''
''' Physical addressing ("peer to peer")
'''
PCANTP_ISOTP_ADDRESSING_PHYSICAL = &H1
'''
''' Functional addressing ("peer to any")
'''
PCANTP_ISOTP_ADDRESSING_FUNCTIONAL = &H2
End Enum
'''
''' Represents the options of a message (mainly supported for ISO-TP message) (see field "cantp_msg.msgdata.options").
'''
Public Enum cantp_option As UInt32
'''
''' 1 BYTE data stating if unsegmented (NON-ISO-TP) CAN frames can be received
'''
PCANTP_OPTION_FRAME_FILTERING = cantp_parameter.PCANTP_PARAMETER_FRAME_FILTERING
'''
''' 1 BYTE data stating if CAN frame DLC uses padding Or Not
'''
PCANTP_OPTION_CAN_DATA_PADDING = cantp_parameter.PCANTP_PARAMETER_CAN_DATA_PADDING
'''
''' 1 BYTE data stating the value used for CAN data padding
'''
PCANTP_OPTION_CAN_PADDING_VALUE = cantp_parameter.PCANTP_PARAMETER_CAN_PADDING_VALUE
'''
''' 1 BYTE data stating the default priority value for normal fixed, mixed And enhanced addressing (default=6)
'''
PCANTP_OPTION_J1939_PRIORITY = cantp_parameter.PCANTP_PARAMETER_J1939_PRIORITY
'''
''' 1 BYTE data stating if pending messages are displayed/hidden
'''
PCANTP_OPTION_MSG_PENDING = cantp_parameter.PCANTP_PARAMETER_MSG_PENDING
'''
''' 1 BYTE data describing the block size parameter (BS)
'''
PCANTP_OPTION_BLOCK_SIZE = cantp_parameter.PCANTP_PARAMETER_BLOCK_SIZE
'''
''' 2 BYTE data describing the transmit block size parameter (BS_TX)
'''
PCANTP_OPTION_BLOCK_SIZE_TX = cantp_parameter.PCANTP_PARAMETER_BLOCK_SIZE_TX
'''
''' 1 BYTE data describing the seperation time parameter (STmin)
'''
PCANTP_OPTION_SEPARATION_TIME = cantp_parameter.PCANTP_PARAMETER_SEPARATION_TIME
'''
''' 2 BYTE data describing the transmit seperation time parameter (STmin_TX)
'''
PCANTP_OPTION_SEPARATION_TIME_TX = cantp_parameter.PCANTP_PARAMETER_SEPARATION_TIME_TX
'''
''' 4 BYTE data describing the Wait Frame Transmissions parameter.µ
'''
PCANTP_OPTION_WFT_MAX = cantp_parameter.PCANTP_PARAMETER_WFT_MAX
'''
''' 1 BYTE data to set optimization options to improve delay between ISO-TP consecutive frames.
'''
PCANTP_OPTION_SELFRECEIVE_LATENCY = cantp_parameter.PCANTP_PARAMETER_SELFRECEIVE_LATENCY
End Enum
'''
''' Represents the status for a message whose transmission Is in progress.
'''
Public Enum cantp_msgprogress_state As UInt32
'''
''' Message Is Not yet handled.
'''
PCANTP_MSGPROGRESS_STATE_QUEUED = 0
'''
''' Message Is being processed (received Or transmitted).
'''
PCANTP_MSGPROGRESS_STATE_PROCESSING = 1
'''
''' Message Is completed.
'''
PCANTP_MSGPROGRESS_STATE_COMPLETED = 2
'''
''' Message Is unknown/Not found.
'''
PCANTP_MSGPROGRESS_STATE_UNKNOWN = 3
End Enum
'''
''' Represents the direction of a message's communication.
'''
Public Enum cantp_msgdirection As UInt32
'''
''' Message Is being received.
'''
PCANTP_MSGDIRECTION_RX = 0
'''
''' Message Is being transmitted.
'''
PCANTP_MSGDIRECTION_TX = 1
End Enum
#End Region
#Region "Structures"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' miscellaneous message related definitions
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
''' Internal information about cantp_msg message (reserved).
'''
Public Structure cantp_msginfo
'''
''' (read-only) size of the message object
'''
Public size As UInt32
'''
''' (read-only) reserved
'''
Public flags As cantp_msginfo_flag
'''
''' (read-only) reserved
'''
Public extra As cantp_msginfo_extra
End Structure
'''
''' Represents message's options to override.
'''
Public Structure cantp_msgoption
'''
''' Name of the option.
'''
Public name As cantp_option
'''
''' Value of the option.
'''
Public value As UInt32
End Structure
'''
''' Represents a list of message's options to override.
'''
Public Structure cantp_msgoption_list
'''
''' Pointer to an array of cantp_msgoption.
''' Use it with with Marshal.Copy, Marshal.ReadInt32, Marshal.WriteInt32
''' (See special VB.Net functions)
'''
Public buffer As IntPtr
'''
''' Number of options in the array.
'''
Public count As UInt32
End Structure
'''
''' Represents common CAN information.
'''
Public Structure cantp_can_info
'''
''' CAN identifier
'''
Public can_id As UInt32
'''
''' Types And flags of the CAN/CAN-FD frame (see cantp_can_msgtype)
'''
Public can_msgtype As cantp_can_msgtype
'''
''' Data Length Code of the frame (0..15)
'''
Public dlc As Byte
End Structure
'''
''' Represents the network address information of an ISO-TP message.
'''
Public Structure cantp_netaddrinfo
'''
''' ISO-TP message type
'''
Public msgtype As cantp_isotp_msgtype
'''
''' ISO-TP format addressing
'''
Public format As cantp_isotp_format
'''
''' ISO-TP addressing/target type
'''
Public target_type As cantp_isotp_addressing
'''
''' source address
'''
Public source_addr As UInt16
'''
''' target address
'''
Public target_addr As UInt16
'''
''' extension address
'''
Public extension_addr As Byte
End Structure
'''
''' Represents a mapping between an ISO-TP network address information And a CAN ID.
'''
Public Structure cantp_mapping
'''
''' Mapping's unique ID
'''
Public uid As UIntPtr
'''
''' CAN ID mapped to the Network Address Information
'''
Public can_id As UInt32
'''
''' CAN ID used for the flow control frame (formerly 'can_id_resp')
'''
Public can_id_flow_ctrl As UInt32
'''
''' CAN frame msgtype (only PCANTP_CAN_MSGTYPE_STANDARD Or PCANTP_CAN_MSGTYPE_EXTENDED Is mandatory)
'''
Public can_msgtype As cantp_can_msgtype
'''
''' Default CAN DLC value to use with segmented messages
'''
Public can_tx_dlc As Byte
'''
''' ISO-TP Network Address Information
'''
Public netaddrinfo As cantp_netaddrinfo
End Structure
'''
''' Represents a message rule for filtering.
'''
Public Structure cantp_msgrule
'''
''' Unique ID (read-only)
'''
Public uid As UIntPtr
'''
''' Type of the message
'''
Public type As cantp_msgtype
'''
''' common CAN information
'''
Public can_info As cantp_can_info
'''
''' ISO-TP network address information
'''
Public netaddrinfo As cantp_netaddrinfo
'''
''' specific options to override global CAN configuration
'''
Public options As cantp_msgoption_list
'''
''' reserved
'''
Public reserved As UIntPtr
End Structure
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Message definitions
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
''' Represents the content of a generic message.
'''
Public Structure cantp_msgdata
'''
''' structure specific flags
'''
Public flags As cantp_msgflag
'''
''' Length of the message
'''
Public length As UInt32
'''
''' Data of the message
''' Array of bytes
''' Use it with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
''' See special VB.Net functions
'''
Public data As IntPtr
'''
''' Network status
'''
Public netstatus As cantp_netstatus
'''
''' Defines specific options to override global message configuration
''' Pointer to a cantp_msgoption_list
''' Use it with Marshal.PtrToStructure() And Marshal.StructureToPtr()
''' See special VB.Net functions
'''
Public options As IntPtr
End Structure
'''
''' Represents the content of a standard CAN frame.
'''
Public Structure cantp_msgdata_can
'''
''' structure specific flags
'''
Public flags As cantp_msgflag
'''
''' Length of the message (0..8)
'''
Public length As UInt32
'''
''' Data of the message
''' Array of bytes
''' Use it with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
''' See special VB.Net functions
'''
Public data As IntPtr
'''
''' Network status
'''
Public netstatus As cantp_netstatus
'''
''' Defines specific options to override global CAN configuration (Not used yet)
''' Pointer to a cantp_msgoption_list
''' Use it with Marshal.PtrToStructure() And Marshal.StructureToPtr()
''' See special VB.Net functions
'''
Public options As IntPtr
'''
''' Data of the message (DATA[0]..DATA[7])
'''
Public data_max As Byte()
End Structure
'''
''' Represents the content of a CAN FD frame.
'''
Public Structure cantp_msgdata_canfd
'''
''' structure specific flags
'''
Public flags As cantp_msgflag
'''
''' Length of the message (0..64)
'''
Public length As UInt32
'''
''' Data of the message
''' Array of bytes
''' Use it with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
''' See special VB.Net functions
'''
Public data As IntPtr
'''
''' Network status
'''
Public netstatus As cantp_netstatus
'''
''' Defines specific options to override global CAN configuration (Not used yet)
''' Pointer to a cantp_msgoption_list
''' Use it with Marshal.PtrToStructure() And Marshal.StructureToPtr()
''' See special VB.Net functions
'''
Public options As IntPtr
'''
''' Data of the message (DATA[0]..DATA[63])
'''
Public data_max As Byte()
End Structure
'''
''' Represents the content of an ISO-TP message.
'''
Public Structure cantp_msgdata_isotp
'''
''' structure specific flags
'''
Public flags As cantp_msgflag
'''
''' Length of the data
'''
Public length As UInt32
'''
''' Data
''' Data of the message
''' Array of bytes
''' Use it with Marshal.WriteByte, Marshal.ReadByte, Marshal.Copy...
''' See special VB.Net functions
'''
Public data As IntPtr
'''
''' Network status
'''
Public netstatus As cantp_netstatus
'''
''' Defines specific options to override global CAN configuration
''' Pointer to a cantp_msgoption_list
''' Use it with Marshal.PtrToStructure() And Marshal.StructureToPtr()
''' See special VB.Net functions
'''
Public options As IntPtr
'''
''' ISO-TP network address information
'''
Public netaddrinfo As cantp_netaddrinfo
'''
''' Reserved ISO-TP information
'''
Public reserved As cantp_isotp_info
End Structure
'''
''' A cantp_msg message Is a generic CAN related message than can be either a standard CAN frame,
''' a CAN FD frame, an ISO-TP message, etc.
'''
Public Structure cantp_msg
'''
''' type of the message
'''
Public type As cantp_msgtype
'''
''' misc. read-only information
'''
Public reserved As cantp_msginfo
'''
''' common CAN information
'''
Public can_info As cantp_can_info
'''
''' data of the message
''' pointer to different structures depending on the message type
''' Use it with following properties (Msgdata_any_Copy, Msgdata_can_copy etc.)
''' Or with Marshal.PtrToStructure And Marshal.StructureToPtr
''' See special VB.Net functions
'''
Private _msgdata As IntPtr
'''
''' get _msgdata field as a property
'''
Public ReadOnly Property Msgdata() As IntPtr
Get
Return _msgdata
End Get
End Property
'''
''' get _msgdata field as a cantp_msgdata property
''' The fields of this property will Not be writable except (Not directly) those whose type Is "IntPtr".
''' Before using this property, check if Msgdata Is Not IntPtr.Zero
'''
Public ReadOnly Property Msgdata_any_Copy() As cantp_msgdata
Get
Return CType(Marshal.PtrToStructure(_msgdata, GetType(cantp_msgdata)), cantp_msgdata)
End Get
End Property
'''
''' get _msgdata field as a cantp_msgdata_can property
''' The fields of this property will Not be writable except (Not directly) those whose type Is "IntPtr".
''' Before using this property, check if Msgdata Is Not IntPtr.Zero
'''
Public ReadOnly Property Msgdata_can_Copy() As cantp_msgdata_can
Get
Return CType(Marshal.PtrToStructure(_msgdata, GetType(cantp_msgdata_can)), cantp_msgdata_can)
End Get
End Property
'''
''' get _msgdata field as a cantp_msgdata_canfd property
''' The fields of this property will Not be writable except (Not directly) those whose type Is "IntPtr".
''' Before using this property, check if Msgdata Is Not IntPtr.Zero
'''
Public ReadOnly Property Msgdata_canfd_Copy() As cantp_msgdata_canfd
Get
Return CType(Marshal.PtrToStructure(_msgdata, GetType(cantp_msgdata_canfd)), cantp_msgdata_canfd)
End Get
End Property
'''
''' get _msgdata field as a cantp_msgdata_isotp property
''' The fields of this property will Not be writable except (Not directly) those whose type Is "IntPtr".
''' Before using this property, check if Msgdata Is Not IntPtr.Zero
'''
Public ReadOnly Property Msgdata_isotp_Copy() As cantp_msgdata_isotp
Get
Return CType(Marshal.PtrToStructure(_msgdata, GetType(cantp_msgdata_isotp)), cantp_msgdata_isotp)
End Get
End Property
End Structure
'''
''' Holds information on the communication progress of a message.
'''
Public Structure cantp_msgprogress
'''
''' State of the message
'''
Public state As cantp_msgprogress_state
'''
''' Progress of the transmission/reception in percent.
'''
Public percentage As Byte
'''
''' Buffer to get a copy of the pending message.
''' Pointer to a cantp_msg
''' If this Is Not needed, set it to IntPtr.Zero.
''' Use it in read-only mode with cantp_msg mp = (cantp_msg)Marshal.PtrToStructure(buffer, TypeOf(cantp_msg));
''' See special VB.Net functions
'''
Public buffer As IntPtr
End Structure
#End Region
#Region "PCANTP Api"
Partial Public NotInheritable Class CanTpApi
#Region "bitrate"
' 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 PCANTP_BITRATE_CLOCK As String = PCANBasic.PCAN_BR_CLOCK
Public Const PCANTP_BITRATE_CLOCK_MHZ As String = PCANBasic.PCAN_BR_CLOCK_MHZ
Public Const PCANTP_BITRATE_NOM_BRP As String = PCANBasic.PCAN_BR_NOM_BRP
Public Const PCANTP_BITRATE_NOM_TSEG1 As String = PCANBasic.PCAN_BR_NOM_TSEG1
Public Const PCANTP_BITRATE_NOM_TSEG2 As String = PCANBasic.PCAN_BR_NOM_TSEG2
Public Const PCANTP_BITRATE_NOM_SJW As String = PCANBasic.PCAN_BR_NOM_SJW
Public Const PCANTP_BITRATE_NOM_SAMPLE As String = PCANBasic.PCAN_BR_NOM_SAMPLE
Public Const PCANTP_BITRATE_DATA_BRP As String = PCANBasic.PCAN_BR_DATA_BRP
Public Const PCANTP_BITRATE_DATA_TSEG1 As String = PCANBasic.PCAN_BR_DATA_TSEG1
Public Const PCANTP_BITRATE_DATA_TSEG2 As String = PCANBasic.PCAN_BR_DATA_TSEG2
Public Const PCANTP_BITRATE_DATA_SJW As String = PCANBasic.PCAN_BR_DATA_SJW
Public Const PCANTP_BITRATE_DATA_SAMPLE As String = PCANBasic.PCAN_BR_DATA_SAMPLE
#End Region
#Region "PCANTP parameter values"
Public Const PCANTP_VALUE_PARAMETER_OFF As Byte = PCANBasic.PCAN_PARAMETER_OFF
Public Const PCANTP_VALUE_PARAMETER_ON As Byte = PCANBasic.PCAN_PARAMETER_ON
'''
''' Enable debug messages (only notices, informations, warnings, errors)
'''
Public Const PCANTP_DEBUG_NOTICE As Byte = &HF4
'''
''' Enable debug messages (only informations, warnings, errors)
'''
Public Const PCANTP_DEBUG_INFO As Byte = &HF3
'''
''' Enable debug messages (only warnings, errors)
'''
Public Const PCANTP_DEBUG_WARNING As Byte = &HF2
'''
''' Enable debug messages (only errors)
'''
Public Const PCANTP_DEBUG_ERROR As Byte = &HF1
#If (PCANTP_API_COMPATIBILITY_ISO_2004 = 0) Then
'''
''' No debug messages
'''
Public Const PCANTP_DEBUG_NONE As Byte = &H0
'''
''' Puts CAN debug messages to stdout
'''
Public Const PCANTP_DEBUG_CAN As Byte = &H1
'''
''' The Channel Is illegal Or Not available
'''
Public Const PCANTP_CHANNEL_UNAVAILABLE As Byte = &H0
'''
''' The Channel Is available
'''
Public Const PCANTP_CHANNEL_AVAILABLE As Byte = &H1
'''
''' The Channel Is valid, And Is being used
'''
Public Const PCANTP_CHANNEL_OCCUPIED As Byte = &H2
'''
''' if set Flow Control frame shall Not use the WT flow status value
'''
Public Const PCANTP_WFT_MAX_UNLIMITED As Byte = &H0
'''
''' an integer describing the Wait Frame Transmissions parameter.
'''
Public Const PCANTP_WFT_MAX_DEFAULT As Byte = &H10
'''
''' hide messages with type PCANTP_MESSAGE_INDICATION from CANTP_Read function
'''
Public Const PCANTP_MSG_PENDING_HIDE As Byte = &H0
'''
''' show messages with type PCANTP_MESSAGE_INDICATION from CANTP_Read function
'''
Public Const PCANTP_MSG_PENDING_SHOW As Byte = &H1
'''
''' uses CAN frame data optimization
'''
Public Const PCANTP_CAN_DATA_PADDING_NONE As Byte = &H0
'''
''' uses CAN frame data padding (default, i.e. CAN DLC As Byte = 8)
'''
Public Const PCANTP_CAN_DATA_PADDING_ON As Byte = &H1
'''
''' default value used if CAN data padding Is enabled
'''
Public Const PCANTP_CAN_DATA_PADDING_VALUE As Byte = &H55
#End If
'''
''' disable reception of unformatted (NON-ISO-TP) CAN frames (default)
''' only ISO 15765 messages will be received
'''
Public Const PCANTP_FRAME_FILTERING_ISOTP As Byte = &H0
'''
''' enable reception of unformatted (NON-ISO-TP) CAN frames
''' received messages will be treated as either ISO 15765 Or as an unformatted CAN frame
'''
Public Const PCANTP_FRAME_FILTERING_CAN As Byte = &H1
'''
''' enable reception of unformatted (NON-ISO-TP) CAN frames
''' received messages will be treated as ISO 15765, unformatted CAN frame, Or both (user will able to read fragmented CAN frames)
'''
Public Const PCANTP_FRAME_FILTERING_VERBOSE As Byte = &H2
#If (PCANTP_API_COMPATIBILITY_ISO_2004 = 0) Then
'''
''' default priority for ISO-TP messages (only available fot normal fixed, mixed And enhanced addressing)
'''
Public Const PCANTP_J1939_PRIORITY_DEFAULT As Byte = &H6
#End If
'''
''' maximum size of a CAN (non-FD) frame (8)
'''
Public Const PCANTP_MAX_LENGTH_CAN_STANDARD As Byte = &H8
'''
''' maximum size of a CAN FD frame (64)
'''
Public Const PCANTP_MAX_LENGTH_CAN_FD As Byte = &H40
'''
''' maximum size of an ISO-TP rev. 2004 frame (4095)
'''
Public Const PCANTP_MAX_LENGTH_ISOTP2004 As UInt32 = &HFFF
'''
''' maximum size of an ISO-TP rev. 2016 frame (4294967295)
'''
Public Const PCANTP_MAX_LENGTH_ISOTP2016 As UInt32 = &HFFFFFFFFUI
'''
''' maximum size before using virtual allocation for ISO-TP messages
'''
Public Const PCANTP_MAX_LENGTH_ALLOC As UInt32 = &HFFFFFFUI
'''
''' default DLC for fragmented frames when transmiting ISO-TP messages
'''
Public Const PCANTP_CAN_TX_DL_DEFAULT As Byte = PCANTP_MAX_LENGTH_CAN_STANDARD
'''
''' ISO-15765-2:2004(E)
'''
Public Const PCANTP_ISO_REV_2004 As Byte = &H1
'''
''' ISO-15765-2:2016(E)
'''
Public Const PCANTP_ISO_REV_2016 As Byte = &H2
'''
''' disables the feature "ignore received BlockSize value"
'''
Public Const PCANTP_BLOCK_SIZE_TX_IGNORE As UInt32 = &HFFFF
'''
''' disables the feature "ignore received STMin value"
'''
Public Const PCANTP_SEPERATION_TIME_TX_IGNORE As UInt32 = &HFFFF
'''
''' sets timeouts according to ISO-15765-2
'''
Public Const PCANTP_ISO_TIMEOUTS_15765_2 As Byte = 0
'''
''' sets timeouts according to ISO-15765-4 (OBDII)
'''
Public Const PCANTP_ISO_TIMEOUTS_15765_4 As Byte = 1
'''
''' no optimization (use this parameter if ECU requires strict respect of Minimum Separation Time)
'''
Public Const PCANTP_SELFRECEIVE_LATENCY_NONE As Byte = 0
'''
''' (DEFAULT) fragmented self-receive frame mechanism Is ignored when STmin Is set to = 0xF3 And lower (less than 300µs)
'''
Public Const PCANTP_SELFRECEIVE_LATENCY_LIGHT As Byte = 1
'''
''' as LIGHT value plus optimize self-receive latency by predicting the time to effectively write frames on bus
'''
Public Const PCANTP_SELFRECEIVE_LATENCY_OPTIMIZED As Byte = 2
'''
''' (DEFAULT) maxinum number of items in the receive queue
'''
Public Const PCANTP_MAX_RX_QUEUE_DEFAULT As UInt32 = 32767
'''
''' (DEFAULT) Network layer design is full-duplex
'''
Public Const PCANTP_NETWORK_LAYER_FULL_DUPLEX As Byte = 0
'''
''' Network layer design is half-duplex (only one transmission/reception of the same NAI at a time)
'''
Public Const PCANTP_NETWORK_LAYER_HALF_DUPLEX As Byte = 1
' Standard ISO-15765-2 values
'''
''' Default value for Separation time
'''
Public Const PCANTP_STMIN_ISO_15765_2 As Byte = 10
'''
''' Default value for BlockSize
'''
Public Const PCANTP_BS_ISO_15765_2 As Byte = 10
'''
''' Default value for Timeout Ar in µs
'''
Public Const PCANTP_TIMEOUT_AR_ISO_15765_2 As UInt32 = (1000 * 1000)
'''
''' Default value for Timeout As in µs
'''
Public Const PCANTP_TIMEOUT_AS_ISO_15765_2 As UInt32 = (1000 * 1000)
'''
''' Default value for Timeout Br in µs
'''
Public Const PCANTP_TIMEOUT_BR_ISO_15765_2 As UInt32 = (1000 * 1000)
'''
''' Default value for Timeout Bs in µs
'''
Public Const PCANTP_TIMEOUT_BS_ISO_15765_2 As UInt32 = (1000 * 1000)
'''
''' Default value for Timeout Cr in µs
'''
Public Const PCANTP_TIMEOUT_CR_ISO_15765_2 As UInt32 = (1000 * 1000)
'''
''' Default value for Timeout Cs in µs
'''
Public Const PCANTP_TIMEOUT_CS_ISO_15765_2 As UInt32 = (1000 * 1000)
'''
''' Default value for timeout tolerance [0..100] (timeout = t * (1 + tolerance/100))
'''
Public Const PCANTP_TIMEOUT_TOLERANCE As Byte = 0
' Standard ISO-15765-4 (OBDII) values
'''
''' OBDII value for Separation time
'''
Public Const PCANTP_STMIN_ISO_15765_4 As Byte = 0
'''
''' OBDII value for BlockSize
'''
Public Const PCANTP_BS_ISO_15765_4 As Byte = 0
'''
''' OBDII value for Timeout Ar in µs
'''
Public Const PCANTP_TIMEOUT_AR_ISO_15765_4 As UInt32 = (1000 * 25)
'''
''' OBDII value for Timeout As in µs
'''
Public Const PCANTP_TIMEOUT_AS_ISO_15765_4 As UInt32 = (1000 * 25)
'''
''' OBDII value for Timeout Br in µs
'''
Public Const PCANTP_TIMEOUT_BR_ISO_15765_4 As UInt32 = (1000 * 75)
'''
''' OBDII value for Timeout Bs in µs
'''
Public Const PCANTP_TIMEOUT_BS_ISO_15765_4 As UInt32 = (1000 * 75)
'''
''' OBDII value for Timeout Cr in µs
'''
Public Const PCANTP_TIMEOUT_CR_ISO_15765_4 As UInt32 = (1000 * 150)
'''
''' OBDII value for Timeout Cs in µs
'''
Public Const PCANTP_TIMEOUT_CS_ISO_15765_4 As UInt32 = (1000 * 150)
' Values for cfg_value
'''
''' Mask for the 29bits ISOTP priority value (stored in bits [0..2])
'''
Public Const PCANTP_FLAG_MASK_PRIORITY As Byte = &H7
'''
''' Padding Is enabled
'''
Public Const PCANTP_FLAG_PADDING_ON As Byte = &H8
'''
''' Message's indication is enabled
'''
Public Const PCANTP_FLAG_INDICATION_ON As Byte = &H10
'''
''' Echo of fragmented frames Is enabled
'''
Public Const PCANTP_FLAG_ECHO_FRAMES_ON As Byte = &H20
#End Region
#Region "constants"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Constants definition
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
''' Mapping does Not require a Flow Control frame.
'''
Public Const PCANTP_MAPPING_FLOW_CTRL_NONE As UInt32 = &HFFFFFFFFUI
#End Region
#Region "PCAN ISO-TP API Implementation"
'''
''' Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
'''
''' Only one PCANTP-Client can be initialized per CAN-Channel
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The CAN Hardware speed
''' NON PLUG-N-PLAY: The type Of hardware And operation mode
''' NON PLUG-N-PLAY: The I/O address For the parallel port
''' NON PLUG-N-PLAY: Interrupt number Of the parallel port
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Initialize_2016(
ByVal channel As cantp_handle,
ByVal baudrate As cantp_baudrate,
ByVal hw_type As cantp_hwtype,
ByVal io_port As UInt32,
ByVal interrupt As UInt16) As cantp_status
End Function
'''
''' Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
'''
''' Only one PCANTP-Client can be initialized per CAN-Channel
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The CAN Hardware speed
''' NON PLUG-N-PLAY: The type Of hardware And operation mode
''' NON PLUG-N-PLAY: The I/O address For the parallel port
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Initialize_2016(
ByVal channel As cantp_handle,
ByVal baudrate As cantp_baudrate,
ByVal hw_type As cantp_hwtype,
ByVal io_port As UInt32) As cantp_status
Return Initialize_2016(channel, baudrate, hw_type, io_port, 0)
End Function
'''
''' Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
'''
''' Only one PCANTP-Client can be initialized per CAN-Channel
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The CAN Hardware speed
''' NON PLUG-N-PLAY: The type Of hardware And operation mode
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Initialize_2016(
ByVal channel As cantp_handle,
ByVal baudrate As cantp_baudrate,
ByVal hw_type As cantp_hwtype) As cantp_status
Return Initialize_2016(channel, baudrate, hw_type, 0, 0)
End Function
'''
''' Initializes a PCANTP-Client based on a CANTP handle (without CAN-FD support)
'''
''' Only one PCANTP-Client can be initialized per CAN-Channel
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The CAN Hardware speed
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Initialize_2016(
ByVal channel As cantp_handle,
ByVal baudrate As cantp_baudrate) As cantp_status
Return Initialize_2016(channel, baudrate, CType(0, cantp_hwtype), 0, 0)
End Function
'''
''' Initializes a PCANTP-Client based on a CANTP Channel (including CAN-FD support)
'''
''' "The handle of a FD capable PCAN Channel"
''' "The speed for the communication (FD bit rate string)"
''' Only one PCANTP-Client can be initialized per CAN-Channel.
''' 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_samp
'''
''' f_clock_mhz=80,nom_brp=0,nom_tseg1=13,nom_tseg2=0,nom_sjw=0,data_brp=0,
''' data_tseg1=13,data_tseg2=0,data_sjw=0
''' "A cantp_status code"
Public Shared Function InitializeFD_2016(
ByVal channel As cantp_handle,
ByVal bitrate_fd As cantp_bitrate) As cantp_status
End Function
'''
''' Uninitializes a PCANTP-Client initialized before
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Uninitialize_2016(
ByVal channel As cantp_handle) As cantp_status
End Function
'''
''' Resets the receive And transmit queues of a PCANTP-Client
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Reset_2016(
ByVal channel As cantp_handle) As cantp_status
End Function
'''
''' Gets information about the internal BUS status of a PCANTP-Channel.
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function GetCanBusStatus_2016(
ByVal channel As cantp_handle) As cantp_status
End Function
'''
''' Reads a PCANTP message from the receive queue of a PCANTP-Client
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_msg structure buffer to store the PUDS message
''' A cantp_timestamp structure buffer to get
''' the reception time of the message.
''' A cantp_msgtype structure buffer to filter the message to read.
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Read_2016(
ByVal channel As cantp_handle,
ByRef msg_buffer As cantp_msg,
ByRef timestamp_buffer As cantp_timestamp,
ByVal msg_type As cantp_msgtype) As cantp_status
End Function
'''
''' Reads a PCANTP message from the receive queue of a PCANTP-Client
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_msg structure buffer to store the PUDS message
''' A cantp_timestamp structure buffer to get
''' the reception time of the message.
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Read_2016(
ByVal channel As cantp_handle,
ByRef msg_buffer As cantp_msg,
ByRef timestamp_buffer As UInt64) As cantp_status
Return Read_2016(channel, msg_buffer, timestamp_buffer, cantp_msgtype.PCANTP_MSGTYPE_ANY)
End Function
Private Shared Function Read_2016(
ByVal channel As cantp_handle,
ByRef msg_buffer As cantp_msg,
ByVal timestamp_buffer As IntPtr,
ByVal msg_type As cantp_msgtype) As cantp_status
End Function
'''
''' Reads a PCANTP message from the receive queue of a PCANTP-Client
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_msg structure buffer to store the PUDS message
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Read_2016(
ByVal channel As cantp_handle,
ByRef msg_buffer As cantp_msg) As cantp_status
Return Read_2016(channel, msg_buffer, IntPtr.Zero, cantp_msgtype.PCANTP_MSGTYPE_ANY)
End Function
'''
''' Gets progress information on a specific message
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_msg structure buffer matching the message to look for
''' The expected direction (incoming/outgoing) of the message
''' A cantp_msgprogress structure buffer to store the progress information
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function GetMsgProgress_2016(
ByVal channel As cantp_handle,
ByRef msg_buffer As cantp_msg,
ByVal direction As cantp_msgdirection,
ByRef msgprogress_buffer As cantp_msgprogress) As cantp_status
End Function
'''
''' Adds a PCANTP message to the Transmit queue
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A cantp_msg buffer with the message to be sent
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function Write_2016(
ByVal channel As cantp_handle,
ByRef msg_buffer As cantp_msg) As cantp_status
End Function
'''
''' Retrieves a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to get
''' Buffer for the parameter value
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function GetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByVal StringBuffer As StringBuilder,
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Retrieves a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to get
''' Numeric buffer for the parameter value
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function GetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByRef NumericBuffer As UInt32,
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Retrieves a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to get
''' Numeric buffer for the parameter value
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function GetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByRef NumericBuffer As UInt64,
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Retrieves a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to get
''' Buffer for the parameter value
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function GetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByVal Buffer As Byte(),
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Configures Or sets a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to set
''' Buffer with the value to be set
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function SetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByRef NumericBuffer As UInt32,
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Configures Or sets a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to set
''' Buffer with the value to be set
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function SetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByRef NumericBuffer As UInt64,
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Configures Or sets a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to set
''' Buffer with the value to be set
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function SetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByVal StringBuffer As String,
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Configures Or sets a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The cantp_parameter parameter to set
''' Buffer with the value to be set
''' Size in bytes of the buffer
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function SetValue_2016(
ByVal channel As cantp_handle,
ByVal parameter As cantp_parameter,
ByVal Buffer As Byte(),
ByVal BufferLength As UInt32) As cantp_status
End Function
'''
''' Adds a user-defined PCAN-TP mapping between CAN ID And Network Address Information
'''
'''
''' Defining a mapping enables ISO-TP communication with 11BITS CAN ID Or
''' with opened Addressing Formats (Like PCANTP_ISOTP_FORMAT_NORMAL Or PCANTP_ISOTP_FORMAT_EXTENDED).
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' Buffer to the mapping to be added
''' A cantp_status code : PCANTP_STATUS_OK Is returned on success,
''' PCANTP_STATUS_WRONG_PARAM states invalid Network Address Information parameters.
Public Shared Function AddMapping_2016(
ByVal channel As cantp_handle,
ByRef mapping As cantp_mapping) As cantp_status
End Function
'''
''' Removes all user-defined PCAN-TP mappings corresponding to a CAN ID
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The mapped CAN ID to search for
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function RemoveMappings_2016(
ByVal channel As cantp_handle,
ByVal can_id As UInt32) As cantp_status
End Function
'''
''' Removes a user-defined PCAN-TP mapping between a CAN ID And Network Address Information
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The identifier of the mapping
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function RemoveMapping_2016(
ByVal channel As cantp_handle,
ByVal uid As UIntPtr) As cantp_status
End Function
'''
''' Retrieves all the mappings defined for a PCAN-TP channel
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A buffer to store an array of cantp_mapping
''' [In]The number of cantp_mapping element the buffer can store. of the mapping.
''' [Out]The actual number of element copied in the buffer.
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success,
''' PCANTP_STATUS_PARAM_BUFFER_TOO_SMALL if the number of mappings exceeds buffer_length.
'''
Public Shared Function GetMappings_2016(
ByVal channel As cantp_handle,
ByVal buffer As cantp_mapping(),
ByRef buffer_length As UInt32) As cantp_status
End Function
'''
''' Adds an entry to the CAN-ID white-list filtering.
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The lowest CAN ID wanted to be received
''' The highest CAN ID wanted to be received
''' States if filter should check the CAN message type.
''' If ignore_can_msgtype Is false, the value states which types of CAN frame should be allowed.
''' A cantp_status code : PCANTP_STATUS_OK Is returned on success, And PCANTP_STATUS_ALREADY_INITIALIZED otherwise.
Public Shared Function AddFiltering_2016(
ByVal channel As cantp_handle,
ByVal can_id_from As UInt32,
ByVal can_id_to As UInt32,
ByVal ignore_can_msgtype As Boolean,
ByVal can_msgtype As cantp_can_msgtype) As cantp_status
End Function
'''
''' Removes an entry from the CAN-ID white-list filtering.
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The lowest CAN ID wanted to be removed
''' The highest CAN ID wanted to be removed
''' States if filter should check the CAN message type.
''' If ignore_can_msgtype Is false, the value states which types of CAN frame should be allowed.
''' A cantp_status code : PCANTP_STATUS_OK Is returned on success, And PCANTP_STATUS_ALREADY_INITIALIZED otherwise.
Public Shared Function RemoveFiltering_2016(
ByVal channel As cantp_handle,
ByVal can_id_from As UInt32,
ByVal can_id_to As UInt32,
ByVal ignore_can_msgtype As Boolean,
ByVal can_msgtype As cantp_can_msgtype) As cantp_status
End Function
'''
''' Adds an entry to the message's rules.
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The rule to insert.
''' A cantp_status code : PCANTP_STATUS_OK Is returned on success
Public Shared Function AddMsgRule_2016(
ByVal channel As cantp_handle,
ByRef msgrule As cantp_msgrule) As cantp_status
End Function
'''
''' Removes an entry from the message's rules.
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The unique ID of the rule to remove.
''' A cantp_status code : PCANTP_STATUS_OK Is returned on success
Public Shared Function RemoveMsgRule_2016(
ByVal channel As cantp_handle,
ByVal uid As UIntPtr) As cantp_status
End Function
'''
''' Returns a descriptive text of a given cantp_status 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 cantp_status error code
''' Indicates a 'Primary language ID'
''' Buffer for a null terminated char array
''' Buffer size
''' A cantp_status error code
Public Shared Function GetErrorText_2016(
ByVal err As cantp_status,
ByVal language As UInt16,
ByVal StringBuffer As StringBuilder,
ByVal BufferSize As UInt32) As cantp_status
End Function
'''
''' Allocates a PCAN-TP message based on the given type
'''
''' A cantp_msg structure buffer (it will be freed if required)
''' Type of the message to allocate
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function MsgDataAlloc_2016(
ByRef msg_buffer As cantp_msg,
ByVal type As cantp_msgtype) As cantp_status
End Function
'''
''' Initializes an allocated PCAN-TP message
'''
''' An allocated cantp_msg structure buffer
''' CAN identifier (ISO-TP message may ignore this parameter And use PCANTP_MAPPING_FLOW_CTRL_NONE (-1))
''' Combination of CAN message types (Like "extended CAN ID", "FD", "RTR", etc. flags)
''' Length of the data
''' A buffer to initialize the message's data with. If NULL, message's data is initialized with zeros.
''' Network address information of the ISO-TP message (only valid with an ISO-TP message)
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function MsgDataInit_2016(
ByRef msg_buffer As cantp_msg,
ByVal can_id As UInt32,
ByVal can_msgtype As cantp_can_msgtype,
ByVal data_length As UInt32,
ByVal data As Byte(),
ByRef netaddrinfo As cantp_netaddrinfo) As cantp_status
End Function
Private Shared Function MsgDataInit_2016(
ByRef msg_buffer As cantp_msg,
ByVal can_id As UInt32,
ByVal can_msgtype As cantp_can_msgtype,
ByVal data_length As UInt32,
ByVal data As Byte(),
ByVal netaddrinfo As IntPtr) As cantp_status
End Function
'''
''' Initializes an allocated PCAN-TP message
'''
''' An allocated cantp_msg structure buffer
''' CAN identifier (ISO-TP message may ignore this parameter And use PCANTP_MAPPING_FLOW_CTRL_NONE (-1))
''' Combination of CAN message types (Like "extended CAN ID", "FD", "RTR", etc. flags)
''' Length of the data
''' A buffer to initialize the message's data with. If NULL, message's data is initialized with zeros.
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function MsgDataInit_2016(
ByRef msg_buffer As cantp_msg,
ByVal can_id As UInt32,
ByVal can_msgtype As cantp_can_msgtype,
ByVal data_length As UInt32,
ByVal data As Byte()) As cantp_status
Return MsgDataInit_2016(msg_buffer, can_id, can_msgtype, data_length, data, IntPtr.Zero)
End Function
'''
''' Initializes a number of options for the PCAN-TP message that will override the channel's parameter(s)
'''
''' An allocated cantp_msg structure buffer.
''' Number of options to initialize.
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function MsgDataInitOptions_2016(
ByRef msg_buffer As cantp_msg,
ByVal nb_options As UInt32) As cantp_status
End Function
'''
''' Deallocates a PCAN-TP message
'''
''' An allocated cantp_msg structure buffer.
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function MsgDataFree_2016(
ByRef msg_buffer As cantp_msg) As cantp_status
End Function
' we do not publish this function because the result must be a byte,
' And applying 'Not' on this result does not work.
Private Shared Function _MsgEqual_2016(
ByRef msg_buffer1 As cantp_msg,
ByRef msg_buffer2 As cantp_msg,
ByVal ignoreSelfReceiveFlag As Boolean) As Byte
End Function
'''
''' Checks if two PCAN-TP messages are equal.
''' If one message Is the indication of an incoming/outgoing ISO-TP message, the actual data-content will Not be compared.
''' In that case the function checks if the messages' network address information matches.
'''
''' A cantp_msg structure buffer.
''' Another cantp_msg structure buffer to compare with first parameter.
''' States if comparison should ignore loopback flag
''' (i.e if true the function will return true when comparing a request And its loopback confirmation).
''' A boolean stating if the cantp_msgs are equal.
Public Shared Function MsgEqual_2016(
ByRef msg_buffer1 As cantp_msg,
ByRef msg_buffer2 As cantp_msg,
ByVal ignoreSelfReceiveFlag As Boolean) As Boolean
Return CType(_MsgEqual_2016(msg_buffer1, msg_buffer2, ignoreSelfReceiveFlag), Boolean)
End Function
'''
''' Copies a PCAN-TP message to another buffer.
'''
''' A cantp_msg structure buffer to store the copied message.
''' The cantp_msg structure buffer used as the source.
''' A cantp_status code. PCANTP_STATUS_OK Is returned on success
Public Shared Function MsgCopy_2016(
ByRef msg_buffer_dst As cantp_msg,
ByRef msg_buffer_src As cantp_msg) As cantp_status
End Function
'''
''' Converts a CAN DLC to its corresponding length.
'''
''' The Data Length Code (DLC) to convert.
''' The corresponding length of the dlc parameter.
Public Shared Function MsgDlcToLength_2016(
ByVal dlc As Byte) As UInt32
End Function
'''
''' Converts a data length to a corresponding CAN DLC.
''' Note the returned DLC can hold more data that the requested length.
'''
''' The length to convert.
''' The smallest DLC that can hold the requested length (0x00-0x0F).
Public Shared Function MsgLengthToDlc_2016(
ByVal length As UInt32) As Byte
End Function
'''
''' Lists the subtypes contained in the PCAN-TP status.
'''
''' The status to analyze.
''' An aggregation of cantp_statustype values.
Public Shared Function StatusListTypes_2016(
ByVal status As cantp_status) As cantp_statustype
End Function
'''
''' Retrieves the value of a cantp_status subtype (Like cantp_errstatus, cantp_busstatus, etc.).
'''
''' The status to analyze.
''' The type of status to filter.
''' The value of the enumeration matching the requested type.
Public Shared Function StatusGet_2016(
ByVal status As cantp_status,
ByVal type As cantp_statustype) As UInt32
End Function
' we do not publish this function because the result must be a byte,
' And applying 'Not' on this result does not work.
Private Shared Function _StatusIsOk_2016(
ByVal status As cantp_status,
ByVal status_expected As cantp_status,
ByVal strict As Boolean) As Byte
End Function
'''
''' Checks if a status matches an expected result.
'''
''' The status to analyze.
''' The expected status.
''' Enable strict mode. Strict mode ensures that bus Or extra information are the same.
''' Returns true if the status matches expected parameter.
Public Shared Function StatusIsOk_2016(
ByVal status As cantp_status,
ByVal status_expected As cantp_status,
ByVal strict As Boolean) As Boolean
Return CType(_StatusIsOk_2016(status, status_expected, strict), Boolean)
End Function
'''
''' Checks if a status matches an expected result in non-strict mode
''' (Strict mode ensures that bus Or extra information are the same).
'''
''' The status to analyze.
''' The expected status (default Is PCANTP_STATUS_OK).
''' Returns true if the status matches expected parameter.
Public Shared Function StatusIsOk_2016(
ByVal status As cantp_status,
ByVal status_expected As cantp_status
) As Boolean
Return StatusIsOk_2016(status, status_expected, False)
End Function
'''
''' Checks if a status matches PCANTP_STATUS_OK in non-strict mode
''' (Strict mode ensures that bus Or extra information are the same).
'''
''' The status to analyze.
''' Returns true if the status matches expected parameter.
Public Shared Function StatusIsOk_2016(
ByVal status As cantp_status
) As Boolean
Return StatusIsOk_2016(status, cantp_status.PCANTP_STATUS_OK, False)
End Function
#Region "Special VB.Net functions, examples of how to use the structures IntPtr fields with Marshaling operations"
'''
''' Get an option value of an option list
'''
''' option list
''' number of the option
''' where to store a copy of the option
''' true if ok, false if Not ok
Private Shared Function getOption_2016(ByRef l As cantp_msgoption_list,
ByVal number As Integer,
ByRef opt As cantp_msgoption) As Boolean
opt = New cantp_msgoption()
If number < l.count And l.buffer <> IntPtr.Zero Then
opt.name = CType(Marshal.ReadInt32(l.buffer, number * 8), cantp_option)
opt.value = CType(Marshal.ReadInt32(l.buffer, number * 8 + 4), UInt32)
Return True
End If
Return False
End Function
'''
''' Modifies an option
'''
''' option list
''' number of the option
''' value to set to the option
''' true if ok, false if Not ok
Private Shared Function setOption_2016(ByRef l As cantp_msgoption_list,
ByVal number As Integer,
ByRef opt As cantp_msgoption) As Boolean
If number < l.count And l.buffer <> IntPtr.Zero Then
Marshal.WriteInt32(l.buffer, number * 8, CType(opt.name, Int32))
Marshal.WriteInt32(l.buffer, number * 8 + 4, CType(opt.value, Int32))
Return True
End If
Return False
End Function
'''
''' in a progress structure, allocate a buffer to receive a copy of the pending message.
''' when finished, must be released with freeProgressBuffer_2016()
'''
''' progress structure
''' type of the pending message
''' resulting status
Public Shared Function allocProgressBuffer_2016(ByRef prog As cantp_msgprogress, ByVal type As cantp_msgtype) As cantp_status
Dim pendingMsg As cantp_msg
Dim status As cantp_status = CanTpApi.MsgDataAlloc_2016(pendingMsg, type)
If status = cantp_status.PCANTP_STATUS_OK Then
Try
' Initialize unmanaged memory to hold the struct.
prog.buffer = Marshal.AllocHGlobal(Marshal.SizeOf(pendingMsg))
Catch
prog.buffer = IntPtr.Zero
End Try
If prog.buffer <> IntPtr.Zero Then
Marshal.StructureToPtr(pendingMsg, prog.buffer, True)
Else
status = cantp_status.PCANTP_STATUS_NO_MEMORY
End If
End If
Return status
End Function
'''
''' free the buffer receiving the pending message in a progress structure,
''' if allocated with allocProgressBuffer_2016()
'''
''' progress structure
Public Shared Sub freeProgressBuffer_2016(ByRef prog As cantp_msgprogress)
' Free unmanaged memory holding the struct.
If prog.buffer <> IntPtr.Zero Then
Marshal.FreeHGlobal(prog.buffer)
prog.buffer = IntPtr.Zero
End If
End Sub
'''
''' get the current pending message of a progress structure.
'''
''' progress structure
''' pending message
''' true if ok, false if not ok
Public Shared Function getProgressBuffer_2016(ByRef prog As cantp_msgprogress, ByRef pendmsg As cantp_msg) As Boolean
If prog.buffer <> IntPtr.Zero Then
pendmsg = CType(Marshal.PtrToStructure(prog.buffer, GetType(cantp_msg)), cantp_msg)
Return True
End If
Return False
End Function
'''
''' get the flags of a message
'''
''' Message structure
''' value of the flags
''' true if ok, false if Not ok
Public Shared Function getFlags_2016(ByRef msg As cantp_msg, ByRef flags As cantp_msgflag) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
flags = msg.Msgdata_any_Copy.flags
Return True
End If
Return False
End Function
'''
''' set the length of a message
''' use carefully
'''
''' value to set
''' true if ok, false if Not ok
Public Shared Function setLength_2016(ByRef msg As cantp_msg, ByVal len As UInt32) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = CType(Marshal.PtrToStructure(msg.Msgdata, GetType(cantp_msgdata)), cantp_msgdata)
msgdata.length = len
Marshal.StructureToPtr(msgdata, msg.Msgdata, True)
Return True
End If
Return False
End Function
'''
''' get the length of a message
'''
''' Message structure
''' value of the length
''' true if ok, false if Not ok
Public Shared Function getLength_2016(ByRef msg As cantp_msg, ByRef len As UInt32) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
len = msg.Msgdata_any_Copy.length
Return True
End If
Return False
End Function
'''
''' set a byte of the data of a message
'''
''' Message structure to modify.
''' offset of the byte, cannot be more than 2147483647
''' value to set
''' true if ok, false if not ok
Public Shared Function setData_2016(ByRef msg As cantp_msg,
ByVal i As Integer,
ByVal val As Byte) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = msg.Msgdata_any_Copy
If msgdata.length > 0 And msgdata.data <> IntPtr.Zero And i >= 0 And i < msgdata.length Then
Marshal.WriteByte(msgdata.data, i, val)
Return True
End If
End If
Return False
End Function
'''
''' set bytes of the data of a message from a contiguous byte array
'''
''' Message structure to modify.
''' offset of the first byte in the message, cannot be more than 2147483647
''' number of bytes
''' values to set, from offset 0
''' true if ok, false if not ok
Public Shared Function setData_2016(ByRef msg As cantp_msg, ByVal i As Integer, ByVal vals As Byte(), ByVal nb As Integer) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = msg.Msgdata_any_Copy
If msgdata.length > 0 And msgdata.data <> IntPtr.Zero And i >= 0 And i + nb - 1 < msgdata.length And vals.Length >= nb Then
If i = 0 Then
Marshal.Copy(vals, 0, msgdata.data, nb)
Else
For j As Integer = 0 To nb - 1
Marshal.WriteByte(msgdata.data, j + i, vals(j))
Next j
End If
Return True
End If
End If
Return False
End Function
'''
''' get a byte of data of a message
'''
''' Message structure containing data.
''' offset of the byte (byte number)
''' value of the byte of data
''' true if ok, false if not ok
Public Shared Function getData_2016(ByRef msg As cantp_msg,
ByVal i As Integer,
ByRef val As Byte) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = msg.Msgdata_any_Copy
If msgdata.length > 0 And msgdata.data <> IntPtr.Zero And i >= 0 And i < msgdata.length Then
val = Marshal.ReadByte(msgdata.data, i)
Return True
End If
End If
Return False
End Function
'''
''' get bytes of the data of a message
'''
''' Message structure containing data.
''' offset of the first byte to get in the message, cannot be more than 2147483647
''' number of bytes
''' values of the bytes, from offset 0
''' true if ok, false if not ok
Public Shared Function getData_2016(ByRef msg As cantp_msg, ByVal i As Integer, ByRef vals As Byte(), ByVal nb As Integer) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = msg.Msgdata_any_Copy
If msgdata.length > 0 And msgdata.data <> IntPtr.Zero And i >= 0 And i + nb - 1 < msgdata.length And nb <= vals.Length Then
If i = 0 Then
Marshal.Copy(msgdata.data, vals, 0, nb)
Else
For j As Integer = 0 To nb - 1
vals(j) = Marshal.ReadByte(msgdata.data, j + i)
Next j
End If
Return True
End If
End If
Return False
End Function
'''
''' get the net status of a message
'''
''' Message structure containing the network status
''' value of the status
''' true if ok, false if Not ok
Public Shared Function getNetStatus_2016(ByRef msg As cantp_msg, ByRef status As cantp_netstatus) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
status = msg.Msgdata_any_Copy.netstatus
Return True
End If
Return False
End Function
'''
''' Get the number of options of a message
'''
''' message
''' number of options
''' true if ok, false if Not ok
Public Shared Function getOptionsNumber_2016(ByRef msg As cantp_msg, ByRef number As Integer) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = msg.Msgdata_any_Copy
If msgdata.options <> IntPtr.Zero Then
Dim l As cantp_msgoption_list = CType(Marshal.PtrToStructure(msgdata.options, GetType(cantp_msgoption_list)), cantp_msgoption_list)
number = l.count
Return True
End If
End If
Return False
End Function
'''
''' Get an option of a message
'''
''' number of the option
''' where to store a copy of the option
''' true if ok, false if Not ok
Public Shared Function getOption_2016(ByRef msg As cantp_msg, ByVal number As Integer,
ByRef opt As cantp_msgoption) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = msg.Msgdata_any_Copy
If msgdata.options <> IntPtr.Zero Then
Dim l As cantp_msgoption_list = CType(Marshal.PtrToStructure(msgdata.options, GetType(cantp_msgoption_list)), cantp_msgoption_list)
Return getOption_2016(l, number, opt)
End If
End If
Return False
End Function
'''
''' Modifies an option of a message
'''
''' Message structure to modify
''' number of the option
''' value to set to the option
''' true if ok, false if Not ok
Public Shared Function setOption_2016(ByRef msg As cantp_msg, ByVal number As Integer,
ByRef opt As cantp_msgoption) As Boolean
If msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata = msg.Msgdata_any_Copy
If msgdata.options <> IntPtr.Zero Then
Dim l As cantp_msgoption_list = CType(Marshal.PtrToStructure(msgdata.options, GetType(cantp_msgoption_list)), cantp_msgoption_list)
Return setOption_2016(l, number, opt)
End If
End If
Return False
End Function
'''
''' set the network address information of an ISO-TP message
'''
''' address to set
''' true if ok, false if Not ok
Public Shared Function setNetaddrinfo_2016(ByRef msg As cantp_msg, ByRef adr As cantp_netaddrinfo) As Boolean
If msg.type = cantp_msgtype.PCANTP_MSGTYPE_ISOTP And msg.Msgdata <> IntPtr.Zero Then
Dim msgdata As cantp_msgdata_isotp = CType(Marshal.PtrToStructure(msg.Msgdata, GetType(cantp_msgdata_isotp)), cantp_msgdata_isotp)
msgdata.netaddrinfo = adr
Marshal.StructureToPtr(msgdata, msg.Msgdata, True)
Return True
End If
Return False
End Function
'''
''' get the network address information of an ISO-TP message
'''
''' value of address
''' true if ok, false if Not ok
Public Shared Function getNetaddrinfo_2016(ByRef msg As cantp_msg, ByRef adr As cantp_netaddrinfo) As Boolean
If msg.type = cantp_msgtype.PCANTP_MSGTYPE_ISOTP And msg.Msgdata <> IntPtr.Zero Then
adr = msg.Msgdata_isotp_Copy.netaddrinfo
Return True
End If
Return False
End Function
#End Region
#End Region
End Class
#End Region
End Namespace