* Enabled "Send" and "Receive" Message types.

* Updated the example to also employ Sym2Lib library
This commit is contained in:
Christian Sueltrop 2014-02-21 16:26:41 +01:00
parent c4c166ce74
commit 950dbb787f
2 changed files with 26 additions and 14 deletions

View file

@ -15,14 +15,14 @@ def readSym(symfile):
'''
Read in a .sym-file created with PEAK PCAN Symbol Editor containing CAN message and signal definitions.
'''
sym = open(symfile, "r")
sym = open(symfile, "r") # File handle to the .sym-file
message = {}
tmp = {}
enums = {}
ignore = True
enums_bool = False
name = ""
message = {} # Decoded message descriptions
tmp = {} #
enums = {} #
ignore = True # temporary ignore flag for message types
enums_bool = False #
name = "" #
for line in sym:
line = line.split("//")[0].strip()
@ -68,15 +68,15 @@ def readSym(symfile):
modus = line.strip("{} \n")
if modus == "ENUMS":
enums_bool = True
ignore = False
elif modus == "SEND":
ignore = False
ignore = False # do not ignore ENUM definitions
elif modus == "SEND":
ignore = False # do not ignore SEND type message definitions
elif modus == "RECEIVE":
ignore = False
ignore = False # do not ignore RECEIVE type message definitions
elif modus == "SENDRECEIVE":
ignore = False
ignore = False # do not ignore SENDRECEIVE type message definitions
elif modus == "VIRTUALVARS":
ignore = True
ignore = True # ignore VIRTUALVARS definitions
elif line[0] == "[":
name = line.strip("[] \n")
@ -170,7 +170,8 @@ def Add2Adapter(pcan, symfile):
mes[i]["DLC"],
mes[i]["CycleTime"],
i))
print "add - %s (%s) - to pcan" % (i, hex(mes[i]["ID"]))
print "adding message to pcan: ID \'%s\', Name \'%s\'" % (hex(mes[i]["ID"]), i)
signals = []
for sig in mes[i]:
if isinstance(mes[i].get(sig), dict):

View file

@ -10,6 +10,7 @@ from CanMessage import CanMessage
from CanSignal import CanSignal
from PCan import PcanAdapter
#from Sym2Lib import addtoPCAN, printCode
from Sym2Lib import Add2Adapter
import time
print '\nCreate a PCAN adapter'
@ -59,6 +60,16 @@ pcan.Messages['mMotor_2'].composeData()
print 'mMotor_2.Data', pcan.Messages['mMotor_2'].Data
pcan.sendMessage(pcan.Messages['mMotor_2'])
# Test Sym2Lib
Add2Adapter(pcan, "Test.sym")
pcan.Messages['Test'].Signals['Var1'].SetData( 30 )
pcan.Messages['Test'].composeData()
pcan.sendMessage(pcan.Messages['Test'])
# receive messages, if the signal MO1_Drehzahl has changed, print the new value
while True:
#print 'send'