Skip to content

Commit 76e0778

Browse files
authored
Update read_nfc_card.py
1 parent 84b18d6 commit 76e0778

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

read_nfc_card.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import nfc
22
import os
33
import json
4+
import sys
45

5-
with open('config.json') as config_file: # Load config
6+
# Load config
7+
with open('config.json') as config_file:
68
config = json.load(config_file)
79

810
CARD_DATA_DIR = config['card_data_dir']
@@ -23,9 +25,13 @@ def on_connect(tag):
2325
print(f"Card data saved to {card_file}")
2426

2527
def main():
26-
with nfc.ContactlessFrontend(config['nfc_reader']) as clf:
27-
print("Place an NFC card near the reader...")
28-
clf.connect(rdwr={'on-connect': on_connect})
28+
try:
29+
with nfc.ContactlessFrontend(config['nfc_reader']) as clf:
30+
print("Place an NFC card near the reader...")
31+
clf.connect(rdwr={'on-connect': on_connect})
32+
except Exception as e:
33+
print(f"Error reading NFC card: {e}")
34+
sys.exit(1)
2935

3036
if __name__ == "__main__":
3137
main()

0 commit comments

Comments
 (0)