33 lines
761 B
Python
33 lines
761 B
Python
import serial
|
|
|
|
def main():
|
|
s = serial.Serial(port="/dev/ttyACM0", parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=1)
|
|
s.flush()
|
|
|
|
rw = input('Read or Write tags? [R/w]')
|
|
rw = rw.lower()
|
|
|
|
if rw == 'w':
|
|
s.write('w'.encode())
|
|
while True:
|
|
data = input('ID:')
|
|
s.write(data.encode())
|
|
elif rw == 'r':
|
|
s.write('r\r'.encode())
|
|
while True:
|
|
mes = s.read_until(b'\r')
|
|
print(mes.decode())
|
|
elif rw == '':
|
|
s.write('r\r'.encode())
|
|
while True:
|
|
mes = s.read_until(b'\r')
|
|
if mes != '':
|
|
print(mes.decode())
|
|
else:
|
|
print('Invalid option')
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |