From a0a7c8f3a2fe49f24546ae2d9f1d14fb11c3b556 Mon Sep 17 00:00:00 2001
From: Bob Jacobsen
Date: Sun, 28 May 2023 11:00:48 -0400
Subject: [PATCH 01/35] Python 3 syntax changes
---
connection.py | 34 +++++++--------
monitor.py | 2 +-
serialolcblink.py | 106 +++++++++++++++++++++++-----------------------
3 files changed, 71 insertions(+), 71 deletions(-)
diff --git a/connection.py b/connection.py
index 61b26bd..4bcbfed 100755
--- a/connection.py
+++ b/connection.py
@@ -12,35 +12,35 @@
network = defaults.network
-thisNodeID = defaults.thisNodeID
+thisNodeID = defaults.thisNodeID
thisNodeAlias = defaults.thisNodeAlias
-testNodeID = defaults.testNodeID
+testNodeID = defaults.testNodeID
testNodeAlias = defaults.testNodeAlias
def main():
usage()
-
+
return # done with example
-
+
def list() :
- print "network.host = "+network.host
- print "network.port = "+str(network.port)
- print "thisNodeID = ",thisNodeID
- print "thisNodeAlias = "+hex(thisNodeAlias)
- print "testNodeID = ",testNodeID
- print "testNodeAlias = "+hex(testNodeAlias)
+ print ("network.host = "+network.host)
+ print ("network.port = "+str(network.port))
+ print ("thisNodeID = ",thisNodeID)
+ print ("thisNodeAlias = "+hex(thisNodeAlias))
+ print ("testNodeID = ",testNodeID)
+ print ("testNodeAlias = "+hex(testNodeAlias))
return
def usage() :
- print ""
- print "Python module for defining the layout connection."
- print ""
- print "Invoked by other routines to know how to send, "
- print "not intended to be invoked standalone"
- print ""
+ print ("")
+ print ("Python module for defining the layout connection.")
+ print ("")
+ print ("Invoked by other routines to know how to send, ")
+ print ("not intended to be invoked standalone")
+ print ("")
list()
return
-
+
if __name__ == '__main__':
main()
diff --git a/monitor.py b/monitor.py
index d698f3d..ebe23f4 100755
--- a/monitor.py
+++ b/monitor.py
@@ -11,7 +11,7 @@
def main():
while (True) :
frame = connection.network.receive()
- if (frame != None ) : print frame,
+ if (frame != None ) : print (frame),
return
if __name__ == '__main__':
diff --git a/serialolcblink.py b/serialolcblink.py
index 31b7042..6ce43e2 100755
--- a/serialolcblink.py
+++ b/serialolcblink.py
@@ -11,7 +11,7 @@
class SerialOlcbLink :
def __init__(self) :
-
+
# defaults (generally overridden by system-wide defaults elsewhere)
self.port = "/dev/tty.usbserial-A7007AOK"
self.speed = 115200
@@ -21,21 +21,21 @@ def __init__(self) :
self.startdelay = 0 # set to 12 if your hardware resets on connection
self.ser = None
return
-
+
def connect(self) :
# if verbose, print
- if (self.verbose) : print " connect to ",self.port," at ",self.speed
-
+ if (self.verbose) : print (" connect to ",self.port," at ",self.speed)
+
self.ser = serial.Serial(self.port, self.speed)
self.ser.parity = serial.PARITY_NONE
self.ser.bytesize = serial.EIGHTBITS
self.ser.stopbits = serial.STOPBITS_TWO
- self.ser.setXonXoff(True)
- self.ser.rtscts = False
- self.ser.dsrdtr = False
+ #self.ser.setXonXoff(True)
+ #self.ser.rtscts = False
+ #self.ser.dsrdtr = False
self.ser.setDTR(True)
self.ser.setRTS(True)
-
+
# from http://bytes.com/topic/python/answers/170478-uart-parity-setting-mark-space-using-pyserial
if self.speed == 230400 and not self.parallel :
self.ser.parity = serial.PARITY_EVEN
@@ -44,23 +44,23 @@ def connect(self) :
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self.ser)
cflag |= 0x40000000 # CMSPAR to select MARK parity
termios.tcsetattr(self.ser, termios.TCSANOW, [iflag, oflag, cflag, lflag,ispeed, ospeed, cc])
-
-
+
+
# wait default time for Arduino startup
# after (possible) reset due to serial startup
if self.startdelay > 0 :
- if self.verbose : print " waiting", self.startdelay, "seconds for adapter restart"
+ if self.verbose : print (" waiting", self.startdelay, "seconds for adapter restart")
time.sleep(self.startdelay)
# dump all messages
while self.ser.inWaiting() > 0 :
self.ser.readline()
return
-
+
def send(self, frame) :
if self.ser == None : self.connect()
-
+
# if verbose, print
- if self.verbose : print " send ",frame
+ if self.verbose : print (" send ",frame)
# double-output format needed if operating at 230400
tframe = frame+'\n'
@@ -71,28 +71,28 @@ def send(self, frame) :
tframe = tframe+";;"
# send
self.ser.write(tframe)
-
+
return
-
+
def receive(self) : # returns frame
if (self.ser == None) : self.connect()
-
+
# if verbose, print
- if (self.verbose) : print " receive ",
-
+ if (self.verbose) : print (" receive "),
+
self.ser.timeout = self.timeout
line = "";
r = self.ser.readline()
# remove Xoff/Xon characters if present
- r = r.replace("\x11", "")
- r = r.replace("\x13", "")
+ #r = r.replace("\x11", "")
+ #r = r.replace("\x13", "")
# timeout returns ""
- if r == "" :
- if (self.verbose) : print "" # blank line to show delay?
+ if r == "" :
+ if (self.verbose) : print ("") # blank line to show delay?
return None
- # if verbose, display what's received
- if (self.verbose) : print r.replace("\x0A", "").replace("\x0D", "")
- return r
+ # if verbose, display what's received
+ if (self.verbose) : print (r.replace("\x0A", "").replace("\x0D", ""))
+ return r
def close(self) :
return
@@ -101,56 +101,56 @@ def close(self) :
def main():
global frame
-
+
# create connection object
network = SerialOlcbLink()
# get defaults
- port = network.port
+ port = network.port
speed = network.speed
verbose = network.verbose
-
+
frame = ':X180A7000N;'
# process arguments
(port, speed, frame, verbose) = args(port, speed, frame, verbose)
-
+
# load new defaults
network.port = port
network.speed = speed
network.verbose = verbose
-
+
# send the frame
network.send(frame)
while True :
network.receive()
-
+
return # done with example
def usage() :
- print ""
- print "Python module for connecting to an OpenLCB via an serial connection."
- print "Called standalone, will send one CAN frame."
- print ""
- print "valid options:"
- print " -v for verbose; also displays any responses"
- print " -p, --port for serial port to USB connection"
- print " -s, --speed for baud rate"
- print ""
- print "valid usages (default values):"
- print " python serialolcblink.py --port=/dev/tty.usbserial-A7007AOK"
- print " python serialolcblink.py --port=/dev/tty.usbserial-A7007AOK --speed=115200"
- print " python serialolcblink.py --port=/dev/tty.usbserial-A7007AOK --speed=115200 :X180A7000N;\;"
- print ""
- print "Note: Most shells require escaping the semicolon at the end of the frame."
-
+ print ("")
+ print ("Python module for connecting to an OpenLCB via an serial connection.")
+ print ("Called standalone, will send one CAN frame.")
+ print ("")
+ print ("valid options:")
+ print (" -v for verbose; also displays any responses")
+ print (" -p, --port for serial port to USB connection")
+ print (" -s, --speed for baud rate")
+ print ("")
+ print ("valid usages (default values):")
+ print (" python serialolcblink.py --port=/dev/tty.usbserial-A7007AOK")
+ print (" python serialolcblink.py --port=/dev/tty.usbserial-A7007AOK --speed=115200")
+ print (" python serialolcblink.py --port=/dev/tty.usbserial-A7007AOK --speed=115200 :X180A7000N;\;")
+ print ("")
+ print ("Note: Most shells require escaping the semicolon at the end of the frame.")
+
def args(port, speed, frame, verbose) :
# argument processing
try:
opts, remainder = getopt.getopt(sys.argv[1:], "s:p:v", ["speed=", "port="])
- except getopt.GetoptError, err:
+ except getopt.GetoptError as err:
# print help information and exit:
- print str(err) # will print something like "option -a not recognized"
+ print (str(err)) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for opt, arg in opts:
@@ -162,10 +162,10 @@ def args(port, speed, frame, verbose) :
speed = int(arg)
else:
assert False, "unhandled option"
- if (len(remainder) > 0) :
+ if (len(remainder) > 0) :
frame = remainder[0]
return (port, speed, frame, verbose)
-
+
if __name__ == '__main__':
main()
-
+
From d9262e834c0b37e7a7ea75e3d5561cd5710e2039 Mon Sep 17 00:00:00 2001
From: Bob Jacobsen
Date: Sun, 28 May 2023 11:53:16 -0400
Subject: [PATCH 02/35] p3; improve output
---
testStartup.py | 160 ++++++++++++++++++++++++++-----------------------
1 file changed, 85 insertions(+), 75 deletions(-)
diff --git a/testStartup.py b/testStartup.py
index 0720f83..72ae98d 100755
--- a/testStartup.py
+++ b/testStartup.py
@@ -26,18 +26,19 @@
import canolcbutils
import time
-
+import sys
+
def usage() :
- print ""
- print "Called standalone, tests a nodes startup processing."
- print "Reset the node (or force startup) after the script starts"
- print ""
- print "Default connection detail taken from connection.py"
- print ""
- print "-a --alias source alias"
- print "-d --dest destination (target node) starting alias"
- print "-v verbose"
- print "-V very verbose"
+ print ("")
+ print ("Called standalone, tests a nodes startup processing.")
+ print ("Reset the node (or force startup) when prompted")
+ print ("")
+ print ("Default connection detail taken from connection.py")
+ print ("")
+ print ("-a --alias source alias")
+ print ("-d --dest destination (target node) starting alias")
+ print ("-v verbose")
+ print ("-V very verbose")
import getopt, sys
@@ -45,13 +46,13 @@ def main():
alias = connection.thisNodeAlias;
dest = connection.testNodeAlias;
verbose = False
-
+
# argument processing
try:
opts, remainder = getopt.getopt(sys.argv[1:], "d:a:vV", ["alias=", "dest="])
- except getopt.GetoptError, err:
+ except getopt.GetoptError as err:
# print help information and exit:
- print str(err) # will print something like "option -a not recognized"
+ print (str(err)) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for opt, arg in opts:
@@ -69,152 +70,161 @@ def main():
retval = test(alias, dest, connection, verbose)
connection.network.close()
- return retval
-
+ sys.exit(retval)
+
def test(alias, dest, connection, verbose) :
# wait for reset
-
- # expect RIF sequence (check timing)
+
+ # expect RIF sequence after reset, check timing
timeout = connection.network.timeout
connection.network.timeout = 25
connection.network.connect()
- if verbose : print "Restart node now"
+
+ print ("Restart node now")
+
reply = connection.network.receive()
- if verbose : print "Start checking node output"
+ if verbose : print ("Start checking node output")
while (True) :
if reply == None :
- print "1st CIM reply not received, did you reset node?"
+ print ("1st CIM reply not received, did you reset node?")
return 1
elif reply.startswith(":X17") :
break
elif reply.startswith(":X") :
- if verbose: print "ignoring unexpected frame", reply
+ if verbose: print ("ignoring unexpected frame", reply)
else :
- if verbose: print "ignoring misc characters not a frame: ", reply
+ if verbose: print ("ignoring misc characters not a frame: ", reply)
reply = connection.network.receive()
-
+
connection.network.timeout = timeout
testAlias = reply[7:10]
if testAlias == "000" :
- print "node using alias == 0"
+ print ("node using alias == 0")
return 331
-
+
id = reply[4:7]
start = time.time()
-
+
reply = connection.network.receive()
if reply == None :
- print "2nd CIM reply not received"
+ print ("2nd CIM reply not received")
return 2
if reply[7:10] != testAlias :
- print "mismatched 2nd CIM source alias"
+ print ("mismatched 2nd CIM source alias")
return 12
if not reply.startswith(":X16") :
- print "2nd CIM reply not correct"
+ print ("2nd CIM reply not correct")
return 32
id = id+reply[4:7]
reply = connection.network.receive()
if reply == None :
- print "3rd CIM reply not received"
+ print ("3rd CIM reply not received")
return 3
if reply[7:10] != testAlias :
- print "mismatched 3rd CIM source alias"
+ print ("mismatched 3rd CIM source alias")
return 13
if not reply.startswith(":X15") :
- print "3rd CIM reply not correct"
+ print ("3rd CIM reply not correct")
return 33
id = id+reply[4:7]
reply = connection.network.receive()
if reply == None :
- print "4th CIM reply not received"
- return 4
+ print ("4th CIM reply not received")
+ return (4)
if reply[7:10] != testAlias :
- print "mismatched 4th CIM source alias"
- return 14
+ print ("mismatched 4th CIM source alias")
+ return (14)
if not reply.startswith(":X14") :
- print "4th CIM reply not correct"
- return 34
+ print ("4th CIM reply not correct")
+ return (34)
id = id+reply[4:7]
-
- # expect CIF (check timing)
- connection.network.timeout = 1
+
+ # expect RIM (check timing)
+ connection.network.timeout = 1
reply = connection.network.receive()
end = time.time()
connection.network.timeout = timeout
if reply == None :
- print "RIM reply not received"
- return 5
+ print ("RIM reply not received")
+ return (5)
if not reply.startswith(":X10700") :
- print "RIM reply not correct"
- return 35
+ print ("RIM reply not correct")
+ return (35)
if reply[7:10] != testAlias :
- print "mismatched RIM source alias"
- return 15
+ print ("mismatched RIM source alias")
+ return (15)
- if verbose : print "delay was ", end-start
+ if verbose : print (" delay was ", end-start)
if end-start < 0.15 :
# some tolerance on check...
- print "did not wait long enough ", end-start
- return 22
+ print ("did not wait long enough ", end-start)
+ return (22)
if end-start > .55 :
# some tolerance on check...
- print "waited too long ", end-start
- return 22
+ print ("waited too long ", end-start)
+ return (22)
# expect AMD
reply = connection.network.receive()
if reply == None :
- print "AMD reply not received"
- return 6
+ print ("AMD reply not received")
+ return (6)
if not reply.startswith(":X10701") :
- print "AMD reply not correct"
- return 35
+ print ("AMD reply not correct")
+ return (35)
if reply[7:10] != testAlias :
- print "mismatched AMD source alias"
- return 16
+ print ("mismatched AMD source alias")
+ return (16)
if id != reply[11:23] :
- print "AMD node ID ",reply[11:23]," did not match one in CID frames ",id
- return 21
-
+ print ("AMD node ID ",reply[11:23],") did not match one in CID frames ",id)
+ return (21)
+
# expect NodeInit
reply = connection.network.receive()
if reply == None :
- print "NodeInit reply not received"
+ print ("NodeInit reply not received")
return 7
if not reply.startswith(":X19100") :
- print "NodeInit reply not correct"
+ print ("NodeInit reply not correct")
return 37
if reply[7:10] != testAlias :
- print "mismatched NodeInit source alias"
+ print ("mismatched NodeInit source alias")
return 17
if id != reply[11:23] :
- print "NodeInit node ID did not match",id, reply[11:23]
- return 27
-
- # expect one or more Produced/Consumed messages
+ print ("NodeInit node ID did not match",id, reply[11:23])
+ return (27)
+
+ # expect zero or more Produced/Consumed messages
consumed = []
produced = []
- while (True) :
+ start = time.time()
+ while (time.time() - start < 5.0) :
reply = connection.network.receive()
if (reply == None ) : break
if (reply.startswith(":X194C")) :
event = canolcbutils.bodyArray(reply)
- if verbose : print "consumes ", event
+ if verbose : print ("consumes ", event)
consumed = consumed+[event]
elif (reply.startswith(":X1954")) :
event = canolcbutils.bodyArray(reply)
- if verbose : print "produces ", event
+ if verbose : print ("produces ", event)
produced = produced+[event]
elif (reply.startswith(":X195B4")) :
event = canolcbutils.bodyArray(reply)
- if verbose : print "event produced", event
+ if verbose : print ("event produced", event)
+ elif (reply.startswith(":X198F4")) :
+ event = canolcbutils.bodyArray(reply)
+ if verbose : print ("Identify Consumer request ", event)
+ elif (reply.startswith(":X19914")) :
+ event = canolcbutils.bodyArray(reply)
+ if verbose : print ("Identify Producer request ", event)
else :
- print "Unexpected message"
- return 50
+ print ("Unexpected message ", reply)
+ return (50)
return 0
if __name__ == '__main__':
From fe2b765a8f5a6ce50f6bc29c80b36a0faaab0aee Mon Sep 17 00:00:00 2001
From: Bob Jacobsen
Date: Sun, 28 May 2023 11:53:50 -0400
Subject: [PATCH 03/35] python3
---
canolcbutils.py | 15 +++++++--------
serialolcblink.py | 11 ++++-------
2 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/canolcbutils.py b/canolcbutils.py
index 31e7b53..8505f58 100755
--- a/canolcbutils.py
+++ b/canolcbutils.py
@@ -27,10 +27,10 @@ def makeframestring(header, body) :
def splitSequence(seq) :
strings = seq.split('.')
result = []
- for a in strings :
+ for a in strings :
result = result+[int(a, 16)]
return result
-
+
'''
Pull body bytes from frame as array
'''
@@ -41,7 +41,7 @@ def bodyArray(frame) :
result = result+[int(string[:2],16)]
string = string[2:]
return result
-
+
'''
Return (header, body) of a P/C Event Report frame
alias: the source alias of this node
@@ -53,11 +53,10 @@ def eventframe(alias, event) :
def main():
(header, body) = eventframe(0x123, [11,255,240,4,5,6,7,8]);
- print makeframestring(header, body)
- print splitSequence("1.2.3.a.0a.10.4")
- print bodyArray(":X1E000000F010203040506;")
-
+ print (makeframestring(header, body))
+ print (splitSequence("1.2.3.a.0a.10.4"))
+ print (bodyArray(":X1E000000F010203040506;"))
+
if __name__ == '__main__':
main()
-
\ No newline at end of file
diff --git a/serialolcblink.py b/serialolcblink.py
index 6ce43e2..530d5f2 100755
--- a/serialolcblink.py
+++ b/serialolcblink.py
@@ -77,21 +77,18 @@ def send(self, frame) :
def receive(self) : # returns frame
if (self.ser == None) : self.connect()
- # if verbose, print
- if (self.verbose) : print (" receive "),
-
self.ser.timeout = self.timeout
line = "";
r = self.ser.readline()
# remove Xoff/Xon characters if present
- #r = r.replace("\x11", "")
- #r = r.replace("\x13", "")
+ r = r.decode('utf8').replace("\x11", "")
+ r = r.replace("\x13", "")
# timeout returns ""
if r == "" :
- if (self.verbose) : print ("") # blank line to show delay?
+ if (self.verbose) : print (" receive ") # blank line to show delay?
return None
# if verbose, display what's received
- if (self.verbose) : print (r.replace("\x0A", "").replace("\x0D", ""))
+ if (self.verbose) : print (" receive "+r.replace("\x0A", "").replace("\x0D", ""))
return r
def close(self) :
From 6dc447e6b6455718acee1d71495718988fb2cf1a Mon Sep 17 00:00:00 2001
From: Bob Jacobsen
Date: Sun, 28 May 2023 12:32:44 -0400
Subject: [PATCH 04/35] for py3
---
ethernetolcblink.py | 90 ++++++++++++++++++++++-----------------------
serialolcblink.py | 3 +-
2 files changed, 45 insertions(+), 48 deletions(-)
diff --git a/ethernetolcblink.py b/ethernetolcblink.py
index a14c482..b2fe147 100755
--- a/ethernetolcblink.py
+++ b/ethernetolcblink.py
@@ -15,7 +15,7 @@ def __init__(self) :
# prepare, but don't open
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#self.socket.timeout(10)
-
+
# defaults (generally overridden by system-wide defaults elsewhere)
self.host = "10.00.01.98" # Arduino adapter default
self.port = 23
@@ -25,49 +25,46 @@ def __init__(self) :
self.socket = None
self.rcvData = ""
return
-
+
def connect(self) :
# if verbose, print
- if (self.verbose) : print " connect to ",self.host,":",self.port
-
+ if (self.verbose) : print (" connect to ",self.host,":",self.port)
+
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((self.host, self.port))
-
+
# wait for link startup
# after (possible) reset due to serial startup
if self.startdelay > 0 :
- if self.verbose : print " waiting", self.startdelay, "seconds for adapter restart"
+ if self.verbose : print (" waiting", self.startdelay, "seconds for adapter restart")
time.sleep(self.startdelay)
return
-
+
def send(self, frame) :
if (self.socket == None) : self.connect()
-
+
# if verbose, print
- if (self.verbose) : print " send ",frame
-
+ if (self.verbose) : print (" send ",frame)
+
# send
- self.socket.send(frame+'\n')
-
+ self.socket.send((frame+'\n').encode())
+
return
-
+
def receive(self) : # returns frame
if (self.socket == None) : self.connect()
-
- # if verbose, print
- if (self.verbose) : print " receive ",
-
+
self.socket.settimeout(self.timeout)
while (self.rcvData.find('\n') < 0) :
try:
self.rcvData = self.rcvData+self.socket.recv(1024)
- except socket.timeout, err:
- if (self.verbose) : print "" # blank line to show delay?
+ except socket.timeout as err:
+ if (self.verbose) : print (" receive ") # blank line to show delay?
return None
r = self.rcvData[0:self.rcvData.find('\n')]
self.rcvData = self.rcvData[self.rcvData.find('\n')+1:]
- if (self.verbose) : print r
+ if (self.verbose) : print (" receive "+r)
return r
def close(self) :
@@ -78,54 +75,54 @@ def close(self) :
def main():
global frame
-
+
# create connection object
network = EthernetToOlcbLink()
# get defaults
- host = network.host
+ host = network.host
port = network.port
verbose = network.verbose
-
+
frame = ':X182DF123N0203040506080001;'
# process arguments
(host, port, frame, verbose) = args(host, port, frame, verbose)
-
+
# load new defaults
network.host = host
network.port = port
network.verbose = verbose
-
+
# send the frame
network.send(frame)
-
+
return # done with example
def usage() :
- print ""
- print "Python module for connecting to an OpenLCB via an Ethernet connection."
- print "Called standalone, will send one CAN frame."
- print ""
- print "valid options:"
- print " -v for verbose; also displays any responses"
- print " -h, --host for host name or IP address"
- print " -p, --port for port number"
- print ""
- print "valid usages (default values):"
- print " ./ethernetolcblink.py --host=10.00.01.98"
- print " ./ethernetolcblink.py --host=10.00.01.98 --port=23"
- print " ./ethernetolcblink.py --host=10.00.01.98 --port=23 :X182DF123N0203040506080001\;"
- print ""
- print "Note: Most shells require escaping the semicolon at the end of the frame."
-
+ print ("")
+ print ("Python module for connecting to an OpenLCB via an Ethernet connection.")
+ print ("Called standalone, will send one CAN frame.")
+ print ("")
+ print ("valid options:")
+ print (" -v for verbose; also displays any responses")
+ print (" -h, --host for host name or IP address")
+ print (" -p, --port for port number")
+ print ("")
+ print ("valid usages (default values):")
+ print (" ./ethernetolcblink.py --host=10.00.01.98")
+ print (" ./ethernetolcblink.py --host=10.00.01.98 --port=23")
+ print (" ./ethernetolcblink.py --host=10.00.01.98 --port=23 :X182DF123N0203040506080001\;")
+ print ("")
+ print ("Note: Most shells require escaping the semicolon at the end of the frame.")
+
def args(host, port, frame, verbose) :
# argument processing
try:
opts, remainder = getopt.getopt(sys.argv[1:], "h:p:v", ["host=", "port="])
- except getopt.GetoptError, err:
+ except getopt.GetoptError as err:
# print help information and exit:
- print str(err) # will print something like "option -a not recognized"
+ print (str(err)) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for opt, arg in opts:
@@ -137,10 +134,9 @@ def args(host, port, frame, verbose) :
port = int(arg)
else:
assert False, "unhandled option"
- if (len(remainder) > 0) :
+ if (len(remainder) > 0) :
frame = remainder[0]
return (host, port, frame, verbose)
-
+
if __name__ == '__main__':
main()
-
\ No newline at end of file
diff --git a/serialolcblink.py b/serialolcblink.py
index 530d5f2..639a57e 100755
--- a/serialolcblink.py
+++ b/serialolcblink.py
@@ -36,6 +36,7 @@ def connect(self) :
self.ser.setDTR(True)
self.ser.setRTS(True)
+
# from http://bytes.com/topic/python/answers/170478-uart-parity-setting-mark-space-using-pyserial
if self.speed == 230400 and not self.parallel :
self.ser.parity = serial.PARITY_EVEN
@@ -70,7 +71,7 @@ def send(self, frame) :
tframe = tframe+c+c
tframe = tframe+";;"
# send
- self.ser.write(tframe)
+ self.ser.write(tframe.encode())
return
From 42d2f92f0c2c98f56567884375063094dbe3a3d5 Mon Sep 17 00:00:00 2001
From: Bob Jacobsen
Date: Sun, 28 May 2023 12:41:48 -0400
Subject: [PATCH 05/35] py3
---
verifyNodeGlobal.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/verifyNodeGlobal.py b/verifyNodeGlobal.py
index ca8f3b2..dc02551 100755
--- a/verifyNodeGlobal.py
+++ b/verifyNodeGlobal.py
@@ -72,19 +72,19 @@ def main():
# now execute
retval = test(options.alias, options.nodeid, connection)
connection.network.close()
- exit(retval)
-
+ exit(retval)
+
def test(alias, nodeID, connection):
# first, send to this node
connection.network.send(makeframe(alias, nodeID))
if (connection.network.expect(startswith=":X19170", data=nodeID) == None) :
- print "Global verify with matching node ID did not receive expected reply"
+ print ("Global verify with matching node ID did not receive expected reply")
return 2
# send without node ID
connection.network.send(makeframe(alias, None))
if (connection.network.expect(startswith=":X19170", data=nodeID) == None) :
- print "Global verify without node ID did not receive expected reply"
+ print ("Global verify without node ID did not receive expected reply")
return 12
# allow time for the bus to settle
@@ -98,7 +98,7 @@ def test(alias, nodeID, connection):
if (reply == None) :
return 0
else :
- print "Global verify with wrong node ID should not receive reply but did: ", reply
+ print ("Global verify with wrong node ID should not receive reply but did: ", reply)
return 24
if __name__ == '__main__':
From f7e24b715dcefd88cef3613f6406a504fda9d730 Mon Sep 17 00:00:00 2001
From: Bob Jacobsen
Date: Sun, 28 May 2023 18:52:44 -0400
Subject: [PATCH 06/35] drop unavailable option
---
index.html | 58 +++++++++++++++++++++++++++---------------------------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/index.html b/index.html
index a15258f..1a5b7ff 100644
--- a/index.html
+++ b/index.html
@@ -20,20 +20,20 @@
This is the index page of the OpenLCB™ Python prototypes
directory.
Most of the Python modules in this package are meant to be run
-from the command line, or invoked programmatically.
+from the command line, or invoked programmatically.
To run one from the Mac OS X or Linux command line, first edit the
defaults.py file with your connection
-information, then do e.g.:
+information, then do e.g.:
./verifyNodeGlobal.py -v
To run the full set of tests from the Mac OS X or Linux command line,
-do :
+do :
./allTest.py -t -v && echo OK
-followed by testing the start-up sequencing with :
+followed by testing the start-up sequencing with :
-./testStartup.py -t -v && echo OK
+
./testStartup.py && echo OK
(Reset the node when prompted to force the start-up sequence to run)
When running from the command line, internal help is available via
the -h option, as in:
@@ -53,99 +53,99 @@
There are text files containing typical
-output from running
+output from running
./allTest.py -t -V
-and
+and
./testStartup.py -t -V
test scripts that you can consult to see what normal operation looks
like. Note that they contain node IDs, aliases, and event IDs that
-are specific to the particular node being tested, so your mileage
+are specific to the particular node being tested, so your mileage
-vary.
+
vary.
The type of access (Ethernet or USB)
and parameters such as IP address, default node IDs, etc are defined
in the default.py file. When using the command line, edit that file
for your specific needs. If you're using a serial connection, you
-need to have PySerial installed, which is
+need to have PySerial installed, which is
described here.
Utilities and Modules
The basic Ethernet connection is accessed via the
-"ethernetolcblink" module.
+"ethernetolcblink" module.
import ethernetolcblink
The basic USB-Serial connection is accessed via the "serialolcblink"
-module.
+module.
import serialolcblink
Other cross-connection utilities can found in the "canolcbutils"
-module.
+module.
Frame and Message Tools
- verifyNodeGlobal
-
Send a "Verify Node Global" message, getting a reply from
- each connected node.
+ each connected node.
-
verifyNodeAddressed
-
Send a "Verify Node Addressed" message, getting a reply
- from the addressed node.
+ from the addressed node.
-
identifyConsumers
-
Send an "Identify Consumers" message, which will generate
- a reply from any node using consuming the Event ID
+ a reply from any node using consuming the Event ID
-
identifyProducers
-
Send a "Identify Producers" message, which will generate a
- reply from any node using consuming the Event ID.
+ reply from any node using consuming the Event ID.
-
identifyEventsGlobal
-
Send a "Identify Events Global" message, getting a reply
- from each connected node.
+ from each connected node.
-
identifyEventsAddressed
-
- Send a "Verify Node Global" message.
+ Send a "Verify Node Global" message.
-
datagram
-
- Send a "datagram" message.
+ Send a "datagram" message.
Tests
- allTest
-
- Runs the complete set of tests in sequence
+ Runs the complete set of tests in sequence
-
testProducerConsumerNotification
-
Uses IdentifyEvents to learn which events a node produces and
consumes, then checks that IdentifyConsumers and IdentifyProducers
- will find them.
+ will find them.
-
testConfigurationProtocol
-
- Does a sequence of tests of the configuration protocol
+ Does a sequence of tests of the configuration protocol
-
testConfigurationProtocol
-
- Does a sequence of tests of the configuration protocol
+ Does a sequence of tests of the configuration protocol
Tools
- monitor
-
- Monitors received frames until cancelled
+ Monitors received frames until cancelled
-
readConfiguration
-
- Reads from a node via the configuration protocol
+ Reads from a node via the configuration protocol
-
ethernetolcblink
-
- Allows you to send specific CAN frames via an Ethernet adapter
+ Allows you to send specific CAN frames via an Ethernet adapter
-
getUnderTestAlias
-
Assumes there is only one node attached, and finds the alias for
- addressing it.
+ addressing it.
@@ -156,4 +156,4 @@
page.
This is SVN $Revision$ of 08/16/09.