[sane-devel] Solved: Persistent USB Scanner Designator via udev rule and alias - Canon LiDE 60 USB

Heinz Rohde 5420108 at mailbox.org
Sat Aug 14 23:43:37 BST 2021


Hello,

I finally solved the problem to get the USB Scanner Designator
persistent.

If we use sane clients on MS Windows machines, the WIA or TWAIN drivers
that are able to connect to sane are struggling to autodetect the
scanner device (USB bus id and device id). The bus id and device id
will change with every reboot or after USB unplug-replug of scanner.

The windows software driver won't reconfigure - so your scanning
ability is broken.

The solution is to create an alias in /etc/sane.d/dll.aliases so that
the windows clients always are going to see the same alias, which is
persistent.

This is how.

Regards, Heinz.

-----8<---------------------------------------------------
How to make USB Scanner persistent
20210814
--------------------------------------------------------
This little how-to is going to use vi as text editor.
You are free to use your favorite editor of choice.

The following instructions are testet on a PC running
Debian Buster, 64bit, all updates

--------------------------------------------------------

Q: Why do we want a persistent USB scanner device designator?
A: If we use sane clients on MS Windows machines, the WIA or TWAIN
drivers that are able to connect to sane are struggling to autodetect
the scanner device (USB bus id and device id). The bus id and device id
will change with every reboot or after USB unplug-replug of scanner.
The solution is to create an alias in /etc/sane.d/dll.aliases so that
the windows clients always are going to see the same alias, which is
persistent.

It is assumed that you have setup your scanner properly according to
sane tutorial.
If sudo scanimage -L works, you're good to go.

And here we go:

- Find your scanner via lsusb

hr at r60e:~$ lsusb
Bus 001 Device 006: ID 04a9:221c Canon, Inc. CanoScan LiDE 60
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

In this example, the scanner is a CanoScan LiDE 60.

The Vendor-ID is 04a9, the Procuct-ID is 221c - this remains always the
same as long as you stick to this scanner.
Your scanner is likely to show up with different IDs, depending on make
and model.

The Bus-# is 001, the Device-# is 006 - this is fragile and will change
with reboot or after USB unplug-replug of scanner.

- Find out what backend your scanner uses

Enter either

hr at r60e:~$ scanimage -L

or

hr at r60e:~$ sudo scanimage -L

The output should look similar to this:

device `genesys:libusb:001:006' is a Canon LiDE 60 flatbed scanner

In this example, the backend for the scanner is "genesys".
You'll need this in the my_scanner script.

Furthermore, we use "LiDE" to grep the device for USB bus and number
extraction within the script my_scanner in /lib/udev

- Create bash script in /lib/udev

hr at r60e:/lib/udev$ sudo vi my_scanner

Copy this into file my_scanner:


#!/bin/bash
SANEBACKEND=genesys
ALIASFILE=/etc/sane.d/dll.aliases
GREPNAME=LiDE

# get USB bus id and number of desired scanner device to form device
string

BUS=$(lsusb | grep LiDE | awk '{ print $2}')
NUM=$(lsusb | grep LiDE | awk '{ print $4}' | sed 's/.$//')
DEVICE=$SANEBACKEND:libusb:$BUS:$NUM
echo "alias MyScanner $DEVICE" > $ALIASFILE

# comment out for optional output to screen for testing purposes
# echo BUS = $BUS
# echo NUM = $NUM
# echo DEVICE = $DEVICE

Save script file.
Make script file executable

hr at r60e:/lib/udev$ sudo chmod 755 my_scanner

Check with

hr at r60e:/lib/udev$ ls -la my_*

output should look like this

-rwxr-xr-x 1 root root 573 Aug  9 21:41 my_scanner


- Create udev rule in /etc/udev/rules.d

hr at r60e:/etc/udev/rules.d$ sudo vi z21_persistent-local.rules

Don't bother about the name, this one worked for me

Enter the following line into z21_persistent-local.rules with YOUR
VENDOR AND PRODUCT IDs

SUBSYSTEMS=="usb",ATTRS{idVendor}=="04a9",ATTRS{idProduct}=="221c",GROU
P+="scanner",RUN+="/lib/udev/my_scanner"

Save file.

Reboot your system.

Check content of /etc/sane.d/dll.aliases

hr at r60e:/etc/sane.d$ cat dll.aliases
alias MyLiDE genesys:libusb:001:006


Check if alias is used by sane.
hr at r60e:~$ scanimage -L
device `MyLiDE' is a Canon LiDE 60 flatbed scanner

Tadaa - congratulations, your scanner now has a persistent name.

--------------------------------------------------------
This took me about two weeks of web search and reading to find out how
to do it right.
Don't get fooled by recommendations to create device aliases in
/dev/... via udev rule - that might work for SCSI scanners, but not for
USB scanners. 
You can't use scanimage -d /dev/my-usbscanner which for example is
correct link into /dev/bus/usb/001/006
--------------------------------------------------------

Sources:
https://sanetwain.ozuzo.net/
FAQ-Section: My USB scanner keeps getting a different name, which makes
it difficult to save default values
Attention:
- DEVPATH seems to be deprecated, therefore I wrote the code above.
- In my system it was necessary to add GROUP+="scanner" in the udev
rule

http://www.sane-project.org/
https://wiki.debian.org/Scanner
https://wiki.debian.org/SaneOverNetwork

Recommendation for Windows Clients:
- Driver WIASANE
https://github.com/mback2k/wiasane/wiki/Downloads
- Scanning Software NAPS2
https://www.naps2.com/

--------------------------------------------------------





-----8<---------------------------------------------------


Am Freitag, den 06.08.2021, 18:48 +0200 schrieb Heinz Rohde:
> To all the people who answerd my SOS, her is the missing info to what
> I
> already tried and considered.
> 
> I hope, you all can see my text. I am quite unfamiliar with mailing-
> lists....
> 
> 
> 
> 
> 
> Hello,
> 
> I am very sorry for beeing so short with my detailed information.
> 
> 
> Here we go:
> 
> - The Scanner is a Canon CanoScan LiDE 60
> - The Scanner is
> connected to an ols ThinkPad r60e via USB (All USB ports are USB 2.0)
> -
> The Scanner is handeled by genesys backend.
> - The OS is Debian Buster 64
> bit, all updates installed.
> - The IP number of the Thinkpad is
> 192.168.168.245
> 
> - The scanner works locally
> hr at r60e:~$ sudo scanimage -L
> d
> evice `genesys:libusb:002:005' is a Canon LiDE 60 flatbed scanner
> 
> 
> - The
> scanner works over the network, my 2nd laptop is a Dell E6440 running
> Debian Buster
> hr at e6440:~$ scanimage -L
> device
> `net:192.168.168.245:genesys:libusb:002:005' is a Canon LiDE 60
> flatbed
> scanner
> 
> 
> - This is my udev-rule in /usr/lib/udev/rules.d
> 
> less 90-
> scanner.rules
> 
> # change device file permission to group scanner for sane
> access
> ATTRS{idVendor}=="04a9", ATTRS{idProduct}=="221c",
> SUBSYSTEMS=="usb", ACTION=="add", MODE="0664", GROUP="scanner",
> SYMLINK+="MyLide60"
> 
> but this does not work - it creates no symlink in
> /dev
> 
> 
> 
> - This does work and is my udev-rule in /etc/udev/rules.d
> 
> less 83-
> scanner.rules
> 
> SUBSYSTEM=="usb", ATTR{product}=="CanoScan",
> ATTR{idProduct}=="221c", ATTR{idVendor}=="04a9", SYMLINK+="myLide60"
> GROUP+="scanner"
> 
> It creates a symlink in /dev/
> lrwxrwxrwx  1 root root   
> 15 Aug  6 18:18 myLide60 -> bus/usb/002/005
> 
> 
> It's hardly possilbe to
> document here all the links I visited during the last 5 days, but
> tere
> are Links that suggested to use
> hr at r60e:~$ sudo scanimage -d
> /dev/myLide60
> 
> which obv iously does not work, because a UNIX Device is
> not to be used within the backend systax.
> 
> A invocation like
> hr at r60e:~$
> sudo scanimage -d genesys:libusb:/dev/myLide60 results also in an
> error, though it was recommended in a forum blogpost by someone more
> or
> less savvy.
> 
> 
> The reason for this is, that I have some windows 10 clients
> in my network. 
> They can be used with sane-Scanning-Solution via NAPS2
> Scanning Software and the windows WIA-Sane driver 
> https://github.com/mback2k/wiasane/wiki/Downloads
> 
> But one need to
> configure the scanning device by hand. Unfortunatly the scanner will
> be
> assigned deviating USB Bus and Device numbers if the scanner is
> unplugged and replugged or if the scanserver is rebootet. You cannot
> rely on the persistence of USB bus/device number assignment.
> 
> That leads
> to the situation, that the users of the windows clients won't be able
> to scan at a certain day or hour noone can predict.
> To assign the then
> valid usb bus / device numbers, you'll have to reinstall the WIA-Sane
> driver each time it is necessary.
> 
> Therefore I'd like to have the option
> to configure the windows WIA Sane Driver to the symbolic link.
> 
> But until
> today this endeavour was not successful.
> 
> 
> Important to know: 
> SCSI-
> Scanners seem to behave other than USB-Scanners. 
> SCSI-Scanners for
> example may have a /dev/sg1, which is a UNIX-Device.
> For SCSI-Scanners
> the symlink may work. I unfortunatly cannot try this out, but several
> postings do claim that.
> 
> 
> I am now looking for a method to get a
> persistent USB device enumeration for my scanner.
> 
> A already tried the
> ALIASES option via dll.aliases.
> 
> I wrote this script, which updates the
> dll.aliases in /dev/sane.d
> 
> -----
> #!/bin/bash
> 
> ALIASFILE=/etc/sane.d/dll.ali
> ases
> 
> lsusb | grep LiDE | awk '{ print "alias MyLiDE
> genesys:libusb:"$2":"$4}' | sed 's/.$//' > $ALIASFILE
> -----
>  
> The scanner
> then is recognised by its alias, but the windows clients cannot make
> use of it.
> All that the windows WIA Sane Driver sees by autotetection is
> the genesys:libusb:002:005 which I can select as only Option during
> WIA-Sane Setup.
> 
> 
> 
> This is the long version, perhaps you have ideas how I
> should proceed.
> 
> THX,
> Heinz
> 
> 
> 
> 
> 
> Am Freitag, den 06.08.2021, 07:43 -0700 schrieb Ralph Little:
> > Hi,
> > 
> > On 2021-08-04 1:44 p.m., Heinz Rohde via sane-devel wrote:
> > > Hello,
> > > 
> > > I created a symlink via udev rule calles MyScanner and points to
> > > /dev/bus/001/002 (for example)
> > > 
> > > I cannot get genesys to use this link, or in other words,
> > > scanimage
> > > -d
> > > /dev/MyScanner resukts in an error.
> > > 
> > The argument to -d is not a device file in the Unix sense, it is a 
> > backend-specific string. The format of that string is determined by
> > the 
> > backend itself and can vary widely.
> > This is because backends can provide services that are not from a
> > local 
> > device, such as the many devices that can be accessed through
> > ethernet 
> > or WiFi. Another example would be the test backend which is not 
> > associated with any backend. For the test backend, the device would
> > be 
> > "test:0" or "test:1".
> > 
> > The common way to determine the device name is to run scanimage -L
> > which 
> > will probe for available devices and list them out.
> > 
> > Can you tell us which model of device you are trying to scan from?
> > 
> > Cheers,
> > Ralph
> > 





More information about the sane-devel mailing list