Linux/optical scanners
This page is a seed article. You can help HTYP water it: make a request to expand a given page and/or donate to help give us more writing-hours!
|
Getting a scanner to run under Linux can be easier or harder than under Windows. If you don't have the driver disk, you're usually sunk with Windows; with Linux, the scanner drivers included in most distros can handle most scanners. Scanning under Linux is handled by the SANE subsystem. Its Windows counterpart, TWAIN, includes the user interface with the scanning routines – in other words, the look-and-feel of the scanner controls are part and parcel with the drivers which talk to the scanner. If you like the way the driver works but hate the way the controls work, the most you can do is buy a different scanner. SANE, however, separates the user interface from the drivers.
Some Commands
(The following worked with an AcerScan 620UT USB scanner I was able to get working on two different Linux distros, the first being Fedora Core 2 (running on a 450 MHz Athlon) and the second being Ubuntu/Kubuntu (warty and hoary versions) on a 1.7 GHz AMD Duron.) Some scanners need to have the firmware uploaded when first powered up. SANE can be configured to do this (need to document), but if the scanner gets switched off without a computer reboot, SANE may need to be prompted to re-upload. As far as I know, the only way to do this is to re-initialize part of the USB subsystem. Do this once, to find out what modules you use:
lsmod|grep usb
This returns one or more lines showing what USB modules you have installed.
example from Ubuntu 5.x:
usbcore 107384 2 ohci_hcd
example from Ubuntu 6.06:
usb_storage 74304 0 usbcore 130820 4 usb_storage,spca5xx,ohci_hcd scsi_mod 139496 4 sg,sd_mod,usb_storage,libata
(The large number may vary.) With Fedora Core 2, I got "uhci_hcd" instead of "ohci...".
Make sure you are root, and then substitute the appropriate module name in the next command:
rmmod ohci-hcd
(Note that the module commands consider "-" and "_" to be equivalent; "-" is usually easier to type, so I will use it instead.) If the command takes more than a second or two to return to a prompt, turn off the scanner, wait a few seconds, and then turn it back on again. (This was necessary under FC2 but not under Ubuntu; this may have been a difference in the PC hardware or in the software; the hardware running FC2 was a few years older. The scanner generally behaved better under Ubuntu.)
Next, again substitute the appropriate module name in the following command:
modprobe ohci-hcd
Assuming no errors have shown up, try this: sane-find-scanner This should return with something like this:
# No SCSI scanners found. If you expected something different, make sure that # you have loaded a SCSI driver for your SCSI adapter. # Also you need support for SCSI Generic (sg) in your operating system. # If using Linux, try "modprobe sg". found USB scanner (vendor=0x04a5 [Color], product=0x2040 [FlatbedScanner 13]) at libusb:001:002 # Your USB scanner was (probably) detected. It may or may not be supported by # SANE. Try scanimage -L and read the backend's manpage. # Not checking for parallel port scanners. # Most Scanners connected to the parallel port or other proprietary ports # can't be detected by this program. # You may want to run this program as root to find all devices. Once you # found the scanner devices, be sure to adjust access permissions as # necessary.
Another example, from Ubuntu 6.10:
# sane-find-scanner will now attempt to detect your scanner. If the # result is different from what you expected, first make sure your # scanner is powered up and properly connected to your computer. # No SCSI scanners found. If you expected something different, make sure that # you have loaded a kernel SCSI driver for your SCSI adapter. # Also you need support for SCSI Generic (sg) in your operating system. # If using Linux, try "modprobe sg". found USB scanner (vendor=0x04a5 [Color], product=0x2040 [ FlatbedScanner 13]) at libusb:001:006 found USB scanner (vendor=0x0923, product=0x010f, chip=ICM532B?) at libusb:001:004 # Your USB scanner was (probably) detected. It may or may not be supported by # SANE. Try scanimage -L and read the backend's manpage. # Not checking for parallel port scanners. # Most Scanners connected to the parallel port or other proprietary ports # can't be detected by this program. # You may want to run this program as root to find all devices. Once you # found the scanner devices, be sure to adjust access permissions as # necessary.
As long as you get the "found USB..." message (or a similar SCSI message, if your scanner is SCSI), something is working. If you've gained confidence in how things work, you can skip the next step, which is just to do what the above message recommends:
scanimage -L
If scanimage seems happy, then you should be able to use the "File / Acquire / XSane / Device Dialog" menu in GIMP (or a corresponding menu item in any other graphics application) to use the scanner. Sometimes I got the "found USB scanner" message and then the next step wouldn't work, and doing "sane-find-scanner" again would claim it could no longer find my scanner. At that point, I've tried several different things and always eventually been able to get it to work:
- turning the scanner off and on again
- running "rmmod ohci-hcd", turning the scanner off and on, then running "modprobe ohci-hcd"
- unmounting and mounting usbdevfs
Network Scanning
SANE was designed in a modular way which allows a scanner device to be networked. More information on this once I've played around with it, but meanwhile a relevant command is sane-net and there's also information here.
Scribbled Notes
Apparently the process goes something like this...
- Get your scanner working locally (process should be discussed elsewhere).
- /etc/services should contain a line like this:
sane-port 6566/tcp # SANE network scanner daemon
- You can determine this by typing grep sane /etc/services; in my case, the line was already there as shown, so I left it.
- The next part depends on which network daemon you are running, initd or xinetd
- for initd, /etc/inetd.conf should contain a line like the following (use the actual path to saned):
sane-port stream tcp nowait saned.saned /usr/sbin/saned saned
sane-port stream tcp nowait saned.saned /usr/sbin/tcpd saned
- for xinetd, /etc/xinetd.conf should contain a block like this (use the actual path to saned):
service sane-port { socket_type = stream server = /usr/local/sbin/saned protocol = tcp user = saned group = saned wait = no disable = no }
You also apparently need to make sure that the user and group "saned" exist and that they have permission to use the scanner. On my system, I was able to make that happen by using the "Users and Groups" utility (users-admin) and giving the saned user (which already was there) access to "scanner devices" (click on "saned" user, click "Properties" button, and select "user privileges" tab on the dialog which pops up).
The acid test for user "saned"'s ability to access the scanner is to attempt a scanimage as that user; I used this command:
sudo -u saned scanimage -L
When it works, you get back the same message as running "scanimage -L" as yourself (or root, or whoever has permission to use the scanner).
For parallel scanners, things apparently are a bit more complicated: "...if you want to use saned to access a parallel port scanner, and the respective backend doesn't support libieee1284 yet (you may want to file a bugreport against the backend), you have to replace saned.saned with root in your inetd.conf or user = saned, group = saned with user = root in your xinetd.conf and you do not need to change any device access rights." [1]
- Next, restart inetd or xinetd (whichever is running).
- Now you can test the saned daemon to see if it is accepting connections:
$ {{Linuxcmd|telnet]] localhost 6566
So far, I haven't been able to get past this point; I get the following message:
telnet: Unable to connect to remote host: Connection refused