-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRFIDTagReaderEventCallback.py
More file actions
executable file
·47 lines (41 loc) · 1.48 KB
/
RFIDTagReaderEventCallback.py
File metadata and controls
executable file
·47 lines (41 loc) · 1.48 KB
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
#! /usr/bin/python
#-*-coding: utf-8 -*-
"""Simple program to illustrate using a call back function with the Tag-In-Range
pin on the Innovations Design tag readers (ID-L3, ID-L12, ID-L20).
This is the general idea used in AutoMouseWeight Program
Last Modified:
2018/10/19 by Jamie Boyd - put callback and code to install callback in TagReader class
2018/03/07 by Jamie Boyd - added some comments and a quit on ctrl-C
"""
serialPort = '/dev/serial0'
#serialPort = '/dev/ttyUSB0'
tag_in_range_pin=21
import RFIDTagReader
from RFIDTagReader import TagReader
from time import sleep
def main ():
tagReader = TagReader(serialPort, True, timeOutSecs = 0.05, kind='ID')
tagReader.installCallback (tag_in_range_pin)
print ("Waiting for tags....")
while True:
try:
"""
Loop with a brief sleep, waiting for a tag to be read.
After reading the tag, it is printed. This is the point
where you might do something interesting
"""
while RFIDTagReader.globalTag == 0:
sleep (0.02)
print ('Tag = ', RFIDTagReader.globalTag)
"""
Loop with a brief sleep, waiting for a tag to exit reading range
"""
while RFIDTagReader.globalTag != 0:
sleep (0.02)
print ('Tag went away')
except KeyboardInterrupt:
del tagReader
print ("Quitting")
break
if __name__ == '__main__':
main()