card reader – PullMonkey Blog http://pullmonkey.com Fri, 27 Jul 2012 15:39:59 +0000 en-US hourly 1 https://wordpress.org/?v=5.6 Using Ruby to read from a MagTek USB Card Reader http://pullmonkey.com/2012/07/27/using-ruby-to-read-from-a-magtek-usb-card-reader/ Fri, 27 Jul 2012 15:39:59 +0000 http://pullmonkey.com/?p=57712 Been playing around with a lot of USB devices lately, to get them to play nicely with some of our touch screen Rails apps.
One of the devices is a card reader - specifically a MagTek reader, and the same code works for the ELO reader.

I've tried a billion different ways to ensure we're reading in all the data. At first, I was just asking the usb stream to present me with a certain number of characters, b/c that's how all the examples do it.
But we're using a lot of different cards with the readers, so that didn't work too well. So now I just read one character at a time until we find the new line.
Here's the code to find the device, open it, close it and read from it, all whilst finding and converting the data as required.

So using this code, we take the swiped data and send it to our server for storage.

]]>