-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option for multiple RFID Readers #760
To use it, the two files Reader.py and RegisterDevice.py must be replaced with the *py..Multi files. If you activate multiple RFID readers it´s e.g. possible to read Card and "Figure" RFID parallel.
- Loading branch information
Markus Prochaska
authored and
Markus Prochaska
committed
Jun 13, 2020
1 parent
c94448c
commit 9145cae
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python3 | ||
# There are a variety of RFID readers out there, USB and non-USB variants. | ||
# This might create problems in recognizing the reader you are using. | ||
# We haven't found the silver bullet yet. If you can contribute to this | ||
# quest, please comment in the issue thread or create pull requests. | ||
# ALTERNATIVE SCRIPTS: | ||
# If you encounter problems with this script Reader.py | ||
# consider and test one of the alternatives in the same scripts folder. | ||
# Replace the Reader.py file with one of the following files: | ||
# * Reader.py.experimental | ||
# This alternative Reader.py script was meant to cover not only USB readers but more. | ||
# It can be used to replace Reader.py if you have readers such as | ||
# MFRC522, RDM6300 or PN532. | ||
# * Reader.py.kkmoonRFIDreader | ||
# KKMOON RFID Reader which appears twice in the devices list as HID 413d:2107 | ||
# and this required to check "if" the device is a keyboard. | ||
|
||
# import string | ||
# import csv | ||
import os.path | ||
import sys | ||
|
||
from evdev import InputDevice, ecodes, list_devices | ||
from select import select | ||
|
||
|
||
def get_devices(): | ||
return [InputDevice(fn) for fn in list_devices()] | ||
|
||
|
||
class Reader: | ||
reader = None | ||
|
||
def __init__(self): | ||
self.reader = self | ||
devs = list() | ||
path = os.path.dirname(os.path.realpath(__file__)) | ||
self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" | ||
if not os.path.isfile(path + '/deviceName.txt'): | ||
sys.exit('Please run RegisterDevice.py first') | ||
else: | ||
with open(path + '/deviceName.txt', 'r') as f: | ||
device_keys = f.readlines() | ||
devices = get_devices() | ||
for device in devices: | ||
for dev_key in device_keys: | ||
dev_name, dev_phys = dev_key.rstrip().split(';', 1) | ||
if device.name == dev_name and device.phys == dev_phys: | ||
devs.append(device) | ||
break | ||
for dev in devs: | ||
try: | ||
dev | ||
except: | ||
sys.exit('Could not find the device %s\n. Make sure is connected' % dev.name) | ||
|
||
str_devs = ','.join([str(x) for x in devs]) | ||
#print("Devs: " + str_devs) | ||
self.devices = map(InputDevice, str_devs) | ||
self.devices = {dev.fd: dev for dev in devs} | ||
|
||
def readCard(self): | ||
stri = '' | ||
key = '' | ||
while key != 'KEY_ENTER': | ||
r, w, x = select(self.devices, [], []) | ||
for fd in r: | ||
for event in self.devices[fd].read(): | ||
if event.type == 1 and event.value == 1: | ||
stri += self.keys[event.code] | ||
# print( keys[ event.code ] ) | ||
key = ecodes.KEY[event.code] | ||
return stri[:-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os.path | ||
from Reader import get_devices | ||
|
||
list_dev_ids = list() | ||
devices = get_devices() | ||
|
||
def addDevice(): | ||
i = 0 | ||
print("Choose the reader from list") | ||
for dev in devices: | ||
print(i, dev.name + str(dev.phys)) | ||
i += 1 | ||
dev_id = int(input('Device Number: ')) | ||
if dev_id not in list_dev_ids: | ||
list_dev_ids.append(dev_id) | ||
|
||
|
||
addDevice() | ||
while True: | ||
answer = input('Do you want to add another device: [Y/n]') | ||
if not answer or answer[0] != 'Y': | ||
break | ||
addDevice() | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
with open(path + '/deviceName.txt', 'w') as f: | ||
for sel_dev_id in list_dev_ids: | ||
f.write(devices[sel_dev_id].name + ";" + devices[sel_dev_id].phys + '\n') | ||
f.close() |