diff options
Diffstat (limited to 'test_serial.py')
-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) )
|