Multiple discrete keyboard inputs on one machine

1.8k views Asked by At

Background:

I am running a large event in October and plan to monitor who attends and where people are in the building for safety using a system that reads mifare cards that everyone in my organsiation has. To do this I have found a cheap mifare reader that reads a particular sector of the card and returns the data as hex which I can convert to a string then send to a server for processing and recording. So far, so good. However, close to 20,000 people attend this event and that means a lot of scanning and so a lot of mifare readers, all of which need to be connected to a computer to read the data and send it on. Ideally, I'd like to connect about 3 or four readers to a machine, and have about three or four of these, one on each entrances/exit at the event.

What I need help doing:

My card readers act as generic keyboards on Windows and Android (and I assume Linux, but I'm about to check this), the computer in essence just acts as though it has multiple keyboards, all of which can enter data simultaneously, but only to one program (i.e., there's ever one caret on the screen). This could cause a problem if two cards are scanned at the same time and the keystrokes from each card get "intermingled" and so cause processing problems.

What I'd like to do is set up one linux box to have multiple carets, so that I could have say four command lines all going at the same time taking data from one card reader each.

For example: if John and Saira scanned in at the same time, at the moment the resulting input could be:

j s o a h i n r a

Whereas I'd like it to be:

CLI 1:

john

CLI2:

saira

etc. etc. for CLI3, CLI4

I know this must be possible, I'd looked at potentially settign up a multi-seat linux distribution, but I feel that would be using a sledgehammer to solve the problem, and creates a new problem since it introduces the need for monitors, mice, etc.

Ideally I'd like this whole system to be as streamlined as possible, either running off a laptop or just a linux box that I can plug in, boot up and let run automatically (with no need for monitors, mice or other clunky bits and pieces!).

Does anyone have any experience on this or advice they can offer? Any help would be much appreciated!

Thanks,

Dom

1

There are 1 answers

3
Dom Weldon On

Dom here again. I've managed to solve this quite easily now using Python. Contact me if you'd like more advice, but the basic gist is to use the evdev module in Python to directly access the hardware (in this case I've set up a class called ActiveReader to take care of each individual reader). Then, setup different processes using the multiprocessing module to handle each card reader separately.

Code for the processing bit is below - it's early days code and needs a bit of extra work, I've left it intentionally short and sweet here to act as a reference for people trying to do similar stuff!

# imports etc
from evdev import InputDevice, categorize, ecodes
from ActiveReader import ActiveReader
from multiprocessing import Process

# for the reader
dev = InputDevice('/dev/input/event4')

def new_device_process(device_name):
    print device_name
    device  =   InputDevice (device_name)
    print device.name
    someDevice  =   ActiveReader(device)


if __name__ == "__main__":

    # put in a process here to work on updating the database

    # set this up with Monitoring module to detect when devices are plugged in/unplugged etc.
    p1      =   Process(target=new_device_process, args=('/dev/input/event4',))
    p1.start()
    p2      =   Process(target=new_device_process, args=('/dev/input/event5',))
    p2.start()