-
Notifications
You must be signed in to change notification settings - Fork 8
/
example_read_iso15693.py
73 lines (60 loc) · 2.36 KB
/
example_read_iso15693.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
# vim:fenc=utf-8:et:sw=4:ts=4:sts=4:tw=0
from __future__ import print_function
import logging
import argparse
import yaml
import time
from copy import copy
from rfidgeek import PyRFIDGeek, ISO15693
# You might need to change this:
COM_PORT_NAME = '/dev/tty.SLAB_USBtoUART'
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
reader = PyRFIDGeek(serial_port=COM_PORT_NAME, debug=True)
reader.set_protocol(ISO15693)
try:
led_enabled = False
uids = []
prev_uids = [[], []]
while True:
uids = list(reader.inventory())
successful_reads = []
print('%d tags' % len(uids))
if len(uids) > 0 and not led_enabled:
reader.enable_led(3)
led_enabled = True
elif len(uids) == 0 and led_enabled:
reader.disable_led(3)
led_enabled = False
for uid in uids:
if uid not in prev_uids[0] and uid not in prev_uids[1]: # and not uid in prev_uids[2]:
item = reader.read_danish_model_tag(uid)
if item['error'] != '':
print('error reading tag: ', item['error'])
else:
if item['is_blank']:
print(' Found blank tag')
elif 'id' in item:
print
print(' Found new tag, usage type: %s' % item['usage_type'])
print(' # Item id: %s (part %d of %d)' % (item['id'],
item['partno'],
item['nparts']))
print(' Country: %s, library: %s' % (item['country'],
item['library']))
if item['crc_ok']:
print(' CRC check successful')
successful_reads.append(uid)
else:
print(' CRC check failed')
# reader.unlock_afi(uid)
# prev_uids[2] = copy(prev_uids[1])
prev_uids[1] = copy(prev_uids[0])
prev_uids[0] = copy(uids)
time.sleep(1)
finally:
reader.close()