Using Magnetic Stripe Readers for Point-of-Sale

by Larry Stone, Mar 2002 (revised Dec 2002)

Audience: Merchants' technical staff, I/S application administrators.

Topics: Recommended Hardware -- Installing and Configuring -- Operating (Order Entry)

Introduction

This document shows how a merchant can read the magnetic stripes on customers' credit cards when entering orders, to increase the speed and accuracy of the transactions. We will use widely-available, inexpensive, off-the-shelf peripherals that work with common IS-supported hardware and software (including Athena, Macintosh, and Windows).

Many magnetic stripe readers made for use with personal computers work by emulating a keyboard, and entering the data from the card as if it had been typed in by hand. This make it very easy to use them with a Web form, since web browsers are already set up to take input from the keyboard.

We recommend purchasing a unit that can read both track 1 and track 2 on ISO-standard magnetic stripes. Although all of the data on track 2 is also encoded on track 1 for the credit cards we have observed, the format of track 2 is more consistent. Track 1 provides the customer's name, so it is worth trying to read and interpret it.

Recommended Hardware

After a thorough market survey, we chose the ID TECH Mini-Mag series of magnetic stripe readers. They are compact, versatile, inexpensive, and easy to configure.

We tested three models of the MiniMag, each with a different type of interface:

IDT3331-12U (USB keyboard interface)
It appears to the computer as a second keyboard. If your computer has a USB interface, we recommend this model most highly. (If you have USB but no free ports, get a USB hub to make more ports available.)
NOTE: This will not work on a Sun SunBlade workstation; although it has a USB interface, the operating system only allows one keyboard device.

IDT3331-12 ("Keyboard wedge" interface)
This unit is inserted into the cable of a standard PC keyboard. Data from the magnetic stripe is indistinguishable from keystrokes. This only works on an IBM PC-clone with an AT or PS/2 style keyboard. It should not be used on a Sun Workstation with the keyboard converter.

IDT3321-12PP (Port-powered RS-232 interface)
This model is connected to a traditional RS-232 serial port. Extra software is required to make it work, but it is the only type of reader that can be used on Athena Sun Workstations. This interface cannot be used directly but is useful on, e.g. Sun workstations which cannot handle USB or PC keyboard interfaces.

Recommendations by Platform

Installing and Configuring the MiniMag

The MiniMag is an "intelligent" device: it contains a tiny computer that processes and formats the data it reads from magnetic stripes. Each MiniMag reader must be configured before it can be used with our order entry forms. The configuration process is easy and it only has to be done once in the lifetime of each reader device, since it remembers the changes.

Each model has its own procedure for installation and configuration:

Configuring MiniMag with USB interface (IDT3331-12U)

This unit also has to be configured first to work correctly with our WebPos form. To configure it, you can use one of the following:
  1. A PC running Windows 2000 (not any later version) and the IDTech configuration utility downloaded from http://www.idt-net.com/download/USB_Reader_Setup_Utility_Software_Win2000.exe"

  2. A PC running Windows 98 (not any later version) and the IDTech configuration utility downloaded from http://www.idt-net.com/download/USB_Reader_Setup_Utility_Software.exe

  3. A PC running Athena Linux 9.1 or 9.2 (or, possibly just Red Hat 7.3 or 9), and the configuration USB driver available from the ECommerce merchant services team (See Linux MiniMag driver installation instructions.)

Configuring the MiniMag under Windows 2000 and 98

First, connect the MiniMag to your Windows PC and wait, perhaps for several minutes until Windows detects the new device. It will notify you with a popup window.

Download and install the configuration utility from ID TECH, found at:

Windows 2000:
http://www.idt-net.com/download/USB_Reader_Setup_Utility_Software_Win2000.exe"

Windows 98:
http://www.idt-net.com/download/USB_Reader_Setup_Utility_Software.exe

Start the program, and enter the configuration commands as they are listed below. After entering each line in the input box, click the "Send" button and wait for the line to be echoed to the MiniMag. Then, listen for the beep: after a successful command the MiniMag will beep softly. It beeps twice after an erroneous command. If it does not beep, the configuration request did not work. Try quitting and restarting the IDTech setup utility.

Configuring the MiniMag under Linux

This procedure was tested under Red Hat Linux 7.3 with kernel version 2.4.18, and Red Hat 9.0 (Athena 9.1 and 9.2). Later Linux kernel versions should also work but we can make no promises.

Please see the Linux MiniMag driver installation instructions for the procedure to get the configuration driver installed and recognizing your device.

To configure the MiniMag, you need only write the configuration commands to the device. Each line must end with a carriage-return character, i.e. the ASCII code 13, or "\r". You can do this with the "printf" shell command, e.g.

       printf "/e/d/fa 022\r" > /dev/usb/minimag0
Wait a few seconds for the driver to finish sending each command -- it inserts a delay of about half a second after each character. The MiniMag unit should beep once after a successful command, twice for an error. If it does not beep at all, something went wrong. Did you end the line with a carriage-return?

Use the same shell command on each of the configuration commands below, e.g.

    printf "configuration command \r" > /dev/usb/minimag0

Configuration commands for USB reader:

  1. Set the general parameters to AT keyboard, loud beep, 10ms keystroke delay:
    /e/d/fa 022
    (Linux: printf "/e/d/fa 022\r" > /dev/usb/minimag0)

  2. Do not send a terminator after card data:
    /e/d/fb 3
    (Linux: printf "/e/d/fb 3\r" > /dev/usb/minimag0)

  3. Do not send a line separator:
    /e/d/fq \nul
    (Linux example, beware of \ escaping:
      printf "/e/d/fq \\\\nul\r" > /dev/usb/minimag0)

  4. Set the postamble to a TAB character:
    /e/d/fd \tab
    (Linux: printf "/e/d/fd \\\\tab\r" > /dev/usb/minimag0)

The MiniMag is now ready for use with our Order Entry pages. You only have to configure each MiniMag USB device once in its lifetime.

Configuring MiniMag with Keyboard Wedge (IDT3331-12)

This unit is interposed in the keyboard cable of an IBM-compatible PC. Plug the MiniMag into the PC's keyboard port and plug the original keyboard into the MiniMag'ss socket connector. The keyboard should continue to function normally. The MiniMag does intercept certain strings (beginningwith /e/d/f), which is how you give it configuration commands.

Enter the following configuration commands to set up the MiniMag for operation with our order entry forms. Remember, you only have to do this once for each device, since it remembers its configuration.

The MiniMag should sound a soft beep after each configuration command to show that it was executed. Two beeps indicates an error. If there are no beeps, something went wrong, so try it again.

  1. General Settings.
    Type this line: /e/d/fa 021<Enter>
    This sets it to emulate a "PC/AT" type keyboard, 5ms inter-character delay, and a "loud" beep. Listen for the beep that indicates the command was accepted.

  2. Track separator:
    Type this line: /e/d/fq \nul<Enter>
    This sets the track separator to nothing. It is the "Enter" key by default, but this would end the input string prematurely and load the next track into another input box. Listen for the beep.

  3. Reporting:
    Use this command to check the device's status and some of its configuration settings. First, start up an application like Notepad that allows random text to be typed and displayed.
    Now enter: /e/d/fo <Enter>
    ..and the MiniMag will type a message showing the general settings and its firmware revision.
The configuration is now complete.

Configuring MiniMag RS-232 Port Powered (IDT3321-12PP)

The port-powered version of the RS-232 model cannot be configured. It simply ignores all configuration commands. The RS-232 card reader with an external power supply can be configured, but we did not have one of these to test.

Fortunately, the default configuration of the RS232 PP model is perfect for our application. It comes with the track separator set to nothing, although the documentation for the externally-powered model shows its default track separator is a CR (ascii 13) character.

Cabling

The MiniMag comes with a cable ending in a 9-pin female (DB9F) connector. This conforms to the standard for an RS-232 DCE device, and indeed it works fine with the standard 9-pin male "PC style" serial ports found on many later Sun Workstations, such as the Ultra 10, Ultra 5 and SunBlade 100.

To connect it to a device with a standard 25-pin RS-232 DTE connector (which should be male, according to the standard; older Sun Workstations incorrectly use female connectors and require a gender-changer), you will need to buy or make an adaptor with the following wiring:

        9-pin           25-pin
        DB-9M           DB-25F
        -----           ------
          4              20        DTR (DSR)
          5               7        GND
          3               2        TxD
          2               3        RxD

Operation

The MiniMag is now sending a stream of characters into some random serial port whenever a card is swiped. This is fine, but it does not get the data into your web browser. For that we need another program, a2x, which was orginally developed to let a DragonDictate voice recognition program enter keystrokes transparently to X Window System applications. We can feed the input from the serial port into a Perl script to do some simple filtering and then into a2x, which will generate keystrokes that go to the application with the keyboard focus, presumably the browser.

The a2x source is available in /afs/athena/project/atic/src/a2x/.

Here is an example with the MiniMag is connected to the "TTY B" port on a Sun Ultra 10, running Athena 9.0 (Solaris 8):

perl -e 'while(1){read(STDIN,$a,1); select(undef,undef,undef,.01); $a=~y/\n/\r/;syswrite(STDOUT,$a,1);}' < /dev/cua/b | /mit/ecommerce/bin/a2x
The Perl script adds a delay of 10 millseconds between characters, since otherwise the simulated keystrokes seem to overwhelm Netscape's input method and the terminating <Enter> keystroke is missed or misinterpreted; the result is that the data entered into the "Magnetic Stripe" text input does not count as a change so the JavaScript is not invoked. Adding the inter-character delay solves the problem.

The perl code also translates newline (ASCII 10) to carriage-return (ASCII 13), since a2x maps newline into a Control-J keystroke which is not a line-ending character to Netscape. A2x maps carriage-return into the Return keysym, which does have the desired effect.

Summary of the steps to use RS-232 MiniMag on an Athena Sun workstation:

  1. Connect it to an unused serial port, and make sure the port is configured correctly. The default EEPROM setting of 9600 bps, 8 bits, no parity, works fine.
  2. Run the perl script filter above piped into a2x.
  3. Start up the Athena Netscape 4.78 with the appropriate Point-of-Sale page loaded. The page should come up with keyboard focus already in the "Magnetic Stripe" input.
  4. With your keyboard focus on Netscape, swipe a card through the MiniMag, and observe that the billing name, credit-card number, and expiration date are filled out automatically.

What Doesn't Work

These combinations of hardware are known NOT to work:

Operating the MiniMag

Once the MiniMag is configured and attached to your computer, its operation is the same on all platforms. You simply swipe a card through its slot, in either direction, with the magnetic stripe facing the "Magnetic Stripe" label on top of the unit. It beeps after a successful read, and the green light will blink. If the card could not be read, the light will turn red.

As soon as a card is read, the MiniMag begins "typing" the data it collected. Do not use your computer's keyboard during this time or the data will be corrupted. The data entry takes a few seconds.

To enter a credit card number in the OMARS Order Entry (aka Point of Sale) form, follow these steps:

  1. Load the Order Entry page in your Netscape browser.

  2. Give the keyboard focus to the text box labelled "Magnetic Stripe". The focus should be here already when the page is first loaded.

  3. Swipe the card through the reader. If it is read successfully, wait for a few seconds while the data is entered. You'll be able to tell when it is finished because the card number and expiration date will appear in the form. The billing name will be filled in too if the card has a valid name on Track 1.

  4. You still have to enter the "CVM Digits" field manually, because CVM number is not encoded on the magnetic stripe. It is printed next to the signature stripe on MC and Visa cards, and on the front of Amex cards.

Implementation Details

We configure the MiniMag to send its data in the following format:

     %BCARDNUMBER^SURNAME/FIRST MI^...?;CARDNUMBER=EXPYEAR EXPMONTH ...? <CR>

The words in underlined italics show the pieces of information that can be extracted. The line is terminated, as shown by the "<CR>", with a carriage return character.

On our Order Entry web page, the "Magnetic Stripe" input field has an onChange attribute that calls some Javascript code when a new value is entered in that field. This code extracts the card number, expiration date, and billing name out of the data and forces those values into the appropriate fields in the form.

For more information, or if you have comments or questions, please contact the E-Commerce team.