write to card is fully functional

This commit is contained in:
2023-09-27 09:29:59 +02:00
parent a2ddbb575e
commit 364d019b3d
2 changed files with 21 additions and 8 deletions

View File

@@ -54,19 +54,34 @@ def read(ser):
print(data_json)
with open(JSON_PATH, 'w') as file:
file.write(data_json)
def write(ser):
while True:
data = input('ID:')
data = data + '\r'
ser.write(data.encode())
while True:
mes = ser.read_until(b'\r')
if b'Waiting' in mes:
print('Waiting for card')
if b'Erasing' in mes:
print('Erasing card')
if b'Writing' in mes:
print('Writing data to card')
if b'done' in mes:
print('Write done')
break
def main():
s = serial.Serial(port="/dev/ttyACM0", parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=1)
s = serial.Serial(port="/dev/ttyACM1", 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())
s.write('w\r'.encode())
write(s)
elif rw == 'r':
s.write('r\r'.encode())
read(s)