From 950dbb787f1cf951ecae305a275d3334233306e7 Mon Sep 17 00:00:00 2001 From: Christian Sueltrop Date: Fri, 21 Feb 2014 16:26:41 +0100 Subject: [PATCH] * Enabled "Send" and "Receive" Message types. * Updated the example to also employ Sym2Lib library --- CANLibrary/Sym2Lib.py | 29 +++++++++++++++-------------- CANLibrary/example.py | 11 +++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CANLibrary/Sym2Lib.py b/CANLibrary/Sym2Lib.py index 0fef639..2aae65e 100644 --- a/CANLibrary/Sym2Lib.py +++ b/CANLibrary/Sym2Lib.py @@ -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): diff --git a/CANLibrary/example.py b/CANLibrary/example.py index c6e2f02..91a9dfa 100644 --- a/CANLibrary/example.py +++ b/CANLibrary/example.py @@ -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'