43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import serial
|
|
import pandas as pd
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
with serial.Serial('/dev/cu.usbserial-1420', 115200, timeout=1, parity=serial.PARITY_NONE) as ser:
|
|
x = ser.read() # read one byte
|
|
s = ser.read(10) # read up to ten bytes (timeout)
|
|
line = ser.readline() # read a '\n' terminated line
|
|
print(x)
|
|
print(s)
|
|
print(line)
|
|
ser.write(b'B')
|
|
while True:
|
|
x = ser.read()
|
|
b = ser.read(100)
|
|
line = ser.readline()
|
|
print(b)
|
|
if 'Buffer Completed' in b.decode("utf-8"):
|
|
ser.write(b'S')
|
|
while True:
|
|
x = ser.read()
|
|
s = ser.read(100)
|
|
line = ser.readline()
|
|
print(s)
|
|
if 'Sample Completed' in s.decode("utf-8"):
|
|
ser.write(b'P')
|
|
while True:
|
|
x = ser.read()
|
|
r = ser.read(100)
|
|
line = ser.readline()
|
|
print(r)
|
|
if 'RESULT' in r.decode("utf-8") or 'REND' in r.decode('utf-8'):
|
|
print(r)
|
|
break
|
|
break
|
|
break
|
|
except serial.serialutil.SerialException:
|
|
print("connect device!")
|
|
except:
|
|
print("error!")
|
|
|