From d960680e2e3df72354f452dd758d729bf995398f Mon Sep 17 00:00:00 2001 From: Philipp Rauch Date: Tue, 19 Nov 2013 15:05:58 +0100 Subject: [PATCH] add option block on receiveMessage added the option block to the receiveMessage Method *default False for no compatibility issues --- CANLibrary/PCan.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CANLibrary/PCan.py b/CANLibrary/PCan.py index 5007f3c..93bb842 100644 --- a/CANLibrary/PCan.py +++ b/CANLibrary/PCan.py @@ -8,9 +8,10 @@ Created on 06.07.2012 import PCANBasic # PCANBasic wrapper library provided by PEAK import sys +from time import sleep -class PcanAdapter (object): +class PcanAdapter(object): ''' A class for controlling a PEAK PCan adapter. Based on the PCANBasic library. ''' @@ -111,7 +112,7 @@ class PcanAdapter (object): self.Pcan.Write(self.Channel, msg) # write it onto the Bus #print ('Message ' + Message.Label + ' written.') - def receiveMessage(self): + def receiveMessage(self, block = False): ''' Tries to receive a CAN message and puts its data into the according CanMessage object's Data field. This method should be called frequently. @@ -135,5 +136,6 @@ class PcanAdapter (object): self.Messages[msgKey].decomposeData() self.Messages[msgKey].timestamp = timestamp.micros + 1000 * timestamp.millis + 0xFFFFFFFF * 1000 * timestamp.millis_overflow return msg.ID - elif result == PCANBasic.PCAN_ERROR_QRCVEMPTY: + elif result == PCANBasic.PCAN_ERROR_QRCVEMPTY and block == False: return None + sleep(0.01) \ No newline at end of file