Tuesday, October 18, 2016

xsane - usb scanner detection

Linux scanner can be even worse than Linux printer. Inadequacies in configuration software have continued for at least a decade. Sometimes scanners are detected, sometimes they're not. Sometimes only in root, sometimes only with sane-find-scanner, but not with scanimage -L. Avoiding lost weekends and domestic disputes is not always possible.

A couple points. First, $ scanimage -L is the gold standard. If this works, scanning works, even if sane-find-scanner does not. Second, if it's a recent Epson, then no matter what the documentation or forums appear to indicate, libsane-epkowa is likely the answer. There are tools for tracking down the answers to any model scanner further down. Just for an example however, here is the impossibly counterintuitive solution to configuring an Epson Perfection V370.
  1. # nano /usr/share/sane
    Comment all but usb
  2. # nano /etc/sane.d/dll.conf
    Comment all but epkowa, and add epkowa if it's not included.
  3. # nano /etc/sane.d/epkowa.conf
    Comment all but usb
  4. # nano /lib/udev/rules.d/49-sane.rules
    Be sure an uncommented line exists for the printer allowing permissions...
    # EPSON Perfection V370 Photo
    ATTRS{idVendor}=="04b8", ATTRS{idProduct}=="014a", MODE="0664", ENV{libsane_matched}="yes", GROUP="scanner"
    ...and that you belong to the named group:
    # nano /etc/group
    With multifunction printers, setfacl information may also be necessary.

tools

1) use strace when the scanner is found with sane-find-scanner, but not with scanimage -L.
# strace scanimage -L 2>&1 |tee bigfile.txt
Here's an interesting portion of the resultant 684K file; large until one comments out unnecessary printers inside /etc/sane.d/dll.conf :
stat64("/etc/sane.d/dll.d/epkowa.conf", {st_mode=S_IFREG|0644, st_size=7, ...}) = 0
open("./dll.d/epkowa.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/sane.d/dll.d/epkowa.conf", O_RDONLY) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=7, ...}) = 0
read(4, "epkowa\n", 4096) = 7
read(4, "", 4096) = 0
close(4) = 0
getdents(3, /* 0 entries */, 32768) = 0
close(3)
Grep in your file for epson, until you find something akin to /run/udev/data/c187:2 and cat it to verify the scanimage reads from it and your /lib/udev/rules.d/49-sane.rules file:
$ cat /run/udev/data/c189:14
I:54330183574
E:ID_VENDOR=EPSON
E:ID_VENDOR_ENC=EPSON
E:ID_VENDOR_ID=04b8
E:ID_MODEL=EPSON_Perfection_V37_V370
E:ID_MODEL_ENC=EPSON\x20Perfection\x20V37\x2fV370
E:ID_MODEL_ID=014a
E:ID_REVISION=0100
E:ID_SERIAL=EPSON_EPSON_Perfection_V37_V370
E:ID_BUS=usb
E:ID_USB_INTERFACES=:ffffff:
E:libsane_matched=yes
E:ID_VENDOR_FROM_DATABASE=Seiko Epson Corp.
E:ID_PATH=pci-0000:00:12.2-usb-0:1
E:ID_PATH_TAG=pci-0000_00_12_2-usb-0_1
E:ID_FOR_SEAT=usb-pci-0000_00_12_2-usb-0_1
G:uaccess
G:seat
2) use /lib/udev/rules.d/49-sane.rules
3) use
#lsusb
# udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/002/009)
... to write udev rules
4) use /usr/lib/libsane/
USB printers are not connected through a network, but their device ID's can be handled as if they were, eg as if they have SNMP (Simple Network Management Protocol). Eg, from this page:
All the above is quite easy to implement if the printer is network connected, now if the printer is USB or PPI connected you need to get your hands into the HP SNMP Proxy Agent, you can find a great post here. It says that basically it is a little Windows software that piggy-backs on the standard Windows SNMP service and provides SNMP data on the default HP printer connected to a computer via USB or parallel cable.


4) look into /usr/lib/sane/libsane-[yourprinter], eg /usr/lib/sane/libsane-epkowa.so.1.0.15



No comments: