[sane-devel] SNAPSCAN 1212U and libusb troubles

Christopher Marshall christopherlmarshall@yahoo.com
Mon, 2 Feb 2004 06:41:30 -0800 (PST)


Barbara:

I think the key is in the debug output from xsane below:

>barbara@babs1:~$ xsane
>[sanei_debug] Setting debug level of snapscan to 64.
>[snapscan] sane_snapscan_init
>[snapscan] sane_snapscan_init: Snapscan backend version 1.4.35
>[snapscan] add_usb_device(/dev/usb/scanner0 bus=usb)
>[snapscan] add_usb_device: Detected (kind of) an USB device
>[snapscan] snapscani_usb_open(/dev/usb/scanner0)
>[snapscan] add_usb_device: error opening device /dev/usb/scanner0:
>Invalid argument
>[snapscan] add_usb_device(libusb:001:003)
>[snapscan] add_usb_device: Detected (kind of) an USB device
>[snapscan] snapscani_usb_open(libusb:001:003)
>[snapscan] add_usb_device: error opening device libusb:001:003: Access
>to resource has been denied
>[snapscan] sane_snapscan_get_devices (0xbfffe748, 0)
>[snapscan] sane_snapscan_exit

You are running xsane as a non-root user, and when xsane tries to access the device
   snapscan:libusb:001:003
it complains that access was denied.  I'm guessing that's because the special files in
/proc/bus/usb that represent libusb devices are owned by root and don't have "world-write"
permissions.

If you had typed, as root, 

   chmod a+rw /proc/bus/usb/001/003

before running xsane as a regular user, it would probably have worked.

Since the bbb:ddd address of the scanner can change every time you plug it in, it can be tricky to
write configuration scripts that will handle usb hot-plugging without manual intervention.  

Depending on how security conscious you are there are a couple of different approaches.  One of
the simpler things you could do is write a script to find every ddd:bbb file in /proc/bus/usb and
"chmod a+rx" it.  Slightly more complex would be to have a script that ran sane-find-scanner and
processed the output to get the device string.  Here are two functions I use in my scripts:

function find_libusb_scanner1 {
   local s1=$(sane-find-scanner | grep "libusb:")

   if [ -z "$s1" ] ; then
      echo "none"
   else
      bbb=$(echo "$s1" | cut -d":" -f2)
      ddd=$(echo "$s1" | cut -d":" -f3)
      echo "/proc/bus/usb/${bbb}/${ddd}"
   fi
}

function find_libusb_scanner2 {
   local s1=$(sane-find-scanner | grep "libusb:")

   if [ -z "$s1" ] ; then
      echo "none"
   else
      bbb=$(echo "$s1" | cut -d":" -f2)
      ddd=$(echo "$s1" | cut -d":" -f3)
      echo "plustek:libusb:${bbb}:${ddd}"
   fi
}

I use the first function to get the device in the proper form to run "chmod" on, and the second
function to get the device in the proper form for using in the scanimage "-d" argument.

Hope this helps.

Chris Marshall


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/