2

I am working on a very simple project where I am using a magnetic card reader to scan ID's off of the card and checking it to see if it is allowed or not. In the past whenever I needed to get information from USB devices in linux they always showed up as ttyUSB* and I could connect to them serially to read the information that is being produced. However this ID reader isn't showing up as that.

so the device is connected moreover when I swipe a card while a terminal is open, it populates the card information to stdout and prints to the terminal.

I made a simple python script to read the info and sort through all the garbage and find only the ID number.

rough code

obviously this code is rough and probably does work but I haven't been able to test it bc I always get this message: message

I'm new to python and fairly new to a ras pi. I am using a ras pi 3. Any help will be greatly appreciated! thanks!

1 Answer 1

1

This ID card is a HID device: it emulates the keyboard and sends information as keystrokes, as if you have typed it yourself. To read it, your script needs to open STDIN and read from it, the same way the terminal does. In Python, you could do something like this:

import sys
ser=sys.stdin
# the rest of your code is unchanged
2
  • That did the trick! I have never worked with an HID device before so that was where my confusion was. My method of searching through the information was incorrect but I have fixed it. Thanks!
    – Wagner2x
    Commented Aug 17, 2016 at 14:23
  • @Wagner2x glad I could help and good luck with your project. Commented Aug 17, 2016 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.