diff --git a/CANLibrary/CanMessage.py b/CANLibrary/CanMessage.py index a5f30b7..87c38fb 100644 --- a/CANLibrary/CanMessage.py +++ b/CANLibrary/CanMessage.py @@ -65,10 +65,10 @@ class CanMessage(object): of the CanMessage object. The position where to copy the data is defined in the Begin and Length fields of the CanSignal objects. ''' - for symKey in self.Signals: - sym = self.Signals[symKey] + for sigKey in self.Signals: + sig = self.Signals[sigKey] srcBegin = 0 # reading the source data (from the Signal definition) always starts at the first bit - tgtBegin = sym.Begin # where the source data goes is defined in the Begin field of the CanSignal object + tgtBegin = sig.Begin # where the source data goes is defined in the Begin field of the CanSignal object srcByteNo = (srcBegin/8) # will be 0 if srcBegin == 0 srcBitNo = (srcBegin%8) # will be 0 if srcBegin == 0 @@ -76,15 +76,24 @@ class CanMessage(object): tgtByteNo = (tgtBegin/8) # get the byte and bit numbers tgtBitNo = (tgtBegin%8) # for the target (the CanMessage object) array - for i in range(0, sym.Length): + for i in range(0, sig.Length): + + #print tgtByteNo + #print tgtBitNo + #print '' # copy the source data bits to the target # OR # get srcBitNo from srcByteNo and shift it to tgtBitNo if tgtByteNo >= self.Length: sys.exit('Signal does not fit into message!') - - tmp = (sym.Data[srcByteNo] >> srcBitNo) & 0x01 - tmp = tmp << tgtBitNo - self.Data[tgtByteNo] |= tmp + + #print srcBitNo + tmp = sig.Data[srcByteNo] + tmp = tmp >> srcBitNo + tmp = tmp & 0x01 + if tmp == 1: # the bit shall be set + self.Data[tgtByteNo] |= (1 << tgtBitNo) + else: # the bit shall be cleared + self.Data[tgtByteNo] &= ~(1 << tgtBitNo) # increment the counters srcBitNo += 1 @@ -96,6 +105,3 @@ class CanMessage(object): if tgtBitNo >= 8: tgtBitNo = 0 tgtByteNo += 1 - - - diff --git a/CANLibrary/CanMessage.pyc b/CANLibrary/CanMessage.pyc index 9b7baa0..05edef8 100644 Binary files a/CANLibrary/CanMessage.pyc and b/CANLibrary/CanMessage.pyc differ diff --git a/CANLibrary/CanSignal.py b/CANLibrary/CanSignal.py index 6af2574..a36f9e8 100644 --- a/CANLibrary/CanSignal.py +++ b/CANLibrary/CanSignal.py @@ -41,6 +41,7 @@ class CanSignal(object): ''' #if not (len(Data) == self.Length): # sys.exit('Data has invalid length') - tmpData = int((SignalData+self.Offset)*self.Scaling) + tmpData = int((SignalData+self.Offset) / self.Scaling) + self.Data = [] for i in range(0, int(self.Length/8)+1): - self.Data.append ( (tmpData >> 8) & 0xff ) \ No newline at end of file + self.Data.append ( (tmpData >> (8*i) ) & 0xff ) \ No newline at end of file diff --git a/CANLibrary/CanSignal.pyc b/CANLibrary/CanSignal.pyc index 90bfd0f..8c6cff1 100644 Binary files a/CANLibrary/CanSignal.pyc and b/CANLibrary/CanSignal.pyc differ diff --git a/CANLibrary/PCan.py b/CANLibrary/PCan.py index 9e259cd..8bbcd3e 100644 --- a/CANLibrary/PCan.py +++ b/CANLibrary/PCan.py @@ -59,7 +59,7 @@ class PcanAdapter (object): msg.ID = Message.Id msg.MSGTYPE = PCANBasic.PCAN_MESSAGE_STANDARD msg.LEN = Message.Length - msg.DATA[0:len(Message.Data)] = Message.Data + msg.DATA[0:Message.Length] = Message.Data self.Pcan.Write(self.Channel, msg) #print ('Message ' + Message.Label + ' written.') \ No newline at end of file diff --git a/CANLibrary/PCan.pyc b/CANLibrary/PCan.pyc index 22d961f..ead0943 100644 Binary files a/CANLibrary/PCan.pyc and b/CANLibrary/PCan.pyc differ