Linux Reads Bar Codes
Bar codes printed on machine-readable labels simplify automatic identification of various things. The Linux kernel device driver module developed by Hewlett-Packard provides serial port access to an HP handheld wand-style bar code reader. An interface circuit is presented for connecting the wand to a PC serial port, and we develop software for reading the Bookland bar code. The Bookland bar code is used in the book trade for encoding the International Standard Book Number (ISBN). Because Bookland and the Universal Product Code (UPC) both use the European Article Number (EAN) bar code patterns for encoding decimal digits, it turns out that our software also decodes the UPC, widely used for groceries and other retail merchandise.
The Hewlett-Packard HBCS-A300 Bar Code Wand (Figure 1) brings out a 3-wire serial interface consisting of two power lines and a signal line. When provided with +5 Vdc power and ground, the open-collector signal line can be pulled up with a resistor to the positive rail so that it becomes a TTL-compatible logic level output. As the wand moves over a bar code pattern, the output signal from the wand is low for a white bar, high for a black bar. This logic level signal does not swing negative, and therefore is not RS-232-compatible. As it turns out, however, it doesn't have to be. Inside a PC, the RS-232 signal and control lines typically are connected to a 1489-type bipolar-to-TTL signal translator called an RS-232 receiver. Information from the wand passes correctly through a 1489-type signal translator because the signal translator's threshold voltages are +1 and +2 volts when the IC's response control pin is left open, as it normally is. In that configuration, the translator operates as an inverting buffer for TTL-compatible signals. A white-level input signal below +1 volts translates into TTL-compatible high at the UART input pin, while a black-level input signal above +2 volts translates into TTL-compatible low.
The wand cable is equipped with a DIN connector that Hewlett-Packard describes as a 5-pin connector. It is really a 6-pin DIN connector with the center pin omitted. Sometimes this kind of DIN connector is described as a 5-pin ``240 degree'' connector. The ``other'' 5-pin DIN connector, such as on the PC/AT keyboard, is the one you will get if you are not careful what you ask for; it has five pins arranged in a 180-degree arc. The socket that matches the Hewlett-Packard wand is a 6-pin DIN socket, such as Mouser catalog number 16PJ224, or Digi-Key 275-1020-ND.
Surplus bar code wands obtained from Electronic Goldmine, and also from All Electronics, had the DIN connector wired differently from the pin-out given in Hewlett-Packard's data sheet. Both pin-outs are shown in Figure 2. Different wiring could have been the result of engineering change or possibly manufacturing snafu. In any case, once the power and signal lines had been identified and properly connected, the surplus wands worked the same as new.
The wand responds to light and dark bars. A nonreflecting black bar results in a logic high (+5 volt) level output, while a reflecting white space results in a logic low (ground level) output. There is, however, more to the story. That quick description implies static behavior, but the wand's response is not static at all. Light-source control and light-sensor signal processing circuits located inside the wand appear to be identical to the circuit diagrammed in Hewlett-Packard's data sheet for the 24-pin special-purpose HBCC-0500 integrated circuit (see Figure 3). That circuit creates dynamic behavior. Whenever the wand sees no transition, either white to black, or black to white, it times out after a short delay, and the output reverts to the low (white) level. It turns out that this behavior simplifies processing of the video signal received from the wand. The timeout expires after a very short delay, so there is high probability that the output signal will be in a known state, the low (white) state, when the wand is first picked up to begin a scan. In our software, this timeout feature is also used to detect abnormal termination, such as occurs when the wand is lifted off early or stopped in the middle of a bar code. Even if the wand is stopped on a black bar the circuit quickly times out and the output reverts to the white (low) level.
Special Reports: DevOps
- Vigilante Malware
- Disney's Linux Light Bulbs (Not a "Luxo Jr." Reboot)
- Libreboot on an X60, Part I: the Setup
- Vagrant Simplified
- System Status as SMS Text Messages
- Bluetooth Hacks
- Dealing with Boundary Issues
- October 2015 Issue of Linux Journal: Raspberry Pi
- Non-Linux FOSS: Code Your Way To Victory!
- October 2015 Video Preview