Skip to content

Commit

Permalink
Added option for multiple RFID Readers #760
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
73 changes: 73 additions & 0 deletions scripts/Reader.py.Multi
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]
31 changes: 31 additions & 0 deletions scripts/RegisterDevice.py.Multi
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()

0 comments on commit 9145cae

Please sign in to comment.