USB Scanner Support

From ArchWiki
Jump to navigation Jump to search

USB Scanner

This document describes the process of installing a scanner with a USB interface in Arch Linux. Since I only have one scanner and thus only experience with this very model, your experience may be quite different. I hope, however, that this document gives you at least an idea how to start.

Update: Since I first wrote this document, the installation routine for the sane package has been improved. The only thing you have to do for supported scanners is to install sane with pacman and add your username to the group "scanner". This document is therefore only necessary for scanners that are not listed in the default usermap file of sane, for people who are interested in hotplug configuration or for those who are interested in network support.

Verify that your scanner works with SANE

Many but not all of the scanners on the market are supported by SANE. The best way to find out whether yours is supported is to directly check on the project's website: [1]. On this site, you will also find the information, which SANE backend you will need.

Install sane, xsane and hotplug

  1. Verify that you have the necessary packages installed on your system.
 # pacman -Q hotplug sane xsane

While xsane is not necessary, it's certainly a good idea to download it, for the program is very useful.

  1. If pacman complains that one or both of the packages is not installed, you can do so by typing
 # pacman -S hotplug


 # pacman -S sane


 # pacman -S xsane

Get scanner to work as root

  1. Open a terminal and log in as root
  1. Execute the program
 # sane-find-scanner

to verify that SANE correctly detects your scanner.

  1. We will now do a testscan from the commandline. To do that, you have to get the device name of your scanner first. The easiest way to find it, is to user the program scanimage:
 # scanimage -L

In my case, the output of this was

 device `plustek:libusb:003:004' is a Canon N1240U/LiDE30 USB flatbed scanner

With this information, we are ready to start the testscan:

 # scanimage -d plustek:libusb:003:004 -x 50 -y 50 --format=tiff > /home/hunzikea/test.tiff

If this correctly creates a file called test.tiff with a reasonable content, we are ready to setup the scanner for the ordinary user.

Configuring hotplug

In this section we will use hotplug to detect when the scanner is plugged in and, as a consequence, set the permissions on the scanner device so that members of the group \"users\" can use it.

  1. First, you will need to get the Vendor and ProdID number of your scanner. To get those, type, as root,
 # cat /proc/bus/usb/devices

Search the output of this command for your scanner. In that block of information, you will find your scanner's Vender and ProdID numbers. In my case, the relevant output of the above command was

T:  Bus<code>03 Lev</code>01 Prnt<code>01 Port</code>01 Cnt<code>02 Dev#</code>  4 Spd<code>12  MxCh</code> 0
D:  Ver<code> 1.10 Cls</code>ff(vend.) Sub<code>00 Prot</code>00 MxPS<code> 8 #Cfgs</code>  1
P:  Vendor<code>04a9 ProdID</code>220e Rev= 1.00
S:  Manufacturer=Canon
S:  Product=CanoScan
C:* #Ifs<code> 1 Cfg#</code> 1 Atr<code>a0 MxPwr</code>500mA
I:  If#<code> 0 Alt</code> 0 #EPs<code> 3 Cls</code>ff(vend.) Sub<code>00 Prot</code>ff Driver=(none)
E:  Ad<code>81(I) Atr</code>03(Int.) MxPS<code>   1 Ivl</code>16ms
E:  Ad<code>82(I) Atr</code>02(Bulk) MxPS<code>  64 Ivl</code>0ms
E:  Ad<code>03(O) Atr</code>02(Bulk) MxPS<code>  64 Ivl</code>0ms

So, for me, the Vendor number is 04a9 and the ProdID is 220e.

  1. Create a usbscanner.usermap file in /etc/hotplug/usb. Open your favorite text editor, e.g.
 # cd /etc/hotplug/usb
 # vi usbscanner.usermap

Add the following two lines to this file:

 #Name of your scanner
 usbscanner 0x0003 0x04a9 0x220e 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000

Instead of the values 0x04a9 and 0x220e, insert the Vendor oder ProdID numbers from step 1. Save the file as usbscanner.usermap.

  1. We now need to create a shell script to set the correct permissions on the scanner device. Again, with you favorite text editor, create a file called usbscanner in /etc/hotplug/usb. Insert the following text
# /etc/hotplug/usb/usbscanner


if [[ \"${ACTION}\" = \"add\" ]] && [[ -f \"${DEVICE}\" ]]
    chmod o-rwx \"${DEVICE}\"
    chgrp \"${GROUP}\" \"${DEVICE}\"
    chmod g+rw \"${DEVICE}\"
and save the script.

# Make the script executable
# chmod +x /etc/hotplug/usb/usbscanner

Test your configuration

  1. To test your configuration, plug in your scanner and turn it on. If it was already plugged in before, plug it out and in again to invoke the script.
  1. List the contents of /proc/bus/usb by typing
 # ls -lR /proc/bus/usb

There should be at least one device which doesn't say \"root\" twice. On my machine, the output looks like so:

total 0
-rw-r--r--  1 root root  43 Apr 12 22:02 001
-rw-r--r--  1 root root  73 Apr 12 22:02 002
-rw-rw----  1 root users 57 Apr 12 22:08 004
 Notice the last line.

Use your scanner in your favourite application

You can now use gimp or xsane to scan pictures with your scanner. Enjoy!

Sharing Your Scanner Over a Network

You can share your scanner with other hosts on your network who use sane, xsane or xsane-enabled Gimp. To set up the server (the PC which is connected to your scanner), first indicate which hosts on your network are allowed access.

Add the following to the /etc/sane.d/sane.conf file:

# required
# allow all local hosts

Of course, you may need to change "" to suit your local area network. You can also specify individual hosts, as the following examples illustrate:

# specific host with static IP address
# specific hosts supported by local DNS or /etc/hosts

Ensure xinetd is installed:

# pacman -S xinetd
:: xinetd-#.#.##-#: is up to date.  Upgrade anyway? [Y/n] n

Also be sure to add xinetd to the list of DAEMONS in /etc/rc.conf

Next, create a file called /etc/xinetd.d/sane-port and include the following:

service sane-port
   port        = 6566
   socket_type = stream
   wait        = no
   user        = nobody
   group       = nobody
   server      = /usr/sbin/saned
   disable     = no

Ensure that port 6566 is not blocked by any firewall which would affect connections inside your local area network.

Now start (or restart) xinetd:

# /etc/rc.d/xinetd start

Your scanner can now be used by other workstations, accross your local area network.

Accessing Your Scanner from a Remote Workstation

You can access your network-enabled scanner from a remote Arch Linux workstation.

To set up your workstation, begin by installing xsane:

# pacman -S xsane

Next, specify the server's host name or IP address in the /etc/sane.d/net.conf file:

# static IP address
# OR /etc/hosts or DNS supported host name

Now test your workstation's connection, from a non-root login prompt:

$ xsane

After a short while, xsane should find your remote scanner and present you with the usual windows, ready for network scanning delight!