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 (email@example.com) 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.
|PasswordPing Ltd.'s Exposed Password and Credentials API Service||Apr 28, 2017|
|Graph Any Data with Cacti!||Apr 27, 2017|
|Be Kind, Buffer!||Apr 26, 2017|
|Preparing Data for Machine Learning||Apr 25, 2017|
|openHAB||Apr 24, 2017|
|Omesh Tickoo and Ravi Iyer's Making Sense of Sensors (Apress)||Apr 21, 2017|
- Graph Any Data with Cacti!
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
- The Weather Outside Is Frightful (Or Is It?)
- Simple Server Hardening
- Understanding Firewalld in Multi-Zone Configurations
- Gordon H. Williams' Making Things Smart (Maker Media, Inc.)
- Server Technology's HDOT Alt-Phase Switched POPS PDU
- IGEL Universal Desktop Converter
- A Switch for Your RPi