Your scanner works on Linux
Benq 5000 scanner for example
Introduction
In this article I'll show you how to get your scanner to work on GNU/Linux.
I'm using several Linux distributions, like Ubuntu 7.04 and Fedora Core 5.0,
but this procedure should work on any recent Linux kernel having the udev system enabled.
I'm discussing BenQ 5000 USB scanner, other scanners should be similar.
There are three important issues about scanners, 1st is to have the user-land back-end driver for it,
2nd is to have the firmware file loaded into the scanner if needed, and the last step is to set permission correctly.
In Linux we have a SANE system for scanners,
which is a multi-platform scanning system (as opposed to TWAIN system in MS-Windows).
SANE is short for Scanner Access Now Easy.
And we have several ways to utilize it, of course first of all, we have the command line utilities,
and we have the GTK+ graphical interface called XSANE and the QT graphical interface for KDE
which is called "Quite insane!" (despite the name it's very nice)
and many others.
Of course, you know GIMP, the best Image editing tool I know.
it got plug-ins to use both XSANE and "Quite insane", but in most cases only the first
is installed by default.
You find them under File -> Acquire menu in the main GIMP window (the one with the tools box).
Detection
You can see all the USB devices by examining the contents of
/proc/bus/usb/devices pseudo file. Because we are looking for a scanner
I'm going to search that file for the word "Scan" and displaying the surrounding context,
you may use GUI text editors, but Why bothering?! a single command line do that
(type onlt the bold text line just after the prompt of "bash$")
bash$ grep -A6 -B5 -i 'Scan' /proc/bus/usb/devices
T: Bus=05 Lev=01 Prnt=01 Port=04 Cnt=01 Dev#= 6 Spd=480 MxCh= 0
D: Ver= 1.00 Cls=ff(vend.) Sub=ff Prot=ff MxPS= 8 #Cfgs= 1
P: Vendor=04a5 ProdID=20f8 Rev= 1.15
S: Manufacturer=Color
S: Product= FlatbedScanner 22
C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr=100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 8 Ivl=0ms
E: Ad=83(I) Atr=03(Int.) MxPS= 8 Ivl=16ms
it tells us that the scanner is plugged and turned on, and where it's plugged
(to the 6th device of the 5th bus, which may change next boot or when you unplug it then plug it again) and what is the ID of the Vendor and the Product
(in this case 04a5 means Acer scanners which are now BenQ scanners and 20f8 for the model called BenQ 5000).
You may play some tricks with the kernel and the udev system,
enjoy trying the following commands:
bash$ cat /sys/class/usb_device/usbdev5.6/device/product
FlatbedScanner 22
bash$ cat /sys/class/usb_device/usbdev5.6/device/idProduct
20f8
bash$ udevinfo -q path -n bus/usb/005/006
/class/usb_device/usbdev5.6
bash$ udevinfo -q all -p /class/usb_device/usbdev5.6
P: /class/usb_device/usbdev5.6
N: bus/usb/005/006
S: scanner-usbdev5.6
bash$ udevinfo -a -p /class/usb_device/usbdev5.6 | less
... display long information
Please notice that you have to replace 5 and 6 with the bus and device number
as obtained from the first command.
The udev system refers to devices by name (in this case bus/usb/005/006)
or by path (in this case /class/usb_device/usbdev5.6, which is just was the rest of the /sys/... full-filename)
and a device may have some symbolic links to make referring to them easier
or in a more comfortable fasion like scanner-usbdev5.6
(the full name is /dev/scanner-usbdev5.6)
this is controlled through the rules set of udev system.
The command before the last one tells us them all with P: for path,
N: for name, S: for symbolic links.
That was the kernel, but one should have a user-land tool to ask for images,
It's the SANE back-end.
If every thing is fine then the command line tool scaneimage
should be able to detect the scanner by using the -L option,
at least as root (super user). First be root (by typing "su" then root password or if you have turned off the root account as in Ubunto type "sudo su" or "sudo -i" followed by your password)
then try the following two commands (only the bold text after the root Bash prompt bash#)
bash# scanimage -L
device `snapscan:libusb:005:006' is a Acer FlatbedScanner22 flatbed scanner
bash# sane-find-scanner
#... long long tips ...
found USB scanner (vendor=0x04a5 [Color], product=0x20f8 [ FlatbedScanner 22]) at libusb:005:006
#... long long tips ...
Firmware loading
First let's know which is the SANE back-end (driver) we need to use by searching
for the name "BenQ" or better the Product ID of our scanner (which is 20f8 in our case)
bash$ grep -i '20f8' /etc/sane.d/*
/etc/sane.d/snapscan.conf:usb 0x04a5 0x20f8
It tells us that snapscan back-end is responsible for this specific model of scanners (and others as well)
and that file /etc/sane.d/snapscan.conf contains the configuration of this driver.
This file tells us that those scanners need to load firmware from the computer to the scanner.
I noticed that if the scanner was on and loaded the firmware then it won't lose it as long as it's on
(for example if Fedora Core is configured to load the firmware and you use it there then you rebooted to Ubuntu which is not yet configured it will work).
It's not very hard to get the firmware, put the CD that come with the scanner and mount it then
locate a .bin file on it (usually named after the Product ID and revision number)
to do that I use this command (you may need to replace /media/cdrom0 with the yours own one)
bash$ cd /media/cdrom0
bash$ find ./ -iname '*.bin'
...
./driver/bin/20f8v115.bin
...
just copy this file to your hard disk filesystem (for example to /usr/share/sane/snapscan/)
by typing as root (I told you how to be root before)
in the very folder of the cdrom (ie. type cd /media/cdrom0 then continue)
bash# mkdir -p /usr/share/sane/snapscan/
bash# cp -v driver/bin/20f8v115.bin /usr/share/sane/snapscan/
You need to replace driver/bin/20f8v115.bin with the one we have
found (or just press TAB to let Bash complete the file name for you).
If you think this is too tricky for you you may do that in the graphical interface,
run the file manager in super user mode then copy and past the file.
In GNOME the file manager is nautilus while in KDE it's konqueror.
Now we have to tell the driver were did we put the firmware,
open the back-end configuration file (which is /etc/sane.d/snapscan.conf) in your favorite text editor (you need super user privileges for it, run for example "gksu gedit /etc/sane.d/snapscan.conf" or with "gksudo" instead of "gksu" to the rest of the command if root is turned off)
to fix this line (which usually point to non-existing file) to point to our firmware
firmware /usr/share/sane/snapscan/20f8v115.bin
then save the file. Try now to detect the scanner with SANE, using
scanimage -L or sane-find-scanner
(as root of course) as it should work now.
Access and Permissions
Of course, scanning is not something you do as root, so the last two commands should
also work as regular user but because the default permissions given to the
device files corresponding to the USB scanner were so restrictive
you can't.
bash$ scanimage -L
No scanners were identified. If you were expecting something different,
check that the scanner is plugged in, turned on and detected by the
sane-find-scanner tool (if appropriate). Please read the documentation
which came with this software (README, FAQ, manpages).
Actually, in our case it's due to that our scanner is not listed on the
udev rules for scanners, that's why the device files are not allowed to be accessed except as root
if this is the case one might think of changing the permissions for the device files
but there are two problems with this solution, 1st, it could be unplugged then plugged back on different USB
device, 2nd the device files are no longed real device files, they are pseudo files
shown by the udev system and when you reboot you'll find them with the original permissions
as set by the policy of the udev rules.
For the sake of playing around, you may try changing permissions
by typing (as root),
bash# chown root:scanner /dev/bus/usb/005/006 /proc/bus/usb/005/006
bash# chmod 664 /dev/bus/usb/005/006 /proc/bus/usb/005/006
this command gave a group of users called "scanner" group to have read/write
access to the scanner (another suggestion is to be the owner of the file instead of "root:scanner" put your login name)
then try scanning or detecting the scanner as regular user.
To have do it right, you should set the udev rules correctly,
we have already have rules for scanners in most distribution,
the file is called /etc/udev/rules.d/??-libsane.rules
(where ?? are two digits, in Fedora Core it's 60, in Ubuntu it's 45)
this file should have an entry for our scanner
in order to implement the distribution policy on the device files,
in Fedora Core the file /etc/udev/rules.d/60-libsane.rules
add an entry like following one after the line of any other scanner
(just duplicate a previous line then modify the IDs)
SYSFS{idVendor}=="04a5", SYSFS{idProduct}=="20f8", SYMLINK+="scanner-%k"
and in Debian and Ubuntu (and MEPIS ..etc) we have the file
/etc/udev/rules.d/45-libsane.rules which should have an entry
like this one
SYSFS{idVendor}=="04a5", SYSFS{idProduct}=="20f8", MODE="664", GROUP="scanner"
Don't bother even typing it just duplicate that on any other scanner then replace the IDs.
The difference between the two policies is that in Fedora Core the console user (whose in front of the screen, who plug the scanner)
owns the device files,
while in Ubuntu it's the members of "scanner" group owns the files.
The other difference that the Fedora Core rules create a link named "scanner-usbdevX.Y"
while in Ubuntu it works for the original device files as those rules runs before the rules that create
the vanilla USB device files so to speak.
Enjoy Scanning
After we have played with Linux kernel, and practiced some commands
it's time for you to restart your computer (not needed but as I want to make sure that the changes are permenent)
and enjoy scanning.
XSANE is very crowded, you should start looking at preview window (if it's not there, show it from the XSANE main window from Windows -> Preview or something like that).
There are too many options in XSANE, some are specific to your scanner back-end,
others are for all scanners and so on.
But because I'm too comfortable with GIMP, I just preview then select the area which I want to scan,
then set the resolution then just scan. After that I do all the editing inside GIMP (although XSANE is very rich with tools)
There are a very useful feature called "batch scanning" which enable you to scan several
different pictures (rectangles) in one pass.
Sometimes you may think that XSANE is frozen or hanged but this is not true,
when I run the command line tool I've got this
[snapscan] Scanner warming up - waiting 21 seconds.
I think this is due to power management or firmware loading or both.
(it also happens on Windows but there the whole system hangs for warming up).
Also note that if some program is using the scanner others can't use it.
SANE got some features that I can't think that there is someone on earth uses them,
like scanning over a network by running SANE daemon! (this feature is turned off or even not included in most distributions)
|