Linux Reads Bar Codes
Any text editor will do, but here, of course we use the author's able editor, described in his book Build Your Own LINUX C Toolbox. Call your editor with a command such as able barcode. and type in the text shown in Listing 1.
Do set COM_BASE in this file to the base I/O address of the serial port you will actually be using.
To create the device-driver source file, call your editor with a command such as able bcdrv.c and enter the text shown in Listing 2 (available at ftp://ftp.linuxjournal.com/pub/elj/listings/issue02).
When we compile this code to create the object module that can be loaded into the kernel by insmod, the compiler needs to be told to access include files from /usr/src/linux/include, and we need to define some control flags for the preprocessor. Let us encapsulate these details in a little shell script. Call your editor with a command such as able mcomp.sh and type in the text
#! /bin/bash gcc -D__KERNEL__ -I/usr/src/linux/include -DMODULE\ -Wall -O2 -c $1.c -o $1.o
Save the file and then mark it executable with the command chmod+x mcomp.sh. When called from the shell prompt using the command mcomp.sh bcdrv this shell script becomes the command:
gcc -D__KERNEL__ -I/usr/src/linux/include -DMODULE\ -Wall -O2 -c bcdrv.c -o bcdrv.oThis asks gcc to compile the file bcdrv.c and create the object file bcdrv.o containing our loadable kernel device-driver module.
To load the device driver into the kernel, first promote yourself to superuser with the command su and then type in root's password. Then use the command insmod bcdrv or the command insmod bcdrv.o to load the device driver into the kernel. The module loader appears to accept either form.
Type exit to restore normal user status, and return to your own directory. The command cat /proc/modules should now show that your kernel has registered a device driver named ``bcdrv''.
For a quick test of the bar code hardware and software, the little program seen in Listing 3 can be used to display continuously the state of the video signal line. While it is running and displaying whether the video signal is ``WHITE'' or ``BLACK'', the program will catch control-C. The first control-C closes the device, the second control-C exits to the shell.
A user-side program, available for download from the source listed below, reads and decodes Bookland and UPC bar codes. It is in principle not much different from this test program. Once you get the hang of scanning with a nice steady motion, the verbose output from that program--which includes the measured width of each bar--can be used to determine the quality of a printed bar code.
To remove the device driver, promote yourself again to superuser with the command su and type in root's password. Using the command rmmod bcdrv will drop DTR to turn off power to the wand interface and remove the driver from the system.
Before ever loading your device driver, entering the shell command cat /proc/ioports will probably show that the serial port you propose to use is already reserved by some kernel driver. That reservation gets pushed aside when we load our bar code device driver. If that initial reservation needs to be restored, then you have what is called an exercise for the reader: Modify the cleanup_module( ) routine such that the original port reservation gets restored when the bar code device driver is removed. It would seem that a call to reserve_region( ) with the original driver's name would do the trick, but I have not tried it, so you get to experiment.
Jack Dennon (firstname.lastname@example.org) studied mechanical engineering at Oregon State University in Corvallis, mayhem at the Infantry School at Fort Benning and low flying at the Army Aviation School at Fort Rucker. Nowadays he uses DOS for maintenance of legacy sawmill systems, studies how to replace them with Linux and helps his wife homeschool their four children.
Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report
August 27, 2015
12:00 PM CDT
DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.
Free to Linux Journal readers.Register Now!
- Hacking a Safe with Bash
- Django Models and Migrations
- Secure Server Deployments in Hostile Territory, Part II
- The Controversy Behind Canonical's Intellectual Property Policy
- Huge Package Overhaul for Debian and Ubuntu
- Home Automation with Raspberry Pi
- Shashlik - a Tasty New Android Simulator
- Embed Linux in Monitoring and Control Systems
- KDE Reveals Plasma Mobile
- diff -u: What's New in Kernel Development