write to card is fully functional
This commit is contained in:
parent
a2ddbb575e
commit
364d019b3d
@ -54,19 +54,34 @@ def read(ser):
|
|||||||
print(data_json)
|
print(data_json)
|
||||||
with open(JSON_PATH, 'w') as file:
|
with open(JSON_PATH, 'w') as file:
|
||||||
file.write(data_json)
|
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():
|
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()
|
s.flush()
|
||||||
|
|
||||||
rw = input('Read or Write tags? [R/w]')
|
rw = input('Read or Write tags? [R/w]')
|
||||||
rw = rw.lower()
|
rw = rw.lower()
|
||||||
|
|
||||||
if rw == 'w':
|
if rw == 'w':
|
||||||
s.write('w'.encode())
|
s.write('w\r'.encode())
|
||||||
while True:
|
write(s)
|
||||||
data = input('ID:')
|
|
||||||
s.write(data.encode())
|
|
||||||
elif rw == 'r':
|
elif rw == 'r':
|
||||||
s.write('r\r'.encode())
|
s.write('r\r'.encode())
|
||||||
read(s)
|
read(s)
|
||||||
|
@ -125,9 +125,6 @@ def write_nfc_loop(data):
|
|||||||
# Try again if no card is available.
|
# Try again if no card is available.
|
||||||
if uid is not None:
|
if uid is not None:
|
||||||
break
|
break
|
||||||
|
|
||||||
print("")
|
|
||||||
print("Found card with UID:", [hex(i) for i in uid])
|
|
||||||
|
|
||||||
set_neopixel_color(255,255,0)
|
set_neopixel_color(255,255,0)
|
||||||
|
|
||||||
@ -160,6 +157,7 @@ def loop():
|
|||||||
if rw == 'w':
|
if rw == 'w':
|
||||||
while True:
|
while True:
|
||||||
sys.stdout.write('ID: \r')
|
sys.stdout.write('ID: \r')
|
||||||
|
poll_results = poll_obj.poll(1)
|
||||||
data = sys.stdin.readline().strip()
|
data = sys.stdin.readline().strip()
|
||||||
write_nfc_loop(data)
|
write_nfc_loop(data)
|
||||||
elif rw == 'r':
|
elif rw == 'r':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user