From 302360954c9851b0d69ce1ee9458ada7c070fabf Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Sat, 24 Apr 2021 00:46:23 -0400 Subject: speed up of communications --- test_serial.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'test_serial.py') 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) ) -- cgit v1.2.3