diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-04-24 00:46:23 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-04-24 00:46:23 -0400 |
commit | 302360954c9851b0d69ce1ee9458ada7c070fabf (patch) | |
tree | 98164ebef99b6fe7faf28160270040c794dea45b | |
parent | d79dc484616e67f4d7c4fe04a701f575973db2c3 (diff) | |
download | pyExpControl-302360954c9851b0d69ce1ee9458ada7c070fabf.tar.gz pyExpControl-302360954c9851b0d69ce1ee9458ada7c070fabf.zip |
speed up of communications
-rwxr-xr-x | test_serial.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/test_serial.py b/test_serial.py index f486945..1d071d9 100755 --- a/test_serial.py +++ b/test_serial.py @@ -6,8 +6,8 @@ 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 = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
+# sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser), line_buffering=True, newline='\r\n')
# ser.write(b'dofile("bits_converging.lua")\r')
@@ -36,15 +36,10 @@ sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser), line_buffering=True) 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()
+ 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) )
|