Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial
- import time
- import array as arr
- STX = 2
- ETX = 3
- ser = serial.Serial(
- port='COM2',\
- baudrate=9600,\
- parity=serial.PARITY_NONE,\
- stopbits=serial.STOPBITS_ONE,\
- bytesize=serial.EIGHTBITS,\
- timeout=0)
- print("connected to: " + ser.portstr)
- #this will store the line
- val = []
- res = bytearray()
- readString = 0
- while True:
- read = bytes(ser.read(2))
- #print(read)
- if read == b'\x03':
- readString=0
- ## TODO:
- print(res)
- print(res).decode("CP852")
- else:
- if read == b'\x02':
- res = []
- readString = 1
- else:
- res += read
- ser.close()
Advertisement
Add Comment
Please, Sign In to add comment