LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 11-26-2009, 01:19 AM   #1
searchingfortao
LQ Newbie
 
Registered: May 2009
Location: Vancouver, Canada
Distribution: Gentoo
Posts: 10

Rep: Reputation: 0
Magnetic card readers in Linux?


I'm building an application that will be using a magnetic card reader as the only interface: no keyboard, no mouse, no screen for that matter. Now as I understand it, most MCRs these days support keyboard emulation so I can just zip the card through and it'll send keystrokes right to /dev/input/eventN. But now I have a few questions:

How do I capture the keystrokes given that this app has to run at boot time?
Do I need a keylogger?
Can't I just use an HID driver of some kind? How would that work?
Is there a preferred model out there for people to do stuff like this?

My app will be written in Python and run on a Sheevaplug, so yeah, I'm working with odd hardware to begin with.
 
Old 11-26-2009, 10:22 AM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
You may want to do some research into /dev/, or how it operates and sees things- you're approaching this all wrong. Play on another box with a mouse attached; play with /dev/input. How can you get the mouse signals? What are devices in Linux?

There is a single line solution in python for this, and you'll kick yourself when you figure out how /dev/ works; simple code you should have used a bazillion times
 
0 members found this post helpful.
Old 11-26-2009, 01:17 PM   #3
searchingfortao
LQ Newbie
 
Registered: May 2009
Location: Vancouver, Canada
Distribution: Gentoo
Posts: 10

Original Poster
Rep: Reputation: 0
Actually, I know how to capture input both via STDIN and at a prompt. What I'm doing here though won't work with either of those options. This computer doesn't have a keyboard, or a mouse. There will be no one in front of the machine to login and start the app waiting for input.

I need this program to start at run-time and capture all input from the cardreader without any user input. Are you suggesting that I can just have Python run a script that waits for input without logging in?
 
Old 11-26-2009, 04:06 PM   #4
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Nope, simpler still. Why not read the stream directly off the device? Series of open( "", 'r' ).read()s. You can either have your python script run as a boot runlevel script (as a gentoo user, you'll know how to do this too) or run the box as a single user environment and have that run it.

I suppose, though, it depends on what the project is for; a commercial environment where you want robustness, you may want to use something like HAL/Dbus. A quick project or proof of concept, yeah- read it off the device like you would a pipe or a socket.

Everything Is A File (tm) after-all
 
0 members found this post helpful.
Old 11-26-2009, 04:27 PM   #5
searchingfortao
LQ Newbie
 
Registered: May 2009
Location: Vancouver, Canada
Distribution: Gentoo
Posts: 10

Original Poster
Rep: Reputation: 0
Is this what you're talking about?

Code:
#!/usr/bin/env python

keyboard = "/dev/input/event3"

f = open(keyboard, "r")
while (True):
        print(f.read(8))
f.close()
'Cause that much I've figured out. The problem is that the data coming out is binary and I don't know how to decode it.
 
Old 11-26-2009, 04:34 PM   #6
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Okay, you didn't say you'd got that far. Well, then now you decode it, or map it to values you already know. You'll want to find the developer docs for your card reader for more information, though, if you want to do more than read data from it.
 
0 members found this post helpful.
Old 11-26-2009, 04:42 PM   #7
searchingfortao
LQ Newbie
 
Registered: May 2009
Location: Vancouver, Canada
Distribution: Gentoo
Posts: 10

Original Poster
Rep: Reputation: 0
The "device" in this case though is a keyboard (I haven't bought a card reader yet). Are you saying that every keyboard sends different data to /dev/input/eventN? Is there no way to easily translate the binary data coming out of /dev/input/eventN into the ASCII that're actually coming through?
 
Old 11-26-2009, 05:38 PM   #8
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 403

Rep: Reputation: 51
Have a look at acpi_fakekey source (in acpi-support package), maybe it will help.
 
  


Reply

Tags
python, reader, usb



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
internal card readers horace12345 Linux - Hardware 3 08-18-2009 01:21 AM
Compatible Magnetic Swipe Card Reader? ESC201 Linux - Hardware 3 02-22-2009 06:49 PM
flash card / memory card readers and linux? Frelov Linux - Hardware 11 08-02-2006 04:37 PM
Do internal SD card readers (on laptops) work in linux? MasterOfTheWind Linux - Hardware 6 07-14-2006 02:54 AM
Drivers for magnetic card stripe readers Shad034 Programming 3 12-13-2004 07:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 04:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration