The SEN-08634 Magnetic Card Reader/Writer is exactly what it sounds like: it reads and writes to magnetic strip cards. SparkFun has them.
This device will connect to your host as a serial device (/dev/ttyUSB0, for example) but if you try to cat it out, it will immediately return. The damn thing doesn't buffer! Well, okay, that's not true, it will buffer, but it throws the buffer away after a very short period of time. So, if you wanted to use the device with some clever bash scripting, you would have to do something like while [ "1" ] ; do echo -n `cat /dev/ttyUSB0` ; done
I didn't actually try that command while I had the device, it didn't occur to me until just now.
Anyway, I borrowed one of these and wrote a python script that can use it. It reads high coercivity cards and reads and writes low coercivity cards, but that's about the only thing that works. For some reason, all the commands that the documentation claims should work don't return anything. My script is heavily commented and I don't recommend simply running it unless you're ready to lose the data on whatever card you swipe through it. The main body of the script will attempt to write hello world to track 1 and then a couple strings of numbers to track 2 and 3. It will not backup what's on the card before writing. That didn't occur to me either. I don't have the device any more, so I'm not going to update the script.
Here's the script via pastebin: magstripe.py.
If you want to see documentation for it, you can do something like this: doxygen -g magstrip.doxy ; doxygen magstrip.doxy
This device will connect to your host as a serial device (/dev/ttyUSB0, for example) but if you try to cat it out, it will immediately return. The damn thing doesn't buffer! Well, okay, that's not true, it will buffer, but it throws the buffer away after a very short period of time. So, if you wanted to use the device with some clever bash scripting, you would have to do something like while [ "1" ] ; do echo -n `cat /dev/ttyUSB0` ; done
I didn't actually try that command while I had the device, it didn't occur to me until just now.
Anyway, I borrowed one of these and wrote a python script that can use it. It reads high coercivity cards and reads and writes low coercivity cards, but that's about the only thing that works. For some reason, all the commands that the documentation claims should work don't return anything. My script is heavily commented and I don't recommend simply running it unless you're ready to lose the data on whatever card you swipe through it. The main body of the script will attempt to write hello world to track 1 and then a couple strings of numbers to track 2 and 3. It will not backup what's on the card before writing. That didn't occur to me either. I don't have the device any more, so I'm not going to update the script.
Here's the script via pastebin: magstripe.py.
If you want to see documentation for it, you can do something like this: doxygen -g magstrip.doxy ; doxygen magstrip.doxy
No comments:
Post a Comment