' PCAN-ISO-TP_2004.vb
'
' ~~~~~~~~~~~~
'
' PCAN-ISO-TP API
'
' ~~~~~~~~~~~~
'
' ------------------------------------------------------------------
' Author : Fabrice Vergnaud
' Last changed by: $Author: Fabrice $
' Last changed date: $Date: 2020-02-10 16:57:41 +0100 (Mon, 10 Feb 2020) $
'
' Language: VB.Net
' ------------------------------------------------------------------
'
' Copyright (C) 2015 PEAK-System Technik GmbH, Darmstadt
' more Info at http:''www.peak-system.com
'
Imports System
Imports System.Text
Imports System.Runtime.InteropServices
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Inclusion of other needed stuff
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports TPCANTPHandle = System.UInt16
Imports TPCANTPBitrateFD = System.String
Namespace Peak.Can.IsoTp
#Region "Enumerations"
'''
''' Represents a PCAN Baud rate register value
'''
Public Enum TPCANTPBaudrate As UShort
'''
''' 1 MBit/s
'''
PCANTP_BAUD_1M = &H14
'''
''' 800 kBit/s
'''
PCANTP_BAUD_800K = &H16
'''
''' 500 kBit/s
'''
PCANTP_BAUD_500K = &H1C
'''
''' 250 kBit/s
'''
PCANTP_BAUD_250K = &H11C
'''
''' 125 kBit/s
'''
PCANTP_BAUD_125K = &H31C
'''
''' 100 kBit/s
'''
PCANTP_BAUD_100K = &H432F
'''
''' 95,238 kBit/s
'''
PCANTP_BAUD_95K = &HC34E
'''
''' 83,333 kBit/s
'''
PCANTP_BAUD_83K = &H852B
'''
''' 50 kBit/s
'''
PCANTP_BAUD_50K = &H472F
'''
''' 47,619 kBit/s
'''
PCANTP_BAUD_47K = &H1414
'''
''' 33,333 kBit/s
'''
PCANTP_BAUD_33K = &H8B2F
'''
''' 20 kBit/s
'''
PCANTP_BAUD_20K = &H532F
'''
''' 10 kBit/s
'''
PCANTP_BAUD_10K = &H672F
'''
''' 5 kBit/s
'''
PCANTP_BAUD_5K = &H7F7F
End Enum
'''
''' Represents the different Not Plug-And-Play PCAN Hardware types
'''
Public Enum TPCANTPHWType As Byte
'''
''' PCAN-ISA 82C200
'''
PCANTP_TYPE_ISA = &H1
'''
''' PCAN-ISA SJA1000
'''
PCANTP_TYPE_ISA_SJA = &H9
'''
''' PHYTEC ISA
'''
PCANTP_TYPE_ISA_PHYTEC = &H4
'''
''' PCAN-Dongle 82C200
'''
PCANTP_TYPE_DNG = &H2
'''
''' PCAN-Dongle EPP 82C200
'''
PCANTP_TYPE_DNG_EPP = &H3
'''
''' PCAN-Dongle SJA1000
'''
PCANTP_TYPE_DNG_SJA = &H5
'''
''' PCAN-Dongle EPP SJA1000
'''
PCANTP_TYPE_DNG_SJA_EPP = &H6
End Enum
'''
''' Represent the PCANTP error and status codes
'''
Public Enum TPCANTPStatus As Integer
'''
''' No error
'''
PCANTP_ERROR_OK = &H0
'''
''' Not Initialized
'''
PCANTP_ERROR_NOT_INITIALIZED = &H1
'''
''' Already Initialized
'''
PCANTP_ERROR_ALREADY_INITIALIZED = &H2
'''
''' Could not obtain memory
'''
PCANTP_ERROR_NO_MEMORY = &H3
'''
''' Input buffer overflow
'''
PCANTP_ERROR_OVERFLOW = &H4
'''
''' No Message available
'''
PCANTP_ERROR_NO_MESSAGE = &H7
'''
''' Wrong message parameters
'''
PCANTP_ERROR_WRONG_PARAM = &H8
'''
''' PCANTP Channel is in BUS-LIGHT error state
'''
PCANTP_ERROR_BUSLIGHT = &H9
'''
''' PCANTP Channel is in BUS-HEAVY error state
'''
PCANTP_ERROR_BUSHEAVY = &HA
'''
''' PCANTP Channel is in BUS-OFF error state
'''
PCANTP_ERROR_BUSOFF = &HB
'''
''' Global CAN error, status code for composition of PCANBasic Errors.
''' Remove this value to get a PCAN-Basic TPCANStatus error code.
'''
PCANTP_ERROR_CAN_ERROR = &H80000000
End Enum
'''
''' Represent message request confirmation values defined in ISO 15765-2
'''
Public Enum TPCANTPConfirmation As Byte
'''
''' No network error
'''
PCANTP_N_OK = &H0
'''
''' timeout occured between 2 frames transmission (sender and receiver side)
'''
PCANTP_N_TIMEOUT_A = &H1
'''
''' sender side timeout while waiting for flow control frame
'''
PCANTP_N_TIMEOUT_BS = &H2
'''
''' receiver side timeout while waiting for consecutive frame
'''
PCANTP_N_TIMEOUT_CR = &H3
'''
''' unexpected sequence number
'''
PCANTP_N_WRONG_SN = &H4
'''
''' invalid or unknown FlowStatus
'''
PCANTP_N_INVALID_FS = &H5
'''
''' unexpected protocol data unit
'''
PCANTP_N_UNEXP_PDU = &H6
'''
''' reception of flow control WAIT frame that exceeds the maximum counter defined by PCANTP_PARAM_WFT_MAX
'''
PCANTP_N_WFT_OVRN = &H7
'''
''' buffer on the receiver side cannot store the data length (server side only)
'''
PCANTP_N_BUFFER_OVFLW = &H8
'''
''' general error
'''
PCANTP_N_ERROR = &H9
'''
''' message was invalid and ignored
'''
PCANTP_N_IGNORED = &HA
End Enum
'''
''' PCANTP parameters
'''
Public Enum TPCANTPParameter As Byte
'''
''' 1 BYTE data describing the block size parameter (BS)
'''
PCANTP_PARAM_BLOCK_SIZE = &HE1
'''
''' 1 BYTE data describing the separation time parameter (STmin)
'''
PCANTP_PARAM_SEPARATION_TIME = &HE2
'''
''' 1 BYTE data describing the debug mode
'''
PCANTP_PARAM_DEBUG = &HE3
'''
''' 1 Byte data describing the condition of a channel
'''
PCANTP_PARAM_CHANNEL_CONDITION = &HE4
'''
''' Integer data describing the Wait Frame Transmissions parameter.
'''
PCANTP_PARAM_WFT_MAX = &HE5
'''
''' 1 BYTE data stating if pending messages are displayed/hidden
'''
PCANTP_PARAM_MSG_PENDING = &HE6
'''
''' PCAN-ISO-TP API version parameter
'''
PCANTP_PARAM_API_VERSION = &HE7
'''
''' 1 BYTE data stating if CAN frame DLC uses padding or not
'''
PCANTP_PARAM_CAN_DATA_PADDING = &HE8
'''
''' 1 BYTE data stating if unsegmented (NON-ISO-TP) CAN frames can be received
'''
PCANTP_PARAM_CAN_UNSEGMENTED = &HE9
'''
''' PCAN-ISO-TP receive event handler parameter
'''
PCANTP_PARAM_RECEIVE_EVENT = &HEA
'''
''' 1 BYTE data stating the value used for CAN data padding
'''
PCANTP_PARAM_PADDING_VALUE = &HED
'''
''' 1 BYTE data stating the default priority value for normal fixed, mixed And enhanced addressing (default=6)
'''
PCANTP_PARAM_J1939_PRIORITY = &HEE
'''
''' 1 BYTE data stating the default DLC to use when transmitting messages with CAN FD
'''
PCANTP_PARAM_CAN_TX_DL = &HEF
'''
''' 1 BYTE data stating how to optimize Minimum SeparationTime latency (enabled=1 by default).
''' Set value to 0 to ensure STMin is always strictly respected (but consequently lose some speed in communication process).
'''
PCANTP_PARAM_SEPARATION_TIME_OPTIMIZATION = &HF0
End Enum
'''
''' PCANTP message types
'''
Public Enum TPCANTPMessageType As Byte
'''
''' Unknown (non-ISO-TP) message
'''
PCANTP_MESSAGE_UNKNOWN = &H0
'''
''' Diagnostic Request/Confirmation
'''
PCANTP_MESSAGE_DIAGNOSTIC = &H1
'''
''' Remote Dignostic Request/Confirmation (uses RA address)
'''
PCANTP_MESSAGE_REMOTE_DIAGNOSTIC = &H2
'''
''' Confirms that a message has been sent successfully/ not successfully
'''
PCANTP_MESSAGE_REQUEST_CONFIRMATION = &H3
'''
''' Multi-Frame Message is being received
'''
PCANTP_MESSAGE_INDICATION = &H4
'''
''' Multi-Frame Message is being transmitted
'''
PCANTP_MESSAGE_INDICATION_TX = &H5
End Enum
'''
''' PCANTP message types
'''
_
Public Enum TPCANTPIdType As Byte
'''
''' 11 bits CAN ID (CAN Standard Frame)
'''
PCANTP_ID_CAN_11BIT = &H1
'''
''' 29 bits CAN ID (CAN Extended Frame)
'''
PCANTP_ID_CAN_29BIT = &H2
'''
''' CAN FD flag
'''
PCANTP_ID_CAN_FD = &H4
'''
''' Bitrate Switch flag (only if CAN FD)
'''
PCANTP_ID_CAN_BRS = &H8
End Enum
'''
''' PCANTP message types utility function to handle priority J1939 compatible ISO-TP messages
'''
Public Class TPCANTPIdTypePriority
'''
''' Get the 29bits CAN ID type with a specific J1939 priority
'''
Public Shared Function PCANTP_ID_CAN_GET_29B(ByVal j1939_priority As Byte) As TPCANTPIdType
Return (CByte(j1939_priority << 5) Or CanTpApi.PCANTP_ID_CAN_IS_PRIORITY_MASK Or (CByte(TPCANTPIdType.PCANTP_ID_CAN_29BIT) And CanTpApi.PCANTP_ID_CAN_MASK))
End Function
'''
''' Retrieves the priority field from a CAN ID type
'''
Public Shared Function PCANTP_ID_CAN_GET_PRIORIY(ByVal id_type As Byte) As Byte
Return CByte(id_type >> 5)
End Function
'''
''' States if the CAN ID Type is 29bits
'''
Public Shared Function PCANTP_ID_CAN_IS_EXTENDED(ByVal id_type As Byte) As Boolean
Return ((id_type And CByte(TPCANTPIdType.PCANTP_ID_CAN_29BIT)) = CByte(TPCANTPIdType.PCANTP_ID_CAN_29BIT))
End Function
'''
''' States if the id_type contains a J1939 priority field
'''
Public Shared Function PCANTP_ID_CAN_HAS_PRIORITY(ByVal id_type As Byte) As Boolean
Return (PCANTP_ID_CAN_IS_EXTENDED(id_type) AndAlso ((id_type And CanTpApi.PCANTP_ID_CAN_IS_PRIORITY_MASK) = CanTpApi.PCANTP_ID_CAN_IS_PRIORITY_MASK))
End Function
End Class
'''
''' PCANTP addressing type
'''
Public Enum TPCANTPFormatType As Byte
'''
''' unknown adressing format
'''
PCANTP_FORMAT_UNKNOWN = &HFF
'''
''' unsegmented CAN frame
'''
PCANTP_FORMAT_NONE = &H0
'''
''' normal adressing format from ISO 15765-2
'''
PCANTP_FORMAT_NORMAL = &H1
'''
''' fixed normal adressing format from ISO 15765-2
'''
PCANTP_FORMAT_FIXED_NORMAL = &H2
'''
''' extended adressing format from ISO 15765-2
'''
PCANTP_FORMAT_EXTENDED = &H3
'''
''' mixed adressing format from ISO 15765-2
'''
PCANTP_FORMAT_MIXED = &H4
'''
''' enhanced adressing format from ISO 15765-3
'''
PCANTP_FORMAT_ENHANCED = &H5
End Enum
'''
''' PCANTP addressing type
'''
Public Enum TPCANTPAddressingType As Byte
'''
''' Unknown (non-ISO-TP) message
'''
PCANTP_ADDRESSING_UNKNOWN = &H0
'''
''' Physical addressing
'''
PCANTP_ADDRESSING_PHYSICAL = &H1
'''
''' Functional addressing
'''
PCANTP_ADDRESSING_FUNCTIONAL = &H2
End Enum
#End Region
#Region "Structures"
Public Structure TPCANTPMsg
'''
''' Represents the origin of this message (address from
''' where this message was or will be sent)
'''
Public SA As Byte
'''
''' Represents the destination of this message (address to
''' where this message was or will be sent)
'''
Public TA As Byte
'''
''' Represents the kind of addressing being used for communication
'''
_
Public TA_TYPE As TPCANTPAddressingType
'''
''' Represents the destination of this message in a remote network
'''
Public RA As Byte
'''
''' Identifies the kind of CAN Identifier
'''
_
Public IDTYPE As TPCANTPIdType
'''
''' Identifies the kind of data represented by this message
'''
_
Public MSGTYPE As TPCANTPMessageType
'''
''' Represents the kind of format represented by this message
'''
_
Public FORMAT As TPCANTPFormatType
'''
''' Represents the buffer containing the data of this message
'''
_
Public DATA As Byte()
'''
''' Indicates the length of the useful data within the DATA buffer
'''
Public LEN As UShort
'''
''' Represent message request confirmation
'''
_
Public RESULT As TPCANTPConfirmation
End Structure
'''
''' Represents a timestamp of a received PCANTP message.
''' Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
'''
Public Structure TPCANTPTimestamp
'''
''' 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
#End Region
#Region "PCANTP Api"
'''
''' The PCAN-ISO-TP API class
'''
Partial Public NotInheritable Class CanTpApi
#Region "PCAN-BUS Handles Definition"
'''
''' Undefined/default value for a PCAN bus
'''
Public Const PCANTP_NONEBUS As TPCANTPHandle = &H0
'''
''' PCAN-ISA interface, channel 1
'''
Public Const PCANTP_ISABUS1 As TPCANTPHandle = &H21
'''
''' PCAN-ISA interface, channel 2
'''
Public Const PCANTP_ISABUS2 As TPCANTPHandle = &H22
'''
''' PCAN-ISA interface, channel 3
'''
Public Const PCANTP_ISABUS3 As TPCANTPHandle = &H23
'''
''' PCAN-ISA interface, channel 4
'''
Public Const PCANTP_ISABUS4 As TPCANTPHandle = &H24
'''
''' PCAN-ISA interface, channel 5
'''
Public Const PCANTP_ISABUS5 As TPCANTPHandle = &H25
'''
''' PCAN-ISA interface, channel 6
'''
Public Const PCANTP_ISABUS6 As TPCANTPHandle = &H26
'''
''' PCAN-ISA interface, channel 7
'''
Public Const PCANTP_ISABUS7 As TPCANTPHandle = &H27
'''
''' PCAN-ISA interface, channel 8
'''
Public Const PCANTP_ISABUS8 As TPCANTPHandle = &H28
'''
''' PPCAN-Dongle/LPT interface, channel 1
'''
Public Const PCANTP_DNGBUS1 As TPCANTPHandle = &H31
'''
''' PCAN-PCI interface, channel 1
'''
Public Const PCANTP_PCIBUS1 As TPCANTPHandle = &H41
'''
''' PCAN-PCI interface, channel 2
'''
Public Const PCANTP_PCIBUS2 As TPCANTPHandle = &H42
'''
''' PCAN-PCI interface, channel 3
'''
Public Const PCANTP_PCIBUS3 As TPCANTPHandle = &H43
'''
''' PCAN-PCI interface, channel 4
'''
Public Const PCANTP_PCIBUS4 As TPCANTPHandle = &H44
'''
''' PCAN-PCI interface, channel 5
'''
Public Const PCANTP_PCIBUS5 As TPCANTPHandle = &H45
'''
''' PCAN-PCI interface, channel 6
'''
Public Const PCANTP_PCIBUS6 As TPCANTPHandle = &H46
'''
''' PCAN-PCI interface, channel 7
'''
Public Const PCANTP_PCIBUS7 As TPCANTPHandle = &H47
'''
''' PCAN-PCI interface, channel 8
'''
Public Const PCANTP_PCIBUS8 As TPCANTPHandle = &H48
'''
''' PCAN-PCI interface, channel 9
'''
Public Const PCANTP_PCIBUS9 As TPCANTPHandle = &H409
'''
''' PCAN-PCI interface, channel 10
'''
Public Const PCANTP_PCIBUS10 As TPCANTPHandle = &H40A
'''
''' PCAN-PCI interface, channel 11
'''
Public Const PCANTP_PCIBUS11 As TPCANTPHandle = &H40B
'''
''' PCAN-PCI interface, channel 12
'''
Public Const PCANTP_PCIBUS12 As TPCANTPHandle = &H40C
'''
''' PCAN-PCI interface, channel 13
'''
Public Const PCANTP_PCIBUS13 As TPCANTPHandle = &H40D
'''
''' PCAN-PCI interface, channel 14
'''
Public Const PCANTP_PCIBUS14 As TPCANTPHandle = &H40E
'''
''' PCAN-PCI interface, channel 15
'''
Public Const PCANTP_PCIBUS15 As TPCANTPHandle = &H40F
'''
''' PCAN-PCI interface, channel 16
'''
Public Const PCANTP_PCIBUS16 As TPCANTPHandle = &H410
'''
''' PCAN-USB interface, channel 1
'''
Public Const PCANTP_USBBUS1 As TPCANTPHandle = &H51
'''
''' PCAN-USB interface, channel 2
'''
Public Const PCANTP_USBBUS2 As TPCANTPHandle = &H52
'''
''' PCAN-USB interface, channel 3
'''
Public Const PCANTP_USBBUS3 As TPCANTPHandle = &H53
'''
''' PCAN-USB interface, channel 4
'''
Public Const PCANTP_USBBUS4 As TPCANTPHandle = &H54
'''
''' PCAN-USB interface, channel 5
'''
Public Const PCANTP_USBBUS5 As TPCANTPHandle = &H55
'''
''' PCAN-USB interface, channel 6
'''
Public Const PCANTP_USBBUS6 As TPCANTPHandle = &H56
'''
''' PCAN-USB interface, channel 7
'''
Public Const PCANTP_USBBUS7 As TPCANTPHandle = &H57
'''
''' PCAN-USB interface, channel 8
'''
Public Const PCANTP_USBBUS8 As TPCANTPHandle = &H58
'''
''' PCAN-USB interface, channel 9
'''
Public Const PCANTP_USBBUS9 As TPCANTPHandle = &H509
'''
''' PCAN-USB interface, channel 10
'''
Public Const PCANTP_USBBUS10 As TPCANTPHandle = &H50A
'''
''' PCAN-USB interface, channel 11
'''
Public Const PCANTP_USBBUS11 As TPCANTPHandle = &H50B
'''
''' PCAN-USB interface, channel 12
'''
Public Const PCANTP_USBBUS12 As TPCANTPHandle = &H50C
'''
''' PCAN-USB interface, channel 13
'''
Public Const PCANTP_USBBUS13 As TPCANTPHandle = &H50D
'''
''' PCAN-USB interface, channel 14
'''
Public Const PCANTP_USBBUS14 As TPCANTPHandle = &H50E
'''
''' PCAN-USB interface, channel 15
'''
Public Const PCANTP_USBBUS15 As TPCANTPHandle = &H50F
'''
''' PCAN-USB interface, channel 16
'''
Public Const PCANTP_USBBUS16 As TPCANTPHandle = &H510
'''
''' PCAN-PC Card interface, channel 1
'''
Public Const PCANTP_PCCBUS1 As TPCANTPHandle = &H61
'''
''' PCAN-PC Card interface, channel 2
'''
Public Const PCANTP_PCCBUS2 As TPCANTPHandle = &H62
'''
''' PCAN-LAN interface, channel 1
'''
Public Const PCANTP_LANBUS1 As TPCANTPHandle = &H801
'''
''' PCAN-LAN interface, channel 2
'''
Public Const PCANTP_LANBUS2 As TPCANTPHandle = &H802
'''
''' PCAN-LAN interface, channel 3
'''
Public Const PCANTP_LANBUS3 As TPCANTPHandle = &H803
'''
''' PCAN-LAN interface, channel 4
'''
Public Const PCANTP_LANBUS4 As TPCANTPHandle = &H804
'''
''' PCAN-LAN interface, channel 5
'''
Public Const PCANTP_LANBUS5 As TPCANTPHandle = &H805
'''
''' PCAN-LAN interface, channel 6
'''
Public Const PCANTP_LANBUS6 As TPCANTPHandle = &H806
'''
''' PCAN-LAN interface, channel 7
'''
Public Const PCANTP_LANBUS7 As TPCANTPHandle = &H807
'''
''' PCAN-LAN interface, channel 8
'''
Public Const PCANTP_LANBUS8 As TPCANTPHandle = &H808
'''
''' PCAN-LAN interface, channel 9
'''
Public Const PCANTP_LANBUS9 As TPCANTPHandle = &H809
'''
''' PCAN-LAN interface, channel 10
'''
Public Const PCANTP_LANBUS10 As TPCANTPHandle = &H80A
'''
''' PCAN-LAN interface, channel 11
'''
Public Const PCANTP_LANBUS11 As TPCANTPHandle = &H80B
'''
''' PCAN-LAN interface, channel 12
'''
Public Const PCANTP_LANBUS12 As TPCANTPHandle = &H80C
'''
''' PCAN-LAN interface, channel 13
'''
Public Const PCANTP_LANBUS13 As TPCANTPHandle = &H80D
'''
''' PCAN-LAN interface, channel 14
'''
Public Const PCANTP_LANBUS14 As TPCANTPHandle = &H80E
'''
''' PCAN-LAN interface, channel 15
'''
Public Const PCANTP_LANBUS15 As TPCANTPHandle = &H80F
'''
''' PCAN-LAN interface, channel 16
'''
Public Const PCANTP_LANBUS16 As TPCANTPHandle = &H810
#End Region
#Region "FD Bit rate parameters"
'''
''' Clock frequency in Herz (80000000, 60000000, 40000000, 30000000, 24000000, 20000000)
'''
Public Const PCANTP_BR_CLOCK As String = "f_clock"
'''
''' Clock frequency in Megaherz (80, 60, 40, 30, 24, 20)
'''
Public Const PCANTP_BR_CLOCK_MHZ As String = "f_clock_mhz"
'''
''' Clock prescaler for nominal time quantum
'''
Public Const PCANTP_BR_NOM_BRP As String = "nom_brp"
'''
''' TSEG1 segment for nominal bit rate in time quanta
'''
Public Const PCANTP_BR_NOM_TSEG1 As String = "nom_tseg1"
'''
''' TSEG2 segment for nominal bit rate in time quanta
'''
Public Const PCANTP_BR_NOM_TSEG2 As String = "nom_tseg2"
'''
''' Synchronization Jump Width for nominal bit rate in time quanta
'''
Public Const PCANTP_BR_NOM_SJW As String = "nom_sjw"
'''
''' Sample point for nominal bit rate
'''
Public Const PCANTP_BR_NOM_SAMPLE As String = "nom_sam"
'''
''' Clock prescaler for highspeed data time quantum
'''
Public Const PCANTP_BR_DATA_BRP As String = "data_brp"
'''
''' TSEG1 segment for fast data bit rate in time quanta
'''
Public Const PCANTP_BR_DATA_TSEG1 As String = "data_tseg1"
'''
''' TSEG2 segment for fast data bit rate in time quanta
'''
Public Const PCANTP_BR_DATA_TSEG2 As String = "data_tseg2"
'''
''' Synchronization Jump Width for highspeed data bit rate in time quanta
'''
Public Const PCANTP_BR_DATA_SJW As String = "data_sjw"
'''
''' Secondary sample point delay for highspeed data bit rate in cyles
'''
Public Const PCANTP_BR_DATA_SAMPLE As String = "data_ssp_offset"
#End Region
#Region "Parameter values definition"
'''
''' No debug messages
'''
Public Const PCANTP_DEBUG_NONE As Byte = 0
'''
''' Puts CAN debug messages to stdout
'''
Public Const PCANTP_DEBUG_CAN As Byte = 1
'''
''' The Channel is illegal or not available
'''
Public Const PCANTP_CHANNEL_UNAVAILABLE As Byte = 0
'''
''' The Channel is available
'''
Public Const PCANTP_CHANNEL_AVAILABLE As Byte = 1
'''
''' The Channel is valid, and is being used
'''
Public Const PCANTP_CHANNEL_OCCUPIED As Byte = 2
'''
''' 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 = 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
'''
''' Disable reception of unformatted (NON-ISO-TP) CAN frames (default):
''' only ISO 15765 messages will be received
'''
Public Const PCANTP_CAN_UNSEGMENTED_OFF = &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_CAN_UNSEGMENTED_ON = &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_CAN_UNSEGMENTED_ALL_FRAMES = &H2
'''
''' Default priority for ISO-TP messages (only available for normal fixed, mixed And enhanced addressing)
'''
Public Const PCANTP_J1939_PRIORITY_DEFAULT = &H6
'''
''' Mask to retrieve the CAN ID type
'''
Public Const PCANTP_ID_CAN_MASK = &HF
'''
''' Mask to check if the priority field is set
'''
Public Const PCANTP_ID_CAN_IS_PRIORITY_MASK = &H10
'''
''' Mask to retrieve the J1939 priority
'''
Public Const PCANTP_ID_CAN_PRIORITY_MASK = &HE0
'''
''' Constant defining that no CAN ID mapping exists
'''
Public Const CAN_ID_NO_MAPPING As UInt32 = UInt32.MaxValue '&HFFFFFFFF
'''
''' max data length prior ISO 15765-2:2016 update
'''
Public Const PCANTP_MESSAGE_MAX_LENGTH As UInt32 = &HFFF
#End Region
#Region "PCAN ISO-TP API Implementation"
'''
''' Initializes a PCANTP-Client based on a CANTP Channel
'''
''' 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 TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function Initialize(
ByVal CanChannel As TPCANTPHandle,
ByVal Baudrate As TPCANTPBaudrate,
ByVal HwType As TPCANTPHWType,
ByVal IOPort As UInt32,
ByVal Interrupt As UInt16) As TPCANTPStatus
End Function
'''
''' Initializes a PCANTP-Client based on a CANTP Channel
'''
''' Only one PCANTP-Client can be initialized per CAN-Channel
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function Initialize(
ByVal CanChannel As TPCANTPHandle,
ByVal Baudrate As TPCANTPBaudrate)
Return Initialize(CanChannel, Baudrate, 0, 0, 0)
End Function
'''
''' Initializes a PCANTP-Client based on a CANTP Channel with FD support
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The speed for the communication (FD bit rate string)
''' Only one PCANTP-Client can be initialized per CAN-Channel
''' See PCANTP_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_samp
''' f_clock_mhz=80, nom_brp=1, nom_tseg1=63, nom_tseg2=16, nom_sjw=7, data_brp=4, data_tseg1=12, data_tseg2=7, data_sjw=1
''' A TPCANTPStatus code. PCANTP_ERROR_OK Is returned on success
Public Shared Function InitializeFD(
ByVal CanChannel As TPCANTPHandle,
ByVal BitrateFD As TPCANTPBitrateFD) As TPCANTPStatus
End Function
'''
''' Uninitializes a PCANTP-Client initialized before
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function Uninitialize(
ByVal CanChannel As TPCANTPHandle) As TPCANTPStatus
End Function
'''
''' Resets the receive and transmit queues of a PCANTP-Client
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function Reset(
ByVal CanChannel As TPCANTPHandle) As TPCANTPStatus
End Function
'''
''' Gets information about the internal BUS status of a PCANTP-Channel.
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function GetStatus(
ByVal CanChannel As TPCANTPHandle) As TPCANTPStatus
End Function
'''
''' Reads a PCANTP message from the receive queue of a PCANTP-Client
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A TPCANTPMsg structure buffer to store the PUDS message
''' "A TPCANTPTimestamp structure buffer to get
''' the reception time of the message. If this value is not desired, this parameter
''' should be passed as NULL"
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function Read(
ByVal CanChannel As TPCANTPHandle,
ByRef MessageBuffer As TPCANTPMsg,
ByRef TimestampBuffer As TPCANTPTimestamp) As TPCANTPStatus
End Function
Private Shared Function Read(
ByVal CanChannel As TPCANTPHandle,
ByRef MessageBuffer As TPCANTPMsg,
ByVal TimestampBuffer As IntPtr) As TPCANTPStatus
End Function
'''
''' Reads a PCANTP message from the receive queue of a PCANTP-Client
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A TPCANTPMsg structure buffer to store the PUDS message
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function Read(
ByVal CanChannel As TPCANTPHandle,
ByRef MessageBuffer As TPCANTPMsg) As TPCANTPStatus
Return Read(CanChannel, MessageBuffer, IntPtr.Zero)
End Function
'''
''' Transmits a PCANTP message
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' A TPCANTPMsg buffer with the message to be sent
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function Write(
ByVal CanChannel As TPCANTPHandle,
ByRef MessageBuffer As TPCANTPMsg) As TPCANTPStatus
End Function
'''
''' Retrieves a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The TPCANTPParameter parameter to get
''' Buffer for the parameter value
''' Size in bytes of the buffer
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function GetValue(
ByVal CanChannel As TPCANTPHandle,
ByVal Parameter As TPCANTPParameter,
ByVal StringBuffer As StringBuilder,
ByVal BufferLength As UInt32) As TPCANTPStatus
End Function
'''
''' Retrieves a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The TPCANTPParameter parameter to get
''' Buffer for the parameter value
''' Size in bytes of the buffer
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function GetValue(
ByVal CanChannel As TPCANTPHandle,
ByVal Parameter As TPCANTPParameter,
ByRef NumericBuffer As UInt32,
ByVal BufferLength As UInt32) As TPCANTPStatus
End Function
'''
''' Retrieves a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The TPCANTPParameter parameter to get
''' Buffer for the parameter value
''' Size in bytes of the buffer
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function GetValue(
ByVal CanChannel As TPCANTPHandle,
ByVal Parameter As TPCANTPParameter,
ByVal Buffer As Byte(),
ByVal BufferLength As UInt32) As TPCANTPStatus
End Function
'''
''' Configures or sets a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The TPCANTPParameter parameter to set
''' Buffer with the value to be set
''' Size in bytes of the buffer
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function SetValue(
ByVal CanChannel As TPCANTPHandle,
ByVal Parameter As TPCANTPParameter,
ByRef NumericBuffer As UInt32,
ByVal BufferLength As UInt32) As TPCANTPStatus
End Function
'''
''' Configures or sets a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The TPCANTPParameter parameter to set
''' Buffer with the value to be set
''' Size in bytes of the buffer
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function SetValue(
ByVal CanChannel As TPCANTPHandle,
ByVal Parameter As TPCANTPParameter,
ByVal StringBuffer As String,
ByVal BufferLength As UInt32) As TPCANTPStatus
End Function
'''
''' Configures or sets a PCANTP-Client value
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The TPCANTPParameter parameter to set
''' Buffer with the value to be set
''' Size in bytes of the buffer
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function SetValue(
ByVal CanChannel As TPCANTPHandle,
ByVal Parameter As TPCANTPParameter,
ByVal Buffer As Byte(),
ByVal BufferLength As UInt32) As TPCANTPStatus
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_FORMAT_NORMAL or PCANTP_FORMAT_EXTENDED).
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The CAN ID to map
''' The CAN ID mapped response
''' CAN ID Type (11 or 29 bits, see PCANTP_ID_CAN_XXX)
''' Addressing format (see PCANTP_FORMAT_XXX)
''' Message type (remote or diagnostic, see PCANTP_MESSAGE_XXX)
''' Source Address
''' Target Address
''' Target Addressing Type (physical or functional, see PCANTP_ADDRESSING_XXX)
''' Address extension or Remote address
''' A TPCANTPStatus code : PCANTP_ERROR_OK is returned on success,
''' PCANTP_ERROR_WRONG_PARAM states invalid Network Address Information parameters.
Public Shared Function AddMapping(
ByVal CanChannel As TPCANTPHandle,
ByVal canID As UInt32,
ByVal canIDResponse As UInt32,
ByVal canIdType As TPCANTPIdType,
ByVal formatType As TPCANTPFormatType,
ByVal msgType As TPCANTPMessageType,
ByVal sourceAddr As Byte,
ByVal targetAddr As Byte,
ByVal targetType As TPCANTPAddressingType,
ByVal remoteAddr As Byte) As TPCANTPStatus
End Function
'''
''' Removes a user-defined PCAN-TP mapping between CAN ID and Network Address Information
'''
''' A PCANTP Channel Handle representing a PCANTP-Client
''' The mapped CAN ID to remove
''' A TPCANTPStatus code. PCANTP_ERROR_OK is returned on success
Public Shared Function RemoveMapping(
ByVal CanChannel As TPCANTPHandle,
ByVal canID As UInt32) As TPCANTPStatus
End Function
'''
''' Returns a descriptive text of a given TPCANTPStatus 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 TPCANTPStatus error code
''' Indicates a 'Primary language ID'
''' Buffer for the text (must be at least 256 in length)
''' A TPCANTPStatus error code
Public Shared Function GetErrorText(
ByVal anError As TPCANTPStatus,
ByVal Language As UInt16,
ByVal StringBuffer As StringBuilder) As TPCANTPStatus
End Function
#End Region
End Class
#End Region
End Namespace