diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9435d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +# Ignore-Datei selbst ausschließen +#.gitignore +.gitmodules +Thumbs.db + +# Bestimmte Dateien ausschließen +cache.dat + +# Es können Wildcards (*,?) verwendet werden: +*.exe +*.dll +*.dsbackup +*.avrsln +*.avrsuo +*.avrgccproj +*.aps +*.atsln +*.atsuo +*.cproj +*.aws +*.xml +*.xslt +*.aux +*.dvi +*.lof +*.log +*.lot +*.out +*.synctex.gz +*.toc +*.pyc +*.patch +*.csv +.project +.pydevproject +tmp?.dat + +# Auch Verzeichnisse kann man ausschießen: +*default/ +*Debug/ +*bin/ +*ADC/ +*CAN/ +*UART/ +.*/ +CANLibrary/ diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 77d664b..24ecbd3 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -2,5 +2,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/Sym2Lib.py=UTF-8 encoding//CANLibrary/example.py=UTF-8 encoding//pycrc/crc_algorithms.py=latin1 diff --git a/CANLibrary/PCan.py b/CANLibrary/PCan.py index 93bb842..ca81341 100644 --- a/CANLibrary/PCan.py +++ b/CANLibrary/PCan.py @@ -15,7 +15,7 @@ class PcanAdapter(object): ''' A class for controlling a PEAK PCan adapter. Based on the PCANBasic library. ''' - + # Class variables: Baudrate = { '100k' : PCANBasic.PCAN_BAUD_100K, '125k' : PCANBasic.PCAN_BAUD_125K, @@ -23,20 +23,21 @@ class PcanAdapter(object): '500k' : PCANBasic.PCAN_BAUD_500K, '1000k': PCANBasic.PCAN_BAUD_1M } - - - def __init__(self, Baudrate): + + + def __init__(self, Baudrate, debug = True): ''' Constructor. @param Baudrate: Baud rate from the PcanAdapter. Baud rate dictionary ''' - # Instance variables: - self.Messages = {} + # Instance variables: + self.debug = debug + self.Messages = {} self.Channel = PCANBasic.PCAN_USBBUS1 self.Pcan = PCANBasic.PCANBasic() self.Baudrate = Baudrate # Baud rate from PCANBasic self.isInitialised = False - + def __del__(self): ''' Destructor. @@ -44,26 +45,26 @@ class PcanAdapter(object): ''' print '\nDestructor:' self.uninitialize() - + def addMessage(self, CanMessage): ''' Add a Message of type CanMessage to the list of messages. - + @param CanMessage: The message to add to the list of messages. ''' - + self.Messages.update({CanMessage.Label: CanMessage}) - + def removeMessage(self, CanMessageLabel): try: self.Messages.pop(CanMessageLabel) except: pass - - + + def clearMessages(self): self.Messages = {} - + def initialize(self): ''' Initializes the PCAN adapter. @@ -71,15 +72,17 @@ class PcanAdapter(object): self.Pcan.Uninitialize(PCANBasic.PCAN_NONEBUS) status = self.Pcan.Initialize(self.Channel, self.Baudrate) if status != PCANBasic.PCAN_ERROR_OK: - print 'Error: ', self.Pcan.GetErrorText(status, 0)[1] + if self.debug: + print 'Error: ', self.Pcan.GetErrorText(status, 0)[1] sys.exit("PCAN initialisation error") - - print("PCAN initialised") + if self.debug: + print("PCAN initialised") self.isInitialised = True - + channel, hwId = self.Pcan.GetValue( self.Channel, PCANBasic.PCAN_DEVICE_NUMBER ) - print 'DeviceNumber: ', hwId - + if self.debug: + print 'DeviceNumber: ', hwId + def uninitialize(self): ''' Unitialize the PCAN adapter. @@ -87,19 +90,20 @@ class PcanAdapter(object): if self.isInitialised: status = self.Pcan.Uninitialize(self.Channel) if status != PCANBasic.PCAN_ERROR_OK: - print 'Error: ', self.Pcan.GetErrorText(status, 0)[1] + if self.debug: + print 'Error: ', self.Pcan.GetErrorText(status, 0)[1] sys.exit("PCAN deinitialisation error") - - print("PCAN deinitialised") - + if self.debug: + print("PCAN deinitialised") + def sendMessage(self, Message, rtr = False): ''' Sends the CanMessage object Message onto the CAN bus. - - @param Messge: The CanMessage object that is to be sent. + + @param Messge: The CanMessage object that is to be sent. ''' Message.composeData() # compose message data array from the signals in Message.Signals. - + msg = PCANBasic.TPCANMsg() # create a new PCAN message object msg.ID = Message.Id # copy the ID if rtr: @@ -108,10 +112,10 @@ class PcanAdapter(object): msg.MSGTYPE = PCANBasic.PCAN_MESSAGE_STANDARD # Message type is standard (not extended) msg.LEN = Message.Length # copy the length msg.DATA[0:Message.Length] = Message.Data # copy the message data into the PCAN message object - + self.Pcan.Write(self.Channel, msg) # write it onto the Bus #print ('Message ' + Message.Label + ' written.') - + def receiveMessage(self, block = False): ''' Tries to receive a CAN message and puts its data into the according CanMessage object's Data field. @@ -120,7 +124,7 @@ class PcanAdapter(object): while True: # do this while messages are read from the bus result, msg, timestamp = self.Pcan.Read(self.Channel) - + if result == PCANBasic.PCAN_ERROR_OK: # loop through the messages and look for one that matches the received message: for msgKey in self.Messages: diff --git a/CANLibrary/example.py b/CANLibrary/example.py index 3debfd4..ad98d90 100644 --- a/CANLibrary/example.py +++ b/CANLibrary/example.py @@ -9,6 +9,7 @@ Example for creating and sending CAN messages via PCAN using the CanMessage, Can from CanMessage import CanMessage from CanSignal import CanSignal from PCan import PcanAdapter +from Sym2Lib import addtoPCAN, printCode import time print '\nCreate a PCAN adapter' diff --git a/PCANBasic/PCANBasic.pyc b/PCANBasic/PCANBasic.pyc deleted file mode 100644 index 1057119..0000000 Binary files a/PCANBasic/PCANBasic.pyc and /dev/null differ diff --git a/pycrc/crc_algorithms.pyc b/pycrc/crc_algorithms.pyc deleted file mode 100644 index 0ef825c..0000000 Binary files a/pycrc/crc_algorithms.pyc and /dev/null differ diff --git a/pycrc/crc_lexer.pyc b/pycrc/crc_lexer.pyc deleted file mode 100644 index b8d15f8..0000000 Binary files a/pycrc/crc_lexer.pyc and /dev/null differ diff --git a/pycrc/crc_models.pyc b/pycrc/crc_models.pyc deleted file mode 100644 index f373a09..0000000 Binary files a/pycrc/crc_models.pyc and /dev/null differ diff --git a/pycrc/crc_opt.pyc b/pycrc/crc_opt.pyc deleted file mode 100644 index 20e375b..0000000 Binary files a/pycrc/crc_opt.pyc and /dev/null differ diff --git a/pycrc/crc_parser.pyc b/pycrc/crc_parser.pyc deleted file mode 100644 index fc1547b..0000000 Binary files a/pycrc/crc_parser.pyc and /dev/null differ diff --git a/pycrc/crc_symtable.pyc b/pycrc/crc_symtable.pyc deleted file mode 100644 index 8c2c13d..0000000 Binary files a/pycrc/crc_symtable.pyc and /dev/null differ diff --git a/pycrc/pycrc.pyc b/pycrc/pycrc.pyc deleted file mode 100644 index 6706699..0000000 Binary files a/pycrc/pycrc.pyc and /dev/null differ