From d79dc484616e67f4d7c4fe04a701f575973db2c3 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Sat, 24 Apr 2021 00:23:55 -0400 Subject: draft of serial protocol --- test_serial.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 test_serial.py (limited to 'test_serial.py') diff --git a/test_serial.py b/test_serial.py new file mode 100755 index 0000000..f486945 --- /dev/null +++ b/test_serial.py @@ -0,0 +1,65 @@ +import serial +import io + +import time # For sleep, clock, time and perf_counter +from datetime import datetime, timedelta + +# ser = serial.Serial('COM4', 115200, timeout=1) +# ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1) +ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=.2) +sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser), line_buffering=True) + + +# ser.write(b'dofile("bits_converging.lua")\r') +# ser.write(b'dofile("microwire.lua")\r') +# ser.write(b'dofile("lmx2487lib.lua")\r') +# ser.write(b'dofile("Frequency_Settings.lua")\r') + +# ser.write(b'settings = initSettings()\r') +# ser.write(b'settings = set_lmx2487_to_Frequency (startfreq, settings)\r') + + +# ser.write(b'\rprint(2+2)\r') +# ser.write(b'print(node.heap())\r') +# s = ser.read(100) + +# print("1st reply") +# print(s) +# line = ser.readline() +# print(line) +# line = ser.readline() +# print(line) +# line = ser.readline() +# print(line) +# line = ser.readline() +# print(line) + +def sendSerialCmd(cmd): + start = datetime.now() + # ser.write(bytes(cmd+'\r','ascii')) + sio.write(cmd+'\r') + line = sio.readline() + while line: + line = line.rstrip() + print(line) + if line == '>': + break + line = sio.readline() + stop = datetime.now() + runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 + print("Command: " + cmd + " runtime %s seconds." % (runTime) ) + +sendSerialCmd("print(2+3)") + +line = ser.readline() +print(line) + +start = datetime.now() +for i in range(1,10): + sendSerialCmd("print(node.heap())") +stop = datetime.now() +runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 +print("runtime %s seconds." % (runTime) ) + + +ser.close() -- cgit v1.2.3