aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-24 12:06:46 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-04-24 12:06:46 -0400
commit934e791190009e1a67ae8084eb1e2c71b2723f76 (patch)
tree3f5112ccde3a59371d32d317adcfa5d62ff183ef
parent302360954c9851b0d69ce1ee9458ada7c070fabf (diff)
downloadpyExpControl-934e791190009e1a67ae8084eb1e2c71b2723f76.tar.gz
pyExpControl-934e791190009e1a67ae8084eb1e2c71b2723f76.zip
changes in serial
-rwxr-xr-xtest_serial.py41
1 files changed, 14 insertions, 27 deletions
diff --git a/test_serial.py b/test_serial.py
index 1d071d9..8587e19 100755
--- a/test_serial.py
+++ b/test_serial.py
@@ -5,10 +5,8 @@ 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=1)
-# sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser), line_buffering=True, newline='\r\n')
-
+ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
+# ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
# ser.write(b'dofile("bits_converging.lua")\r')
# ser.write(b'dofile("microwire.lua")\r')
@@ -19,30 +17,17 @@ ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
# 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()
+ # start = datetime.now()
ser.write(bytes(cmd+'\r','ascii'))
- # sio.write(cmd+'\r')
- line = ser.read_until(terminator=b'> ')
- print(line)
- stop = datetime.now()
- runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000
- print("Command: " + cmd + " runtime %s seconds." % (runTime) )
+ resp = ser.read_until(terminator=b'> ')
+ resp = resp.decode('utf-8')
+ # print(resp)
+ # stop = datetime.now()
+ # runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000
+ # print("Command: " + cmd + " runtime %s seconds." % (runTime) )
+ return resp
sendSerialCmd("print(2+3)")
@@ -50,8 +35,10 @@ line = ser.readline()
print(line)
start = datetime.now()
-for i in range(1,10):
- sendSerialCmd("print(node.heap())")
+# resp = sendSerialCmd("print(node.heap())")
+# resp = sendSerialCmd(""); # empty command
+resp = sendSerialCmd("Sb, muSb= rtctime.get(); print(4); Se, muSe =rtctime.get(); print(\"execution time: \" .. muSe-muSb .. \" muS\")")
+print(resp)
stop = datetime.now()
runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000
print("runtime %s seconds." % (runTime) )