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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Ubuntu Online Summit
- Devuan Beta Release
- The Qt Company's Qt Start-Up
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- The US Government and Open-Source Software
- May 2016 Issue of Linux Journal
- The Death of RoboVM
- Open-Source Project Secretly Funded by CIA
- New Container Image Standard Promises More Portable Apps
- BitTorrent Inc.'s Sync
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide