PCAN_LOG_LOCATION = TPCANParameter(0x09) # Directory path for log files
PCAN_LOG_STATUS = TPCANParameter(0x0A) # Debug-Log activation status
PCAN_LOG_CONFIGURE = TPCANParameter(0x0B) # Configuration of the debugged information (LOG_FUNCTION_***)
PCAN_LOG_TEXT = TPCANParameter(0x0C) # Custom insertion of text into the log file
PCAN_CHANNEL_CONDITION = TPCANParameter(0x0D) # Availability status of a PCAN-Channel
PCAN_HARDWARE_NAME = TPCANParameter(0x0E) # PCAN hardware name parameter
PCAN_RECEIVE_STATUS = TPCANParameter(0x0F) # Message reception status of a PCAN-Channel
PCAN_CONTROLLER_NUMBER = TPCANParameter(0x10) # CAN-Controller number of a PCAN-Channel
PCAN_TRACE_LOCATION = TPCANParameter(0x11) # Directory path for PCAN trace files
PCAN_TRACE_STATUS = TPCANParameter(0x12) # CAN tracing activation status
PCAN_TRACE_SIZE = TPCANParameter(0x13) # Configuration of the maximum file size of a CAN trace
PCAN_TRACE_CONFIGURE = TPCANParameter(0x14) # Configuration of the trace file storing mode (TRACE_FILE_***)
PCAN_CHANNEL_IDENTIFYING = TPCANParameter(
0x15) # Physical identification of a USB based PCAN-Channel by blinking its associated LED
PCAN_CHANNEL_FEATURES = TPCANParameter(0x16) # Capabilities of a PCAN device (FEATURE_***)
PCAN_BITRATE_ADAPTING = TPCANParameter(0x17) # Using of an existing bit rate (PCAN-View connected to a channel)
PCAN_BITRATE_INFO = TPCANParameter(0x18) # Configured bit rate as Btr0Btr1 value
PCAN_BITRATE_INFO_FD = TPCANParameter(0x19) # Configured bit rate as TPCANBitrateFD string
PCAN_BUSSPEED_NOMINAL = TPCANParameter(0x1A) # Configured nominal CAN Bus speed as Bits per seconds
PCAN_BUSSPEED_DATA = TPCANParameter(0x1B) # Configured CAN data speed as Bits per seconds
PCAN_IP_ADDRESS = TPCANParameter(0x1C) # Remote address of a LAN channel as string in IPv4 format
PCAN_LAN_SERVICE_STATUS = TPCANParameter(0x1D) # Status of the Virtual PCAN-Gateway Service
# PCAN parameter values
#
PCAN_PARAMETER_OFF = int(0x00) # The PCAN parameter is not set (inactive)
PCAN_PARAMETER_ON = int(0x01) # The PCAN parameter is set (active)
PCAN_FILTER_CLOSE = int(0x00) # The PCAN filter is closed. No messages will be received
PCAN_FILTER_OPEN = int(0x01) # The PCAN filter is fully opened. All messages will be received
PCAN_FILTER_CUSTOM = int(0x02) # The PCAN filter is custom configured. Only registered messages will be received
PCAN_CHANNEL_UNAVAILABLE = int(0x00) # The PCAN-Channel handle is illegal, or its associated hardware is not available
PCAN_CHANNEL_AVAILABLE = int(
0x01) # The PCAN-Channel handle is available to be connected (Plug&Play Hardware: it means furthermore that the hardware is plugged-in)
PCAN_CHANNEL_OCCUPIED = int(0x02) # The PCAN-Channel handle is valid, and is already being used
PCAN_CHANNEL_PCANVIEW = PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED # The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect
LOG_FUNCTION_DEFAULT = int(0x00) # Logs system exceptions / errors
LOG_FUNCTION_ENTRY = int(0x01) # Logs the entries to the PCAN-Basic API functions
LOG_FUNCTION_PARAMETERS = int(0x02) # Logs the parameters passed to the PCAN-Basic API functions
LOG_FUNCTION_LEAVE = int(0x04) # Logs the exits from the PCAN-Basic API functions
LOG_FUNCTION_WRITE = int(0x08) # Logs the CAN messages passed to the CAN_Write function
LOG_FUNCTION_READ = int(0x10) # Logs the CAN messages received within the CAN_Read function
LOG_FUNCTION_ALL = int(0xFFFF) # Logs all possible information within the PCAN-Basic API functions
TRACE_FILE_SINGLE = int(0x00) # A single file is written until it size reaches PAN_TRACE_SIZE
TRACE_FILE_SEGMENTED = int(0x01) # Traced data is distributed in several files with size PAN_TRACE_SIZE
TRACE_FILE_DATE = int(0x02) # Includes the date into the name of the trace file
TRACE_FILE_TIME = int(0x04) # Includes the start time into the name of the trace file
TRACE_FILE_OVERWRITE = int(0x80) # Causes the overwriting of available traces (same name)
res = self.__m_dllBasic.CAN_InitializeFD(Channel, BitrateFD)
return TPCANStatus(res)
except:
print("Exception on PCANBasic.InitializeFD")
raise
# Uninitializes one or all PCAN Channels initialized by CAN_Initialize
#
def Uninitialize(
self,
Channel):
"""
Uninitializes one or all PCAN Channels initialized by CAN_Initialize
Remarks:
Giving the TPCANHandle value "PCAN_NONEBUS", uninitialize all initialized channels
Parameters:
Channel : A TPCANHandle representing a PCAN Channel
Returns:
A TPCANStatus error code
"""
try:
res = self.__m_dllBasic.CAN_Uninitialize(Channel)
return TPCANStatus(res)
except:
print("Exception on PCANBasic.Uninitialize")
raise
# Resets the receive and transmit queues of the PCAN Channel
#
def Reset(
self,
Channel):
"""
Resets the receive and transmit queues of the PCAN Channel
Remarks:
A reset of the CAN controller is not performed
Parameters:
Channel : A TPCANHandle representing a PCAN Channel
Returns:
A TPCANStatus error code
"""
try:
res = self.__m_dllBasic.CAN_Reset(Channel)
return TPCANStatus(res)
except:
print("Exception on PCANBasic.Reset")
raise
# Gets the current status of a PCAN Channel
#
def GetStatus(
self,
Channel):
"""
Gets the current status of a PCAN Channel
Parameters:
Channel : A TPCANHandle representing a PCAN Channel
Returns:
A TPCANStatus error code
"""
try:
res = self.__m_dllBasic.CAN_GetStatus(Channel)
return TPCANStatus(res)
except:
print("Exception on PCANBasic.GetStatus")
raise
# Reads a CAN message from the receive queue of a PCAN Channel
#
def Read(
self,
Channel):
"""
Reads a CAN message from the receive queue of a PCAN Channel
Remarks:
The return value of this method is a 3-touple, where
the first value is the result (TPCANStatus) of the method.
The order of the values are:
[0]: A TPCANStatus error code
[1]: A TPCANMsg structure with the CAN message read
[2]: A TPCANTimestamp structure with the time when a message was read
Parameters:
Channel : A TPCANHandle representing a PCAN Channel
Returns:
A touple with three values
"""
try:
msg = TPCANMsg()
timestamp = TPCANTimestamp()
res = self.__m_dllBasic.CAN_Read(Channel, byref(msg), byref(timestamp))
return TPCANStatus(res), msg, timestamp
except:
print("Exception on PCANBasic.Read")
raise
# Reads a CAN message from the receive queue of a FD capable PCAN Channel
#
def ReadFD(
self,
Channel):
"""
Reads a CAN message from the receive queue of a FD capable PCAN Channel
Remarks:
The return value of this method is a 3-touple, where
the first value is the result (TPCANStatus) of the method.
The order of the values are:
[0]: A TPCANStatus error code
[1]: A TPCANMsgFD structure with the CAN message read
[2]: A TPCANTimestampFD that is the time when a message was read
Parameters:
Channel : The handle of a FD capable PCAN Channel
Returns:
A touple with three values
"""
try:
msg = TPCANMsgFD()
timestamp = TPCANTimestampFD()
res = self.__m_dllBasic.CAN_ReadFD(Channel, byref(msg), byref(timestamp))
return TPCANStatus(res), msg, timestamp
except:
print("Exception on PCANBasic.ReadFD")
raise
# Transmits a CAN message
#
def Write(
self,
Channel,
MessageBuffer):
"""
Transmits a CAN message
Parameters:
Channel : A TPCANHandle representing a PCAN Channel
MessageBuffer: A TPCANMsg representing the CAN message to be sent
Returns:
A TPCANStatus error code
"""
try:
res = self.__m_dllBasic.CAN_Write(Channel, byref(MessageBuffer))
return TPCANStatus(res)
except:
print("Exception on PCANBasic.Write")
raise
# Transmits a CAN message over a FD capable PCAN Channel
#
def WriteFD(
self,
Channel,
MessageBuffer):
"""
Transmits a CAN message over a FD capable PCAN Channel
Parameters:
Channel : The handle of a FD capable PCAN Channel
MessageBuffer: A TPCANMsgFD buffer with the message to be sent
Returns:
A TPCANStatus error code
"""
try:
res = self.__m_dllBasic.CAN_WriteFD(Channel, byref(MessageBuffer))
return TPCANStatus(res)
except:
print("Exception on PCANBasic.WriteFD")
raise
# Configures the reception filter
#
def FilterMessages(
self,
Channel,
FromID,
ToID,
Mode):
"""
Configures the reception filter
Remarks:
The message filter will be expanded with every call to this function.
If it is desired to reset the filter, please use the 'SetValue' function.
Parameters:
Channel : A TPCANHandle representing a PCAN Channel
FromID : A c_uint value with the lowest CAN ID to be received
ToID : A c_uint value with the highest CAN ID to be received
Mode : A TPCANMode representing the message type (Standard, 11-bit
identifier, or Extended, 29-bit identifier)
Returns:
A TPCANStatus error code
"""
try:
res = self.__m_dllBasic.CAN_FilterMessages(Channel, FromID, ToID, Mode)
return TPCANStatus(res)
except:
print("Exception on PCANBasic.FilterMessages")
raise
# Retrieves a PCAN Channel value
#
def GetValue(
self,
Channel,
Parameter):
"""
Retrieves a PCAN Channel value
Remarks:
Parameters can be present or not according with the kind
of Hardware (PCAN Channel) being used. If a parameter is not available,
a PCAN_ERROR_ILLPARAMTYPE error will be returned.
The return value of this method is a 2-touple, where
the first value is the result (TPCANStatus) of the method and
the second one, the asked value
Parameters:
Channel : A TPCANHandle representing a PCAN Channel
Parameter : The TPCANParameter parameter to get
Returns:
A touple with 2 values
"""
try:
if Parameter == PCAN_API_VERSION or Parameter == PCAN_HARDWARE_NAME or Parameter == PCAN_CHANNEL_VERSION or Parameter == PCAN_LOG_LOCATION or Parameter == PCAN_TRACE_LOCATION or Parameter == PCAN_BITRATE_INFO_FD or Parameter == PCAN_IP_ADDRESS:
mybuffer = create_string_buffer(256)
else:
mybuffer = c_int(0)
res = self.__m_dllBasic.CAN_GetValue(Channel, Parameter, byref(mybuffer), sizeof(mybuffer))