File tree 1 file changed +10
-4
lines changed
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 1
1
import nfc
2
2
import os
3
3
import json
4
+ import sys
4
5
5
- with open ('config.json' ) as config_file : # Load config
6
+ # Load config
7
+ with open ('config.json' ) as config_file :
6
8
config = json .load (config_file )
7
9
8
10
CARD_DATA_DIR = config ['card_data_dir' ]
@@ -23,9 +25,13 @@ def on_connect(tag):
23
25
print (f"Card data saved to { card_file } " )
24
26
25
27
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 )
29
35
30
36
if __name__ == "__main__" :
31
37
main ()
You can’t perform that action at this time.
0 commit comments