write to card is fully functional

This commit is contained in:
Angoosh Leviocki 2023-09-27 09:29:59 +02:00
parent a2ddbb575e
commit 364d019b3d
Signed by: angoosh
GPG Key ID: 1CCB948F5CBF1995
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)

View File

@ -125,9 +125,6 @@ def write_nfc_loop(data):
# Try again if no card is available.
if uid is not None:
break
print("")
print("Found card with UID:", [hex(i) for i in uid])
set_neopixel_color(255,255,0)
@ -160,6 +157,7 @@ def loop():
if rw == 'w':
while True:
sys.stdout.write('ID: \r')
poll_results = poll_obj.poll(1)
data = sys.stdin.readline().strip()
write_nfc_loop(data)
elif rw == 'r':