Difference between revisions of "USB Scanner Support"

From ArchWiki
Jump to: navigation, search
(removed parts about tcp_wrappers (deprecated))
Line 5: Line 5:
 
This document describes the process of installing a scanner with a USB interface in Arch Linux.  
 
This document describes the process of installing a scanner with a USB interface in Arch Linux.  
  
'''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.
+
'''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 "scanner" group. 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====
 
====Verify that your scanner works with SANE====
Line 12: Line 12:
 
====Install sane====
 
====Install sane====
  
  # pacman -S sane
+
pacman -S sane
  
While xsane is not necessary, but the program is very useful under X windows, it's with gtk2 GUI.
+
While xsane is not necessary, but the program is very useful under X, it's with gtk2 GUI.
  
  # pacman -S xsane
+
pacman -S xsane
  
 
By default, '''hotplug''' has been installed on your Arch system, but if not, you can decide to install or not. However it's strongly recommended.
 
By default, '''hotplug''' has been installed on your Arch system, but if not, you can decide to install or not. However it's strongly recommended.
Line 27: Line 27:
 
# Execute the program
 
# Execute the program
  
  # sane-find-scanner
+
sane-find-scanner
  
 
to verify that SANE correctly detects your scanner.
 
to verify that SANE correctly detects your scanner.
  
# Get the device name of your scanner. The easiest way to find it, is to user the program scanimage:
+
# Get the device name of your scanner. The easiest way to find it is to use the program scanimage:
  
  # scanimage -L
+
scanimage -L
  
The output of this was alike:
+
The output of this was:
  
 +
<code>
 
   device `plustek:libusb:003:004' is a Canon N1240U/LiDE30 USB flatbed scanner
 
   device `plustek:libusb:003:004' is a Canon N1240U/LiDE30 USB flatbed scanner
 +
</code>
  
With this information, we are ready to start the testscan:
+
With this information, we are ready to start the test scan:
  
  # scanimage -d plustek:libusb:003:004 -x 50 -y 50 --format=tiff > /home/hunzikea/test.tiff
+
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.
+
If this correctly creates a file called test.tiff with a reasonable content, we are ready to set up the scanner for the ordinary user.
  
  # gpasswd -a yourusername scanner
+
gpasswd -a yourusername scanner
  
 
Minor remarks for some plustek scanners (noticeably Canoscan ones), they require a lock directory. Make sure that /var/lock/sane directory exists, that its permissions are 660, and that it is owned by <user>:scanner. If the directory permissions are wrong, only root will be able to use the scanner.
 
Minor remarks for some plustek scanners (noticeably Canoscan ones), they require a lock directory. Make sure that /var/lock/sane directory exists, that its permissions are 660, and that it is owned by <user>:scanner. If the directory permissions are wrong, only root will be able to use the scanner.
Line 58: Line 60:
 
====Epson Perfection 1270====
 
====Epson Perfection 1270====
  
This is for some scanners which are listed as 'good' support but you simple don't know how to make it work, here I take '''Epson Perfection 1270''' as an example.
+
This is for some scanners which are listed as "good" support but you simple don't know how to make it work, here I take '''Epson Perfection 1270''' as an example.
  
 
By checking the [http://www.sane-project.org/sane-supported-devices.html sane-supported-devices] page, you can find very useful information for your scanner. Here I know Epson Perfection 1270 is supported by snapscan backend.
 
By checking the [http://www.sane-project.org/sane-supported-devices.html sane-supported-devices] page, you can find very useful information for your scanner. Here I know Epson Perfection 1270 is supported by snapscan backend.
Line 66: Line 68:
 
Modify configuration file of snapscan backend:
 
Modify configuration file of snapscan backend:
  
  # vi /etc/sane.d/snapscan.conf  
+
vi /etc/sane.d/snapscan.conf  
  
 
Change the firmware path line with yours. :
 
Change the firmware path line with yours. :
  
 +
<pre>
 
   # Change to the fully qualified filename of your firmware file, if
 
   # Change to the fully qualified filename of your firmware file, if
 
   # firmware upload is needed by the scanner
 
   # firmware upload is needed by the scanner
 
   firmware /mnt/mydata/Backups/firmware/esfw3e.bin
 
   firmware /mnt/mydata/Backups/firmware/esfw3e.bin
 +
</pre>
  
 
And add the following line in the end or anywhere you like
 
And add the following line in the end or anywhere you like
  
 +
<pre>
 
   # Epson Perfection 1270
 
   # Epson Perfection 1270
 
   usb 0x04b8 0x0120
 
   usb 0x04b8 0x0120
 +
</pre>
  
 
You can get such code information (''usb 0x04b8 0x0120'') by "sane-find-scanner" command.
 
You can get such code information (''usb 0x04b8 0x0120'') by "sane-find-scanner" command.
Line 83: Line 89:
 
Also add such information lines in your libsane.usermap file to setup your privilage, like:
 
Also add such information lines in your libsane.usermap file to setup your privilage, like:
  
  vi /etc/hotplug/usb/libsane.usermap
+
vi /etc/hotplug/usb/libsane.usermap
 
    
 
    
 
   #Epson Perfection 1270
 
   #Epson Perfection 1270
Line 101: Line 107:
 
# First, you will need to get the Vendor and ProdID number of your scanner. To get those, type, as root,
 
# 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
+
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
 
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
Line 122: Line 128:
 
# Create a usbscanner.usermap file in /etc/hotplug/usb. Open your favorite text editor, e.g.
 
# Create a usbscanner.usermap file in /etc/hotplug/usb. Open your favorite text editor, e.g.
  
  # cd /etc/hotplug/usb
+
vi /etc/hotplug/usb/usbscanner.usermap
  # vi usbscanner.usermap
+
  
 
Add the following two lines to this file:
 
Add the following two lines to this file:
  
 +
<pre>
 
   #Name of your scanner
 
   #Name of your scanner
 
   usbscanner 0x0003 0x04a9 0x220e 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
 
   usbscanner 0x0003 0x04a9 0x220e 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000
 +
</pre>
  
 
Instead of the values 0x04a9 and 0x220e, insert the Vendor oder ProdID numbers from step 1.
 
Instead of the values 0x04a9 and 0x220e, insert the Vendor oder ProdID numbers from step 1.
Line 162: Line 169:
 
# List the contents of /proc/bus/usb by typing
 
# List the contents of /proc/bus/usb by typing
  
   # ls -lR /proc/bus/usb
+
   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:
 
There should be at least one device which doesn't say \"root\" twice. On my machine, the output looks like so:
Line 174: Line 181:
 
</pre>
 
</pre>
  
  Notice the last line.
+
Notice the last line.
  
 
====Use your scanner in your favourite application====
 
====Use your scanner in your favourite application====
Line 206: Line 213:
 
Ensure xinetd is installed:
 
Ensure xinetd is installed:
 
<pre>
 
<pre>
# pacman -S xinetd
+
pacman -S xinetd
 
:: xinetd-#.#.##-#: is up to date.  Upgrade anyway? [Y/n] n
 
:: xinetd-#.#.##-#: is up to date.  Upgrade anyway? [Y/n] n
 
</pre>
 
</pre>
Line 238: Line 245:
  
 
Ensure that ports 6566 and 6567 are not blocked by any firewall which would affect connections inside your local area network. You can check which ports are being used by running the daemon in debug mode:
 
Ensure that ports 6566 and 6567 are not blocked by any firewall which would affect connections inside your local area network. You can check which ports are being used by running the daemon in debug mode:
<pre>
+
 
# saned -d128
+
saned -d128
</pre>
+
 
 
instead of using xinetd.
 
instead of using xinetd.
  
 
Normally, you just need to start (or restart) xinetd as root:
 
Normally, you just need to start (or restart) xinetd as root:
<pre>
+
 
# /etc/rc.d/xinetd start
+
/etc/rc.d/xinetd start
</pre>
+
  
 
Your scanner can now be used by other workstations, across your local area network.
 
Your scanner can now be used by other workstations, across your local area network.
Line 255: Line 261:
  
 
To set up your workstation, begin by installing xsane:
 
To set up your workstation, begin by installing xsane:
<pre>
+
 
# pacman -S xsane
+
pacman -S xsane
</pre>
+
  
 
Next, specify the server's host name or IP address in the /etc/sane.d/net.conf file:
 
Next, specify the server's host name or IP address in the /etc/sane.d/net.conf file:
Line 268: Line 273:
  
 
Now test your workstation's connection, from a non-root login prompt:
 
Now test your workstation's connection, from a non-root login prompt:
<pre>
+
 
$ xsane
+
xsane
</pre>
+
  
 
After a short while, xsane should find your remote scanner and present you with the usual windows, ready for network scanning delight!
 
After a short while, xsane should find your remote scanner and present you with the usual windows, ready for network scanning delight!
Line 281: Line 285:
  
 
Stop xinetd (as a root):
 
Stop xinetd (as a root):
<pre>
+
 
/etc/rc.d/xinetd stop
+
/etc/rc.d/xinetd stop
</pre>
+
  
 
Run saned in debug mode as a user belonging to group scanner:
 
Run saned in debug mode as a user belonging to group scanner:
<pre>
+
 
saned -d
+
saned -d
</pre>
+
  
 
Try to scan from the client. If the scanning program at the client side reports no available devices and saned at the server reports following before exiting:
 
Try to scan from the client. If the scanning program at the client side reports no available devices and saned at the server reports following before exiting:
Line 307: Line 309:
  
 
And start xinetd again (as root):
 
And start xinetd again (as root):
<pre>
+
 
/etc/rc.d/xinetd start
+
/etc/rc.d/xinetd start
</pre>
+

Revision as of 18:21, 3 October 2011

Merge-arrows-2.pngThis article or section is a candidate for merging with Sane.Merge-arrows-2.png

Notes: please use the second argument of the template to provide more detailed indications. (Discuss in Talk:USB Scanner Support#)

USB Scanner

This document describes the process of installing a scanner with a USB interface in Arch Linux.

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 "scanner" group. 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: sane-supported-devices. On this site, you will also find the information, which SANE backend you will need. For multifunction devices from Epson see iscan

Install sane

pacman -S sane

While xsane is not necessary, but the program is very useful under X, it's with gtk2 GUI.

pacman -S xsane

By default, hotplug has been installed on your Arch system, but if not, you can decide to install or not. However it's strongly recommended.


Get scanner to work

  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. Get the device name of your scanner. The easiest way to find it is to use the program scanimage:
scanimage -L

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 test scan:

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 set up the scanner for the ordinary user.

gpasswd -a yourusername scanner

Minor remarks for some plustek scanners (noticeably Canoscan ones), they require a lock directory. Make sure that /var/lock/sane directory exists, that its permissions are 660, and that it is owned by <user>:scanner. If the directory permissions are wrong, only root will be able to use the scanner. Seems (at least on x86-64) that some programs using libusb (noticeably xsane and kooka) need scanner group rw permissions also for accessing /proc/bus/usb to work for a normal user.

That's it, have fun with your scanner.

Fixing potential problems with the above

  • To remedy the problem where an HP All-In-One device appears in the output of sane-find-scanner but does not appear in the output of scanimage -L, edit the file /etc/sane.d/dll.conf and uncomment the hpaio line.

Epson Perfection 1270

This is for some scanners which are listed as "good" support but you simple don't know how to make it work, here I take Epson Perfection 1270 as an example.

By checking the sane-supported-devices page, you can find very useful information for your scanner. Here I know Epson Perfection 1270 is supported by snapscan backend.

For Epson Perfection 1270, you also need a firmware named esfw3e.bin, you can get it from (anyone could give a working place so I can upload it?), or you can get it yourself by reference to Scanner setup & configure. I get it by installing the driver in the windows.

Modify configuration file of snapscan backend:

vi /etc/sane.d/snapscan.conf 

Change the firmware path line with yours. :

   # Change to the fully qualified filename of your firmware file, if
   # firmware upload is needed by the scanner
   firmware /mnt/mydata/Backups/firmware/esfw3e.bin

And add the following line in the end or anywhere you like

  # Epson Perfection 1270
  usb 0x04b8 0x0120

You can get such code information (usb 0x04b8 0x0120) by "sane-find-scanner" command.

Also add such information lines in your libsane.usermap file to setup your privilage, like:

vi /etc/hotplug/usb/libsane.usermap
 
 #Epson Perfection 1270
 libusbscanner 0x0003 0x04b8 0x0120 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000

Replug scanner, you have a working Epson Perfection 1270 now.

NOTE: I can scan image if I define the X and Y value, but without that error meassage occors like: "scanimage: sane_start: Error during device I/O", if anyone know why, please complete the section. ".

Configuring hotplug/udev

The following hotplug configuration steps are no longer needed (with 0.6 or above), For your information only

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.
vi /etc/hotplug/usb/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. (for newer udev, edit the /etc/udev/rules.d/sane.rules)

  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
#!/bin/bash
#
# /etc/hotplug/usb/usbscanner
#

GROUP=users

if [[ \"${ACTION}\" = \"add\" ]] && [[ -f \"${DEVICE}\" ]]
then
    chmod o-rwx \"${DEVICE}\"
    chgrp \"${GROUP}\" \"${DEVICE}\"
    chmod g+rw \"${DEVICE}\"
fi
 
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:

/proc/bus/usb/003:
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!

Network scanning

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/saned.conf file:

# required
localhost
# allow all local hosts
192.168.0.0/24

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

# specific host with static IP address
192.168.0.2
# specific hosts supported by local DNS or /etc/hosts
bristol
brandal
brutus

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
}

Note: Apparently you are more likely to achieve success specifying:

   user        = root
   group       = scanner

Add the following line to /etc/services:

sane-port 6566/tcp # SANE network scanner daemon

Ensure that ports 6566 and 6567 are not blocked by any firewall which would affect connections inside your local area network. You can check which ports are being used by running the daemon in debug mode:

saned -d128

instead of using xinetd.

Normally, you just need to start (or restart) xinetd as root:

/etc/rc.d/xinetd start

Your scanner can now be used by other workstations, across 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
192.168.0.1
# OR /etc/hosts or DNS supported host name
stratus

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!

Common problems with scanner sharing

If your saned backend, at the computer that you're trying to access shared scanner from, says that no scanners are available on the server, but scanning works locally and you're sure, that you have done everything according to the previous two chapters, check following scenarios:

Missing hostname declaration

Stop xinetd (as a root):

/etc/rc.d/xinetd stop

Run saned in debug mode as a user belonging to group scanner:

saned -d

Try to scan from the client. If the scanning program at the client side reports no available devices and saned at the server reports following before exiting:

[saned] check_host: getaddrinfo failed: Name or service not known
[saned] init: access by host 192.168.0.2 denied

then it's probably just missing declaration of your hostname in /etc/hosts

Fix it by adding following line to the /etc/hosts:

127.0.0.1     yourhostname

where "yourhostname" is the same as the one, you have chosen during instalation. Check the following line in /etc/rc.conf:

HOSTNAME="yourhostname"

And start xinetd again (as root):

/etc/rc.d/xinetd start