CanSignal data arrays are now constructed automatically, based on the signal length.
This commit is contained in:
parent
b4631bbd9a
commit
2aa6eb3da7
6 changed files with 27 additions and 22 deletions
|
|
@ -82,7 +82,9 @@ class CanMessage(object):
|
|||
if tgtByteNo >= self.Length:
|
||||
sys.exit('Signal does not fit into message!')
|
||||
|
||||
self.Data[tgtByteNo] |= ((sym.Data[srcByteNo] >> srcBitNo) & 0x01) << tgtBitNo
|
||||
tmp = (sym.Data[srcByteNo] >> srcBitNo) & 0x01
|
||||
tmp = tmp << tgtBitNo
|
||||
self.Data[tgtByteNo] |= tmp
|
||||
|
||||
# increment the counters
|
||||
srcBitNo += 1
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -30,7 +30,10 @@ class CanSignal(object):
|
|||
self.Length = SignalLength
|
||||
self.Label = SignalLabel
|
||||
|
||||
self.Data = SignalData
|
||||
for i in range(0, int(SignalLength/8)+1):
|
||||
self.Data.append ( (SignalData >> 8) & 0xff )
|
||||
|
||||
#self.Data = SignalData
|
||||
|
||||
|
||||
def SetData(self, Data):
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -1,48 +1,48 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
|
||||
'''
|
||||
Example for creating and sending CAN messages via PCAN using the CanMessage, CanSymbol and PCan classes.
|
||||
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 CanSymbol import CanSymbol
|
||||
from CanSignal import CanSignal
|
||||
from PCan import PcanAdapter
|
||||
|
||||
|
||||
print '\ncreate some messages'
|
||||
mMotor_1 = CanMessage(0x280, 8, 10)
|
||||
mMotor_1 = CanMessage(0x280, 8, 10, 'mMotor_1')
|
||||
print 'mMotor_1.Data', mMotor_1.Data
|
||||
|
||||
mMotor_2 = CanMessage(0x288, 8, 20)
|
||||
mMotor_2 = CanMessage(0x288, 8, 20, 'mMotor_2')
|
||||
print 'mMotor_2.Data', mMotor_2.Data
|
||||
|
||||
print '\ncreate some symbols'
|
||||
print '\ncreate some Signals'
|
||||
# for mMotor_1
|
||||
MO1_Leergas = CanSymbol(0, 1, [0x01], 'MO1_Leergas')
|
||||
MO1_Sta_Pedal = CanSymbol(1, 1, [0x01], 'MO1_Sta_Pedal')
|
||||
MO1_Mo_m_ex = CanSymbol(8, 8, [0x00], 'MO1_Mo_m_ex')
|
||||
MO1_Leergas = CanSignal(0, 1, [0x01], 'MO1_Leergas')
|
||||
MO1_Sta_Pedal = CanSignal(1, 1, [0x01], 'MO1_Sta_Pedal')
|
||||
MO1_Mo_m_ex = CanSignal(8, 8, [0x00], 'MO1_Mo_m_ex')
|
||||
|
||||
value = int(3000*0.25)
|
||||
MO1_Drehzahl = CanSymbol(16, 16, [value>>8, value&0x00ff], 'MO1_Drehzahl') # split into two bytes
|
||||
MO1_Drehzahl = CanSignal(16, 16, [value>>8, value&0x00ff], 'MO1_Drehzahl') # split into two bytes
|
||||
|
||||
mMotor_1.addSymbol(MO1_Leergas)
|
||||
mMotor_1.addSymbol(MO1_Sta_Pedal)
|
||||
mMotor_1.addSymbol(MO1_Mo_m_ex)
|
||||
mMotor_1.addSymbol(MO1_Drehzahl)
|
||||
mMotor_1.addSignal(MO1_Leergas)
|
||||
mMotor_1.addSignal(MO1_Sta_Pedal)
|
||||
mMotor_1.addSignal(MO1_Mo_m_ex)
|
||||
mMotor_1.addSignal(MO1_Drehzahl)
|
||||
print MO1_Drehzahl.Data
|
||||
|
||||
# for mMotor_2
|
||||
MO2_Kuehlm_T = CanSymbol(8, 8, [int(60*0.75)-48], 'MO2_Kuehlm_T')
|
||||
mMotor_2.addSymbol( MO2_Kuehlm_T )
|
||||
mMotor_2.addSymbol( CanSymbol(24, 8, [0], 'MO2_GRA_Soll') )
|
||||
mMotor_2.addSymbol( CanSymbol(0, 6, [44], 'MO2_CAN_Vers') )
|
||||
MO2_Kuehlm_T = CanSignal(8, 8, [int(60*0.75)-48], 'MO2_Kuehlm_T')
|
||||
mMotor_2.addSignal( MO2_Kuehlm_T )
|
||||
mMotor_2.addSignal( CanSignal(24, 8, [0], 'MO2_GRA_Soll') )
|
||||
mMotor_2.addSignal( CanSignal(0, 6, [44], 'MO2_CAN_Vers') )
|
||||
|
||||
print '\nManipulate Symbols'
|
||||
# does not work yet! need a way to replace a symbol -> dictionary
|
||||
print '\nManipulate Signals'
|
||||
# does not work yet! need a way to replace a Signal -> dictionary
|
||||
MO1_Leergas.SetData( [0x00] )
|
||||
mMotor_1.addSymbol( MO1_Leergas )
|
||||
mMotor_1.addSignal( MO1_Leergas )
|
||||
|
||||
print '\nCreate a PCAN adapter'
|
||||
pcan = PcanAdapter(PcanAdapter.Baudrate['500k'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue