From a04155be8c28dd9cd386da0e863cc7de092bf8fc Mon Sep 17 00:00:00 2001 From: Christian Sueltrop Date: Wed, 2 Oct 2013 12:17:32 +0200 Subject: [PATCH] Bugfix: Path to PCANBasic was not correct. Now using a relative path to the sub directory. --- .project | 17 + .pydevproject | 12 + .settings/org.eclipse.core.resources.prefs | 6 + CANLibrary/example.py | 163 +-- PCANBasic/PCANBasic.py | 1134 ++++++++++---------- PCANBasic/PCANBasic.pyc | Bin 14926 -> 14948 bytes pycrc/crc_algorithms.pyc | Bin 5880 -> 5916 bytes pycrc/crc_lexer.pyc | Bin 6945 -> 6993 bytes pycrc/crc_models.pyc | Bin 5051 -> 5067 bytes pycrc/crc_opt.pyc | Bin 11745 -> 11777 bytes pycrc/crc_parser.pyc | Bin 8714 -> 8786 bytes pycrc/crc_symtable.pyc | Bin 37808 -> 37868 bytes pycrc/pycrc.pyc | Bin 6939 -> 6939 bytes 13 files changed, 685 insertions(+), 647 deletions(-) create mode 100644 .project create mode 100644 .pydevproject create mode 100644 .settings/org.eclipse.core.resources.prefs diff --git a/.project b/.project new file mode 100644 index 0000000..3b2674a --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + CANLibrary + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 0000000..546e447 --- /dev/null +++ b/.pydevproject @@ -0,0 +1,12 @@ + + + + +Default +python 2.7 + +/CANLibrary +/CANLibrary/PCANBasic +/CANLibrary/pycrc + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..77d664b --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//CANLibrary/CanMessage.py=UTF-8 +encoding//CANLibrary/CanSignal.py=UTF-8 +encoding//CANLibrary/PCan.py=UTF-8 +encoding//CANLibrary/example.py=UTF-8 +encoding//pycrc/crc_algorithms.py=latin1 diff --git a/CANLibrary/example.py b/CANLibrary/example.py index d4fa956..3debfd4 100644 --- a/CANLibrary/example.py +++ b/CANLibrary/example.py @@ -1,80 +1,83 @@ -# -*- coding: UTF-8 -*- - -''' -Example for creating and sending CAN messages via PCAN using the CanMessage, CanSignal and PCan classes. - -@author: Christian Sültrop -''' - -from CanMessage import CanMessage -from CanSignal import CanSignal -from PCan import PcanAdapter -import time - -print '\nCreate a PCAN adapter' -pcan = PcanAdapter(PcanAdapter.Baudrate['500k']) -pcan.initialize() - -print '\ncreate some messages' -mMotor_1 = CanMessage(0x280, 8, 10, 'mMotor_1') -pcan.addMessage(mMotor_1) -print 'mMotor_1.Data', pcan.Messages['mMotor_1'].Data - -mMotor_2 = CanMessage(0x288, 8, 20, 'mMotor_2') -pcan.addMessage(mMotor_2) -print 'mMotor_2.Data', pcan.Messages['mMotor_2'].Data - -print '\ncreate some Signals' -# for mMotor_1 -MO1_Leergas = CanSignal(0, 1, 0, 1, 1, 'MO1_Leergas') -MO1_Sta_Pedal = CanSignal(1, 1, 0, 1, 1, 'MO1_Sta_Pedal') -MO1_Mo_m_ex = CanSignal(8, 8, 0, 1, 0, 'MO1_Mo_m_ex') -value = 3000 -MO1_Drehzahl = CanSignal(16, 16, 0, 0.25, value, 'MO1_Drehzahl') # split into two bytes - -print '\nadd Signals to the Messages' -pcan.Messages['mMotor_1'].addSignal(MO1_Leergas) -pcan.Messages['mMotor_1'].addSignal(MO1_Sta_Pedal) -pcan.Messages['mMotor_1'].addSignal(MO1_Mo_m_ex) -pcan.Messages['mMotor_1'].addSignal(MO1_Drehzahl) -print "pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].Data", pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].Data - - -# for mMotor_2 -MO2_Kuehlm_T = CanSignal(8, 8, -48, 0.75, 60, 'MO2_Kuehlm_T') -pcan.Messages['mMotor_2'].addSignal( MO2_Kuehlm_T ) -pcan.Messages['mMotor_2'].addSignal( CanSignal(24, 8, 0, 1, 0, 'MO2_GRA_Soll') ) -pcan.Messages['mMotor_2'].addSignal( CanSignal(0, 6, 0, 1, 44, 'MO2_CAN_Vers') ) - -print '\nManipulate Signals' -pcan.Messages['mMotor_1'].Signals['MO1_Leergas'].SetData( 0 ) - -print '\nSend the messages' -pcan.Messages['mMotor_1'].composeData() -print 'mMotor_1.Data', pcan.Messages['mMotor_1'].Data -pcan.sendMessage(pcan.Messages['mMotor_1']) - -pcan.Messages['mMotor_2'].composeData() -print 'mMotor_2.Data', pcan.Messages['mMotor_2'].Data -pcan.sendMessage(pcan.Messages['mMotor_2']) - -# receive messages, if the signal MO1_Drehzahl has changed, print the new value -while True: - pcan.sendMessage(pcan.Messages['mMotor_2']) - dataOld = pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].GetData() - pcan.receiveMessage() - if pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].GetData() != dataOld: - print 'mMotor_1.Data', pcan.Messages['mMotor_1'].Data - print 'GetData()', pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].GetData() - time.sleep(0.01) - - -# wait a while to make sure messages can be sent and end -time.sleep(1) -print 'end of program' - - - - - - +# -*- coding: UTF-8 -*- + +''' +Example for creating and sending CAN messages via PCAN using the CanMessage, CanSignal and PCan classes. + +@author: Christian Sültrop +''' + +from CanMessage import CanMessage +from CanSignal import CanSignal +from PCan import PcanAdapter +import time + +print '\nCreate a PCAN adapter' +pcan = PcanAdapter(PcanAdapter.Baudrate['500k']) +pcan.initialize() + +print '\ncreate some messages' +mMotor_1 = CanMessage(0x280, 8, 10, 'mMotor_1') +pcan.addMessage(mMotor_1) +print 'mMotor_1.Data', pcan.Messages['mMotor_1'].Data + +mMotor_2 = CanMessage(0x288, 8, 20, 'mMotor_2') +pcan.addMessage(mMotor_2) +print 'mMotor_2.Data', pcan.Messages['mMotor_2'].Data + +print '\ncreate some Signals' +# for mMotor_1 +MO1_Leergas = CanSignal(0, 1, 0, 1, 1, 'MO1_Leergas') +MO1_Sta_Pedal = CanSignal(1, 1, 0, 1, 1, 'MO1_Sta_Pedal') +MO1_Mo_m_ex = CanSignal(8, 8, 0, 1, 0, 'MO1_Mo_m_ex') +value = 3000 +MO1_Drehzahl = CanSignal(16, 16, 0, 0.25, value, 'MO1_Drehzahl') # split into two bytes + +print '\nadd Signals to the Messages' +pcan.Messages['mMotor_1'].addSignal(MO1_Leergas) +pcan.Messages['mMotor_1'].addSignal(MO1_Sta_Pedal) +pcan.Messages['mMotor_1'].addSignal(MO1_Mo_m_ex) +pcan.Messages['mMotor_1'].addSignal(MO1_Drehzahl) +print "pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].Data", pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].Data + + +# for mMotor_2 +MO2_Kuehlm_T = CanSignal(8, 8, -48, 0.75, 60, 'MO2_Kuehlm_T') +pcan.Messages['mMotor_2'].addSignal( MO2_Kuehlm_T ) +pcan.Messages['mMotor_2'].addSignal( CanSignal(24, 8, 0, 1, 0, 'MO2_GRA_Soll') ) +pcan.Messages['mMotor_2'].addSignal( CanSignal(0, 6, 0, 1, 44, 'MO2_CAN_Vers') ) + +print '\nManipulate Signals' +pcan.Messages['mMotor_1'].Signals['MO1_Leergas'].SetData( 0 ) + +print '\nSend the messages' +pcan.Messages['mMotor_1'].composeData() +print 'mMotor_1.Data', pcan.Messages['mMotor_1'].Data +pcan.sendMessage(pcan.Messages['mMotor_1']) + +pcan.Messages['mMotor_2'].composeData() +print 'mMotor_2.Data', pcan.Messages['mMotor_2'].Data +pcan.sendMessage(pcan.Messages['mMotor_2']) + +# receive messages, if the signal MO1_Drehzahl has changed, print the new value +while True: + #print 'send' + pcan.sendMessage(pcan.Messages['mMotor_2']) + dataOld = pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].GetData() + + #print 'receive' + pcan.receiveMessage() + if pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].GetData() != dataOld: + print 'mMotor_1.Data', pcan.Messages['mMotor_1'].Data + print 'GetData()', pcan.Messages['mMotor_1'].Signals['MO1_Drehzahl'].GetData() + time.sleep(0.01) + + +# wait a while to make sure messages can be sent and end +time.sleep(1) +print 'end of program' + + + + + + diff --git a/PCANBasic/PCANBasic.py b/PCANBasic/PCANBasic.py index 3952fa1..bafa69e 100644 --- a/PCANBasic/PCANBasic.py +++ b/PCANBasic/PCANBasic.py @@ -1,567 +1,567 @@ -# PCANBasic.py -# -# ~~~~~~~~~~~~ -# -# PCAN-Basic API -# -# ~~~~~~~~~~~~ -# -# ------------------------------------------------------------------ -# Author : Keneth Wagner -# Last change: 08.11.2011 Wagner -# -# Language: Python 2.6 -# ------------------------------------------------------------------ -# -# Copyright (C) 1999-2012 PEAK-System Technik GmbH, Darmstadt -# more Info at http://www.peak-system.com -# - -# Module Imports -# -from ctypes import * - -#/////////////////////////////////////////////////////////// -# Type definitions -#/////////////////////////////////////////////////////////// - -TPCANHandle = c_ubyte # Represents a PCAN hardware channel handle -TPCANStatus = int # Represents a PCAN status/error code -TPCANParameter = c_ubyte # Represents a PCAN parameter to be read or set -TPCANDevice = c_ubyte # Represents a PCAN device -TPCANMessageType = c_ubyte # Represents the type of a PCAN message -TPCANType = c_ubyte # Represents the type of PCAN hardware to be initialized -TPCANMode = c_ubyte # Represents a PCAN filter mode -TPCANBaudrate = c_ushort # Represents a PCAN Baud rate register value - -#/////////////////////////////////////////////////////////// -# Value definitions -#/////////////////////////////////////////////////////////// - -# Currently defined and supported PCAN channels -# -PCAN_NONEBUS = TPCANHandle(0x00) # Undefined/default value for a PCAN bus - -PCAN_ISABUS1 = TPCANHandle(0x21) # PCAN-ISA interface, channel 1 -PCAN_ISABUS2 = TPCANHandle(0x22) # PCAN-ISA interface, channel 2 -PCAN_ISABUS3 = TPCANHandle(0x23) # PCAN-ISA interface, channel 3 -PCAN_ISABUS4 = TPCANHandle(0x24) # PCAN-ISA interface, channel 4 -PCAN_ISABUS5 = TPCANHandle(0x25) # PCAN-ISA interface, channel 5 -PCAN_ISABUS6 = TPCANHandle(0x26) # PCAN-ISA interface, channel 6 -PCAN_ISABUS7 = TPCANHandle(0x27) # PCAN-ISA interface, channel 7 -PCAN_ISABUS8 = TPCANHandle(0x28) # PCAN-ISA interface, channel 8 - -PCAN_DNGBUS1 = TPCANHandle(0x31) # PCAN-Dongle/LPT interface, channel 1 - -PCAN_PCIBUS1 = TPCANHandle(0x41) # PCAN-PCI interface, channel 1 -PCAN_PCIBUS2 = TPCANHandle(0x42) # PCAN-PCI interface, channel 2 -PCAN_PCIBUS3 = TPCANHandle(0x43) # PCAN-PCI interface, channel 3 -PCAN_PCIBUS4 = TPCANHandle(0x44) # PCAN-PCI interface, channel 4 -PCAN_PCIBUS5 = TPCANHandle(0x45) # PCAN-PCI interface, channel 5 -PCAN_PCIBUS6 = TPCANHandle(0x46) # PCAN-PCI interface, channel 6 -PCAN_PCIBUS7 = TPCANHandle(0x47) # PCAN-PCI interface, channel 7 -PCAN_PCIBUS8 = TPCANHandle(0x48) # PCAN-PCI interface, channel 8 - -PCAN_USBBUS1 = TPCANHandle(0x51) # PCAN-USB interface, channel 1 -PCAN_USBBUS2 = TPCANHandle(0x52) # PCAN-USB interface, channel 2 -PCAN_USBBUS3 = TPCANHandle(0x53) # PCAN-USB interface, channel 3 -PCAN_USBBUS4 = TPCANHandle(0x54) # PCAN-USB interface, channel 4 -PCAN_USBBUS5 = TPCANHandle(0x55) # PCAN-USB interface, channel 5 -PCAN_USBBUS6 = TPCANHandle(0x56) # PCAN-USB interface, channel 6 -PCAN_USBBUS7 = TPCANHandle(0x57) # PCAN-USB interface, channel 7 -PCAN_USBBUS8 = TPCANHandle(0x58) # PCAN-USB interface, channel 8 - -PCAN_PCCBUS1 = TPCANHandle(0x61) # PCAN-PC Card interface, channel 1 -PCAN_PCCBUS2 = TPCANHandle(0x62) # PCAN-PC Card interface, channel 2 - -# Represent the PCAN error and status codes -# -PCAN_ERROR_OK = TPCANStatus(0x00000) # No error -PCAN_ERROR_XMTFULL = TPCANStatus(0x00001) # Transmit buffer in CAN controller is full -PCAN_ERROR_OVERRUN = TPCANStatus(0x00002) # CAN controller was read too late -PCAN_ERROR_BUSLIGHT = TPCANStatus(0x00004) # Bus error: an error counter reached the 'light' limit -PCAN_ERROR_BUSHEAVY = TPCANStatus(0x00008) # Bus error: an error counter reached the 'heavy' limit -PCAN_ERROR_BUSOFF = TPCANStatus(0x00010) # Bus error: the CAN controller is in bus-off state -PCAN_ERROR_ANYBUSERR = TPCANStatus(PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF) # Mask for all bus errors -PCAN_ERROR_QRCVEMPTY = TPCANStatus(0x00020) # Receive queue is empty -PCAN_ERROR_QOVERRUN = TPCANStatus(0x00040) # Receive queue was read too late -PCAN_ERROR_QXMTFULL = TPCANStatus(0x00080) # Transmit queue is full -PCAN_ERROR_REGTEST = TPCANStatus(0x00100) # Test of the CAN controller hardware registers failed (no hardware found) -PCAN_ERROR_NODRIVER = TPCANStatus(0x00200) # Driver not loaded -PCAN_ERROR_HWINUSE = TPCANStatus(0x00400) # Hardware already in use by a Net -PCAN_ERROR_NETINUSE = TPCANStatus(0x00800) # A Client is already connected to the Net -PCAN_ERROR_ILLHW = TPCANStatus(0x01400) # Hardware handle is invalid -PCAN_ERROR_ILLNET = TPCANStatus(0x01800) # Net handle is invalid -PCAN_ERROR_ILLCLIENT = TPCANStatus(0x01C00) # Client handle is invalid -PCAN_ERROR_ILLHANDLE = TPCANStatus(PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) # Mask for all handle errors -PCAN_ERROR_RESOURCE = TPCANStatus(0x02000) # Resource (FIFO, Client, timeout) cannot be created -PCAN_ERROR_ILLPARAMTYPE = TPCANStatus(0x04000) # Invalid parameter -PCAN_ERROR_ILLPARAMVAL = TPCANStatus(0x08000) # Invalid parameter value -PCAN_ERROR_UNKNOWN = TPCANStatus(0x10000) # Unknow error -PCAN_ERROR_ILLDATA = TPCANStatus(0x20000) # Invalid data, function, or action -PCAN_ERROR_INITIALIZE = TPCANStatus(0x40000) # Channel is not initialized - -# PCAN devices -# -PCAN_NONE = TPCANDevice(0x00) # Undefined, unknown or not selected PCAN device value -PCAN_PEAKCAN = TPCANDevice(0x01) # PCAN Non-Plug&Play devices. NOT USED WITHIN PCAN-Basic API -PCAN_ISA = TPCANDevice(0x02) # PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus -PCAN_DNG = TPCANDevice(0x03) # PCAN-Dongle -PCAN_PCI = TPCANDevice(0x04) # PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express -PCAN_USB = TPCANDevice(0x05) # PCAN-USB and PCAN-USB Pro -PCAN_PCC = TPCANDevice(0x06) # PCAN-PC Card - -# PCAN parameters -# -PCAN_DEVICE_NUMBER = TPCANParameter(0x01) # PCAN-USB device number parameter -PCAN_5VOLTS_POWER = TPCANParameter(0x02) # PCAN-PC Card 5-Volt power parameter -PCAN_RECEIVE_EVENT = TPCANParameter(0x03) # PCAN receive event handler parameter -PCAN_MESSAGE_FILTER = TPCANParameter(0x04) # PCAN message filter parameter -PCAN_API_VERSION = TPCANParameter(0x05) # PCAN-Basic API version parameter -PCAN_CHANNEL_VERSION = TPCANParameter(0x06) # PCAN device channel version parameter -PCAN_BUSOFF_AUTORESET = TPCANParameter(0x07) # PCAN Reset-On-Busoff parameter -PCAN_LISTEN_ONLY = TPCANParameter(0x08) # PCAN Listen-Only parameter -PCAN_LOG_LOCATION = TPCANParameter(0x09) # Directory path for trace files -PCAN_LOG_STATUS = TPCANParameter(0x0A) # Debug-Trace 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(0x010) # CAN-Controller number of a PCAN-Channel - -# 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 hadware is not available -PCAN_CHANNEL_AVAILABLE = int(0x01) # The PCAN-Channel handle is available to be connected (Plug&Play Hardware: it means futhermore that the hardware is plugged-in) -PCAN_CHANNEL_OCCUPIED = int(0x02) # The PCAN-Channel handle is valid, and is already being used - -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 - -# PCAN message types -# -PCAN_MESSAGE_STANDARD = TPCANMessageType(0x00) # The PCAN message is a CAN Standard Frame (11-bit identifier) -PCAN_MESSAGE_RTR = TPCANMessageType(0x01) # The PCAN message is a CAN Remote-Transfer-Request Frame -PCAN_MESSAGE_EXTENDED = TPCANMessageType(0x02) # The PCAN message is a CAN Extended Frame (29-bit identifier) -PCAN_MESSAGE_STATUS = TPCANMessageType(0x80) # The PCAN message represents a PCAN status message - -# Frame Type / Initialization Mode -# -PCAN_MODE_STANDARD = PCAN_MESSAGE_STANDARD -PCAN_MODE_EXTENDED = PCAN_MESSAGE_EXTENDED - -# Baud rate codes = BTR0/BTR1 register values for the CAN controller. -# You can define your own Baud rate with the BTROBTR1 register. -# Take a look at www.peak-system.com for our free software "BAUDTOOL" -# to calculate the BTROBTR1 register for every baudrate and sample point. -# -PCAN_BAUD_1M = TPCANBaudrate(0x0014) # 1 MBit/s -PCAN_BAUD_800K = TPCANBaudrate(0x0016) # 800 kBit/s -PCAN_BAUD_500K = TPCANBaudrate(0x001C) # 500 kBit/s -PCAN_BAUD_250K = TPCANBaudrate(0x011C) # 250 kBit/s -PCAN_BAUD_125K = TPCANBaudrate(0x031C) # 125 kBit/s -PCAN_BAUD_100K = TPCANBaudrate(0x432F) # 100 kBit/s -PCAN_BAUD_95K = TPCANBaudrate(0xC34E) # 95,238 kBit/s -PCAN_BAUD_83K = TPCANBaudrate(0x4B14) # 83,333 kBit/s -PCAN_BAUD_50K = TPCANBaudrate(0x472F) # 50 kBit/s -PCAN_BAUD_47K = TPCANBaudrate(0x1414) # 47,619 kBit/s -PCAN_BAUD_33K = TPCANBaudrate(0x1D14) # 33,333 kBit/s -PCAN_BAUD_20K = TPCANBaudrate(0x532F) # 20 kBit/s -PCAN_BAUD_10K = TPCANBaudrate(0x672F) # 10 kBit/s -PCAN_BAUD_5K = TPCANBaudrate(0x7F7F) # 5 kBit/s - -# Supported No-Plug-And-Play Hardware types -# -PCAN_TYPE_ISA = TPCANType(0x01) # PCAN-ISA 82C200 -PCAN_TYPE_ISA_SJA = TPCANType(0x09) # PCAN-ISA SJA1000 -PCAN_TYPE_ISA_PHYTEC = TPCANType(0x04) # PHYTEC ISA -PCAN_TYPE_DNG = TPCANType(0x02) # PCAN-Dongle 82C200 -PCAN_TYPE_DNG_EPP = TPCANType(0x03) # PCAN-Dongle EPP 82C200 -PCAN_TYPE_DNG_SJA = TPCANType(0x05) # PCAN-Dongle SJA1000 -PCAN_TYPE_DNG_SJA_EPP = TPCANType(0x06) # PCAN-Dongle EPP SJA1000 - -# Represents a PCAN message -# -class TPCANMsg (Structure): - """ - Represents a PCAN message - """ - _fields_ = [ ("ID", c_ulong), # 11/29-bit message identifier - ("MSGTYPE", TPCANMessageType), # Type of the message - ("LEN", c_ubyte), # Data Length Code of the message (0..8) - ("DATA", c_ubyte * 8) ] # Data of the message (DATA[0]..DATA[7]) - -# Represents a timestamp of a received PCAN message -# Total Microseconds = micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow -# -class TPCANTimestamp (Structure): - """ - Represents a timestamp of a received PCAN message - Total Microseconds = micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow - """ - _fields_ = [ ("millis", c_ulong), # Base-value: milliseconds: 0.. 2^32-1 - ("millis_overflow", c_ushort), # Roll-arounds of millis - ("micros", c_ushort) ] # Microseconds: 0..999 - -#/////////////////////////////////////////////////////////// -# PCAN-Basic API function declarations -#/////////////////////////////////////////////////////////// - -# PCAN-Basic API class implementation -# -class PCANBasic: - """ - PCAN-Basic API class implementation - """ - def __init__(self): - # Loads the PCANBasic.dll - # - self.__m_dllBasic = windll.LoadLibrary("PCANBasic") - if self.__m_dllBasic == None: - print "Exception: The PCAN-Basic DLL couldn't be loaded!" - - # Initializes a PCAN Channel - # - def Initialize( - self, - Channel, - Btr0Btr1, - HwType = TPCANType(0), - IOPort = c_uint(0), - Interrupt = c_ushort(0)): - - """ - Initializes a PCAN Channel - - Parameters: - Channel : A TPCANHandle representing a PCAN Channel - Btr0Btr1 : The speed for the communication (BTR0BTR1 code) - HwType : NON PLUG&PLAY: The type of hardware and operation mode - IOPort : NON PLUG&PLAY: The I/O address for the parallel port - Interrupt: NON PLUG&PLAY: Interrupt number of the parallel port - - Returns: - A TPCANStatus error code - """ - try: - res = self.__m_dllBasic.CAN_Initialize(Channel,Btr0Btr1,HwType,IOPort,Interrupt) - return TPCANStatus(res) - except: - print "Exception on PCANBasic.Initialize" - raise - - # 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 - - # 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 - - # 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_ulong value with the lowest CAN ID to be received - ToID : A c_ulong 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_CHANNEL_VERSION or Parameter == PCAN_LOG_LOCATION: - mybuffer = create_string_buffer(256) - else: - mybuffer = c_int(0) - - res = self.__m_dllBasic.CAN_GetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer)) - return TPCANStatus(res),mybuffer.value - except: - print "Exception on PCANBasic.GetValue" - raise - - # Returns a descriptive text of a given TPCANStatus - # error code, in any desired language - # - def SetValue( - self, - Channel, - Parameter, - Buffer): - - """ - Returns a descriptive text of a given TPCANStatus error - code, in any desired language - - Remarks: - Parameters can be present or not according with the kind - of Hardware (PCAN Channel) being used. If a parameter is not available, - a PCAN_ERROR_ILLPARAMTYPE error will be returned. - - Parameters: - Channel : A TPCANHandle representing a PCAN Channel - Parameter : The TPCANParameter parameter to set - Buffer : Buffer with the value to be set - BufferLength : Size in bytes of the buffer - - Returns: - A TPCANStatus error code - """ - try: - if Parameter == PCAN_LOG_LOCATION or Parameter == PCAN_LOG_TEXT: - mybuffer = create_string_buffer(256) - else: - mybuffer = c_int(0) - - mybuffer.value = Buffer - res = self.__m_dllBasic.CAN_SetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer)) - return TPCANStatus(res) - except: - print "Exception on PCANBasic.SetValue" - raise - - def GetErrorText( - self, - Error, - Language = 0): - - """ - Configures or sets a PCAN Channel value - - Remarks: - - The current languages available for translation are: - Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), - Italian (0x10) and French (0x0C) - - The return value of this method is a 2-touple, where - the first value is the result (TPCANStatus) of the method and - the second one, the error text - - Parameters: - Error : A TPCANStatus error code - Language : Indicates a 'Primary language ID' (Default is Neutral(0)) - - Returns: - A touple with 2 values - """ - try: - mybuffer = create_string_buffer(256) - res = self.__m_dllBasic.CAN_GetErrorText(Error,Language,byref(mybuffer)) - return TPCANStatus(res),mybuffer.value - except: - print "Exception on PCANBasic.GetErrorText" - raise - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# PCANBasic.py +# +# ~~~~~~~~~~~~ +# +# PCAN-Basic API +# +# ~~~~~~~~~~~~ +# +# ------------------------------------------------------------------ +# Author : Keneth Wagner +# Last change: 08.11.2011 Wagner +# +# Language: Python 2.6 +# ------------------------------------------------------------------ +# +# Copyright (C) 1999-2012 PEAK-System Technik GmbH, Darmstadt +# more Info at http://www.peak-system.com +# + +# Module Imports +# +from ctypes import * + +#/////////////////////////////////////////////////////////// +# Type definitions +#/////////////////////////////////////////////////////////// + +TPCANHandle = c_ubyte # Represents a PCAN hardware channel handle +TPCANStatus = int # Represents a PCAN status/error code +TPCANParameter = c_ubyte # Represents a PCAN parameter to be read or set +TPCANDevice = c_ubyte # Represents a PCAN device +TPCANMessageType = c_ubyte # Represents the type of a PCAN message +TPCANType = c_ubyte # Represents the type of PCAN hardware to be initialized +TPCANMode = c_ubyte # Represents a PCAN filter mode +TPCANBaudrate = c_ushort # Represents a PCAN Baud rate register value + +#/////////////////////////////////////////////////////////// +# Value definitions +#/////////////////////////////////////////////////////////// + +# Currently defined and supported PCAN channels +# +PCAN_NONEBUS = TPCANHandle(0x00) # Undefined/default value for a PCAN bus + +PCAN_ISABUS1 = TPCANHandle(0x21) # PCAN-ISA interface, channel 1 +PCAN_ISABUS2 = TPCANHandle(0x22) # PCAN-ISA interface, channel 2 +PCAN_ISABUS3 = TPCANHandle(0x23) # PCAN-ISA interface, channel 3 +PCAN_ISABUS4 = TPCANHandle(0x24) # PCAN-ISA interface, channel 4 +PCAN_ISABUS5 = TPCANHandle(0x25) # PCAN-ISA interface, channel 5 +PCAN_ISABUS6 = TPCANHandle(0x26) # PCAN-ISA interface, channel 6 +PCAN_ISABUS7 = TPCANHandle(0x27) # PCAN-ISA interface, channel 7 +PCAN_ISABUS8 = TPCANHandle(0x28) # PCAN-ISA interface, channel 8 + +PCAN_DNGBUS1 = TPCANHandle(0x31) # PCAN-Dongle/LPT interface, channel 1 + +PCAN_PCIBUS1 = TPCANHandle(0x41) # PCAN-PCI interface, channel 1 +PCAN_PCIBUS2 = TPCANHandle(0x42) # PCAN-PCI interface, channel 2 +PCAN_PCIBUS3 = TPCANHandle(0x43) # PCAN-PCI interface, channel 3 +PCAN_PCIBUS4 = TPCANHandle(0x44) # PCAN-PCI interface, channel 4 +PCAN_PCIBUS5 = TPCANHandle(0x45) # PCAN-PCI interface, channel 5 +PCAN_PCIBUS6 = TPCANHandle(0x46) # PCAN-PCI interface, channel 6 +PCAN_PCIBUS7 = TPCANHandle(0x47) # PCAN-PCI interface, channel 7 +PCAN_PCIBUS8 = TPCANHandle(0x48) # PCAN-PCI interface, channel 8 + +PCAN_USBBUS1 = TPCANHandle(0x51) # PCAN-USB interface, channel 1 +PCAN_USBBUS2 = TPCANHandle(0x52) # PCAN-USB interface, channel 2 +PCAN_USBBUS3 = TPCANHandle(0x53) # PCAN-USB interface, channel 3 +PCAN_USBBUS4 = TPCANHandle(0x54) # PCAN-USB interface, channel 4 +PCAN_USBBUS5 = TPCANHandle(0x55) # PCAN-USB interface, channel 5 +PCAN_USBBUS6 = TPCANHandle(0x56) # PCAN-USB interface, channel 6 +PCAN_USBBUS7 = TPCANHandle(0x57) # PCAN-USB interface, channel 7 +PCAN_USBBUS8 = TPCANHandle(0x58) # PCAN-USB interface, channel 8 + +PCAN_PCCBUS1 = TPCANHandle(0x61) # PCAN-PC Card interface, channel 1 +PCAN_PCCBUS2 = TPCANHandle(0x62) # PCAN-PC Card interface, channel 2 + +# Represent the PCAN error and status codes +# +PCAN_ERROR_OK = TPCANStatus(0x00000) # No error +PCAN_ERROR_XMTFULL = TPCANStatus(0x00001) # Transmit buffer in CAN controller is full +PCAN_ERROR_OVERRUN = TPCANStatus(0x00002) # CAN controller was read too late +PCAN_ERROR_BUSLIGHT = TPCANStatus(0x00004) # Bus error: an error counter reached the 'light' limit +PCAN_ERROR_BUSHEAVY = TPCANStatus(0x00008) # Bus error: an error counter reached the 'heavy' limit +PCAN_ERROR_BUSOFF = TPCANStatus(0x00010) # Bus error: the CAN controller is in bus-off state +PCAN_ERROR_ANYBUSERR = TPCANStatus(PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF) # Mask for all bus errors +PCAN_ERROR_QRCVEMPTY = TPCANStatus(0x00020) # Receive queue is empty +PCAN_ERROR_QOVERRUN = TPCANStatus(0x00040) # Receive queue was read too late +PCAN_ERROR_QXMTFULL = TPCANStatus(0x00080) # Transmit queue is full +PCAN_ERROR_REGTEST = TPCANStatus(0x00100) # Test of the CAN controller hardware registers failed (no hardware found) +PCAN_ERROR_NODRIVER = TPCANStatus(0x00200) # Driver not loaded +PCAN_ERROR_HWINUSE = TPCANStatus(0x00400) # Hardware already in use by a Net +PCAN_ERROR_NETINUSE = TPCANStatus(0x00800) # A Client is already connected to the Net +PCAN_ERROR_ILLHW = TPCANStatus(0x01400) # Hardware handle is invalid +PCAN_ERROR_ILLNET = TPCANStatus(0x01800) # Net handle is invalid +PCAN_ERROR_ILLCLIENT = TPCANStatus(0x01C00) # Client handle is invalid +PCAN_ERROR_ILLHANDLE = TPCANStatus(PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) # Mask for all handle errors +PCAN_ERROR_RESOURCE = TPCANStatus(0x02000) # Resource (FIFO, Client, timeout) cannot be created +PCAN_ERROR_ILLPARAMTYPE = TPCANStatus(0x04000) # Invalid parameter +PCAN_ERROR_ILLPARAMVAL = TPCANStatus(0x08000) # Invalid parameter value +PCAN_ERROR_UNKNOWN = TPCANStatus(0x10000) # Unknow error +PCAN_ERROR_ILLDATA = TPCANStatus(0x20000) # Invalid data, function, or action +PCAN_ERROR_INITIALIZE = TPCANStatus(0x40000) # Channel is not initialized + +# PCAN devices +# +PCAN_NONE = TPCANDevice(0x00) # Undefined, unknown or not selected PCAN device value +PCAN_PEAKCAN = TPCANDevice(0x01) # PCAN Non-Plug&Play devices. NOT USED WITHIN PCAN-Basic API +PCAN_ISA = TPCANDevice(0x02) # PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus +PCAN_DNG = TPCANDevice(0x03) # PCAN-Dongle +PCAN_PCI = TPCANDevice(0x04) # PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express +PCAN_USB = TPCANDevice(0x05) # PCAN-USB and PCAN-USB Pro +PCAN_PCC = TPCANDevice(0x06) # PCAN-PC Card + +# PCAN parameters +# +PCAN_DEVICE_NUMBER = TPCANParameter(0x01) # PCAN-USB device number parameter +PCAN_5VOLTS_POWER = TPCANParameter(0x02) # PCAN-PC Card 5-Volt power parameter +PCAN_RECEIVE_EVENT = TPCANParameter(0x03) # PCAN receive event handler parameter +PCAN_MESSAGE_FILTER = TPCANParameter(0x04) # PCAN message filter parameter +PCAN_API_VERSION = TPCANParameter(0x05) # PCAN-Basic API version parameter +PCAN_CHANNEL_VERSION = TPCANParameter(0x06) # PCAN device channel version parameter +PCAN_BUSOFF_AUTORESET = TPCANParameter(0x07) # PCAN Reset-On-Busoff parameter +PCAN_LISTEN_ONLY = TPCANParameter(0x08) # PCAN Listen-Only parameter +PCAN_LOG_LOCATION = TPCANParameter(0x09) # Directory path for trace files +PCAN_LOG_STATUS = TPCANParameter(0x0A) # Debug-Trace 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(0x010) # CAN-Controller number of a PCAN-Channel + +# 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 hadware is not available +PCAN_CHANNEL_AVAILABLE = int(0x01) # The PCAN-Channel handle is available to be connected (Plug&Play Hardware: it means futhermore that the hardware is plugged-in) +PCAN_CHANNEL_OCCUPIED = int(0x02) # The PCAN-Channel handle is valid, and is already being used + +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 + +# PCAN message types +# +PCAN_MESSAGE_STANDARD = TPCANMessageType(0x00) # The PCAN message is a CAN Standard Frame (11-bit identifier) +PCAN_MESSAGE_RTR = TPCANMessageType(0x01) # The PCAN message is a CAN Remote-Transfer-Request Frame +PCAN_MESSAGE_EXTENDED = TPCANMessageType(0x02) # The PCAN message is a CAN Extended Frame (29-bit identifier) +PCAN_MESSAGE_STATUS = TPCANMessageType(0x80) # The PCAN message represents a PCAN status message + +# Frame Type / Initialization Mode +# +PCAN_MODE_STANDARD = PCAN_MESSAGE_STANDARD +PCAN_MODE_EXTENDED = PCAN_MESSAGE_EXTENDED + +# Baud rate codes = BTR0/BTR1 register values for the CAN controller. +# You can define your own Baud rate with the BTROBTR1 register. +# Take a look at www.peak-system.com for our free software "BAUDTOOL" +# to calculate the BTROBTR1 register for every baudrate and sample point. +# +PCAN_BAUD_1M = TPCANBaudrate(0x0014) # 1 MBit/s +PCAN_BAUD_800K = TPCANBaudrate(0x0016) # 800 kBit/s +PCAN_BAUD_500K = TPCANBaudrate(0x001C) # 500 kBit/s +PCAN_BAUD_250K = TPCANBaudrate(0x011C) # 250 kBit/s +PCAN_BAUD_125K = TPCANBaudrate(0x031C) # 125 kBit/s +PCAN_BAUD_100K = TPCANBaudrate(0x432F) # 100 kBit/s +PCAN_BAUD_95K = TPCANBaudrate(0xC34E) # 95,238 kBit/s +PCAN_BAUD_83K = TPCANBaudrate(0x4B14) # 83,333 kBit/s +PCAN_BAUD_50K = TPCANBaudrate(0x472F) # 50 kBit/s +PCAN_BAUD_47K = TPCANBaudrate(0x1414) # 47,619 kBit/s +PCAN_BAUD_33K = TPCANBaudrate(0x1D14) # 33,333 kBit/s +PCAN_BAUD_20K = TPCANBaudrate(0x532F) # 20 kBit/s +PCAN_BAUD_10K = TPCANBaudrate(0x672F) # 10 kBit/s +PCAN_BAUD_5K = TPCANBaudrate(0x7F7F) # 5 kBit/s + +# Supported No-Plug-And-Play Hardware types +# +PCAN_TYPE_ISA = TPCANType(0x01) # PCAN-ISA 82C200 +PCAN_TYPE_ISA_SJA = TPCANType(0x09) # PCAN-ISA SJA1000 +PCAN_TYPE_ISA_PHYTEC = TPCANType(0x04) # PHYTEC ISA +PCAN_TYPE_DNG = TPCANType(0x02) # PCAN-Dongle 82C200 +PCAN_TYPE_DNG_EPP = TPCANType(0x03) # PCAN-Dongle EPP 82C200 +PCAN_TYPE_DNG_SJA = TPCANType(0x05) # PCAN-Dongle SJA1000 +PCAN_TYPE_DNG_SJA_EPP = TPCANType(0x06) # PCAN-Dongle EPP SJA1000 + +# Represents a PCAN message +# +class TPCANMsg (Structure): + """ + Represents a PCAN message + """ + _fields_ = [ ("ID", c_ulong), # 11/29-bit message identifier + ("MSGTYPE", TPCANMessageType), # Type of the message + ("LEN", c_ubyte), # Data Length Code of the message (0..8) + ("DATA", c_ubyte * 8) ] # Data of the message (DATA[0]..DATA[7]) + +# Represents a timestamp of a received PCAN message +# Total Microseconds = micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow +# +class TPCANTimestamp (Structure): + """ + Represents a timestamp of a received PCAN message + Total Microseconds = micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow + """ + _fields_ = [ ("millis", c_ulong), # Base-value: milliseconds: 0.. 2^32-1 + ("millis_overflow", c_ushort), # Roll-arounds of millis + ("micros", c_ushort) ] # Microseconds: 0..999 + +#/////////////////////////////////////////////////////////// +# PCAN-Basic API function declarations +#/////////////////////////////////////////////////////////// + +# PCAN-Basic API class implementation +# +class PCANBasic: + """ + PCAN-Basic API class implementation + """ + def __init__(self): + # Loads the PCANBasic.dll + # + self.__m_dllBasic = windll.LoadLibrary("../PCANBasic/PCANBasic") + if self.__m_dllBasic == None: + print "Exception: The PCAN-Basic DLL couldn't be loaded!" + + # Initializes a PCAN Channel + # + def Initialize( + self, + Channel, + Btr0Btr1, + HwType = TPCANType(0), + IOPort = c_uint(0), + Interrupt = c_ushort(0)): + + """ + Initializes a PCAN Channel + + Parameters: + Channel : A TPCANHandle representing a PCAN Channel + Btr0Btr1 : The speed for the communication (BTR0BTR1 code) + HwType : NON PLUG&PLAY: The type of hardware and operation mode + IOPort : NON PLUG&PLAY: The I/O address for the parallel port + Interrupt: NON PLUG&PLAY: Interrupt number of the parallel port + + Returns: + A TPCANStatus error code + """ + try: + res = self.__m_dllBasic.CAN_Initialize(Channel,Btr0Btr1,HwType,IOPort,Interrupt) + return TPCANStatus(res) + except: + print "Exception on PCANBasic.Initialize" + raise + + # 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 + + # 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 + + # 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_ulong value with the lowest CAN ID to be received + ToID : A c_ulong 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_CHANNEL_VERSION or Parameter == PCAN_LOG_LOCATION: + mybuffer = create_string_buffer(256) + else: + mybuffer = c_int(0) + + res = self.__m_dllBasic.CAN_GetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer)) + return TPCANStatus(res),mybuffer.value + except: + print "Exception on PCANBasic.GetValue" + raise + + # Returns a descriptive text of a given TPCANStatus + # error code, in any desired language + # + def SetValue( + self, + Channel, + Parameter, + Buffer): + + """ + Returns a descriptive text of a given TPCANStatus error + code, in any desired language + + Remarks: + Parameters can be present or not according with the kind + of Hardware (PCAN Channel) being used. If a parameter is not available, + a PCAN_ERROR_ILLPARAMTYPE error will be returned. + + Parameters: + Channel : A TPCANHandle representing a PCAN Channel + Parameter : The TPCANParameter parameter to set + Buffer : Buffer with the value to be set + BufferLength : Size in bytes of the buffer + + Returns: + A TPCANStatus error code + """ + try: + if Parameter == PCAN_LOG_LOCATION or Parameter == PCAN_LOG_TEXT: + mybuffer = create_string_buffer(256) + else: + mybuffer = c_int(0) + + mybuffer.value = Buffer + res = self.__m_dllBasic.CAN_SetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer)) + return TPCANStatus(res) + except: + print "Exception on PCANBasic.SetValue" + raise + + def GetErrorText( + self, + Error, + Language = 0): + + """ + Configures or sets a PCAN Channel value + + Remarks: + + The current languages available for translation are: + Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), + Italian (0x10) and French (0x0C) + + The return value of this method is a 2-touple, where + the first value is the result (TPCANStatus) of the method and + the second one, the error text + + Parameters: + Error : A TPCANStatus error code + Language : Indicates a 'Primary language ID' (Default is Neutral(0)) + + Returns: + A touple with 2 values + """ + try: + mybuffer = create_string_buffer(256) + res = self.__m_dllBasic.CAN_GetErrorText(Error,Language,byref(mybuffer)) + return TPCANStatus(res),mybuffer.value + except: + print "Exception on PCANBasic.GetErrorText" + raise + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PCANBasic/PCANBasic.pyc b/PCANBasic/PCANBasic.pyc index 246ed6c4113e4bc42f586f05409e3c55023eebb6..81ae74b43286c3358ed9123cb2b712687e67bb50 100644 GIT binary patch delta 50 xcmX?C@}z`=`7?iM_jU2zYrHjQF7#Q^Q^aGq7{hShuGm{al&FnnxdH}GV54!*W delta 28 kcmaD-a;}7f`7o0IN(1x&QzG diff --git a/pycrc/crc_algorithms.pyc b/pycrc/crc_algorithms.pyc index 124b92f31f657469c9e77115192c761438f8667e..0ef825c90d4b8019131c641093b1f8634ef91bdf 100644 GIT binary patch delta 292 zcmeyNJ4cU=`7Gr}qQTGQ9HV_&?&6|1K1ZPkwTb=v-XZ`-w&4k^=gA@%{{}C#{rhf8N(G6IXPtFsI#wPqpObY;<(?!hy diff --git a/pycrc/crc_lexer.pyc b/pycrc/crc_lexer.pyc index 88e73b9f6cf5f196300de42936bcf418b19ef09c..b8d15f87c2cd282a474111ad54b5f5327a921e63 100644 GIT binary patch delta 346 zcmZ2zcF~ND`7tQXq)^?N*w@oG^vv}P4JOC3KEo!Q!}bx2@a8u5 z`Ha}a{Wy)7u!v7y$$bNh@a9!Kkywq<;ah}N{5$_AW^CpNi9BY(CN3vwgUy`D%~Ew( Kluy=@RtEsx T8HdznNx^U?9CDMV3abGC`*bMx delta 109 zcmX@DzFVD*`7lhG8W;@ Ps)FH6Si~nU6;=ZPl!G0K diff --git a/pycrc/crc_opt.pyc b/pycrc/crc_opt.pyc index 0b4ca6d12eb5478b702716c748536ff65651315c..20e375bafb0691b7de70b60c68e07a46dfdcd9a3 100644 GIT binary patch delta 236 zcmaDD-5A5h{F#@l!D%B~1}me%=H_70V%Tl_* qj6-g6y4njIQkzTE-!tNp>(IQ9Q?5tb376dD&pOj^7&&>Jt}y^G!cm?8 delta 204 zcmZpSc^J*c{F#?)Lcm703|2;+$@#1jJO!1>MajAbdggkD2Aij|Zj!+!UZiw`8H@Pj mVzn1ogg3XSzh}fIK1cIDR`Dg;PT0gJ^XpE-V$9@oy2bz|#5-jG diff --git a/pycrc/crc_parser.pyc b/pycrc/crc_parser.pyc index 164a26e433c6069cdf85e55e2c800bfa89d6fc1d..fc1547bdbe74aad313988a831bc2d673e49805b6 100644 GIT binary patch delta 514 zcmeBjx#Yse{F#@l!D%DgEG9Vsl)KHo6qidjFXb}8sqYte4^Fw&yccoGE#%i_#^uh>LhLx*A}<<_ s)6Cgo@i^t=CDd@*mnD4zr+w*i9k|S#ETV7V{?zRFgsRzy+y;ZnsZt# o9;P}u!Uw0^)=Ea4a<{7_m~hxPIiOyAvwrO#oO%Q5vvA7YZ-{2WVeaPm s))UM)yCN}2Jyj&9kHnMFJVlhE4tCla+Ftiz@W6$!$Ja$%s|_bCm=W7CR;v)QfNSuKj~mPeFYaR&nOWXcjDH vZEkNp!HiA3qO%99dfmPy*wjzf?K7CHHE9PHqb74t?!qSgP)Kz0<;ju&ps{}e diff --git a/pycrc/pycrc.pyc b/pycrc/pycrc.pyc index 744f9d928bc99ee007dec0047ed2855c8becd431..6706699d0e110aa90a1003b3ac361f18af9484a6 100644 GIT binary patch delta 15 WcmbPjHrtGi`7