aboutsummaryrefslogtreecommitdiff
path: root/test_serial.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-24 00:23:55 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-24 00:23:55 -0400
commitd79dc484616e67f4d7c4fe04a701f575973db2c3 (patch)
tree5e18a85860dc612fb0ce29ae5a3848987b84df6c /test_serial.py
parentadba2bece3eae3e204398ec7464b61b1e3cb730a (diff)
downloadpyExpControl-d79dc484616e67f4d7c4fe04a701f575973db2c3.tar.gz
pyExpControl-d79dc484616e67f4d7c4fe04a701f575973db2c3.zip
draft of serial protocol
Diffstat (limited to 'test_serial.py')
-rwxr-xr-xtest_serial.py65
1 files changed, 65 insertions, 0 deletions
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()