UNIX / Linux keyboard.

How to Fix the "invalid argument" Error with Sane and XSane

Errors with sane, xsane, and scanimage

You try to start using your scanner with xsane and all you get is a pop-up window with a cryptic message. Or you do some Google searching and find suggestions to use scanimage to first detect and list and to then test what it finds. But the second command produces this same vague error message about an "Invalid argument":

# scanimage -L
device `artec_eplus48u:libusb:009:005' is a Memorex MEM 48U flatbed scanner
# scanimage --test
Failed to open device 'artec_eplus48u:libusb:009:005': Invalid argument 

Here is how to fix the problem.

Find and verify the group associated with your scanner

Use the lsusb command to find your USB-connected scanner. Below is the relevant line of output on my system.

# lsusb
[... several lines deleted ...]
Bus 009 Device 005: ID 05d8:4005 Ultima Electronics Corp. MEM48U
[... several lines deleted ...] 

Notice the 3-digit bus and device numbers. Yours, of course, is probably different, and if I unplug mine and plug it back in again it will get a new device number. Change the bus and device numbers in the following example commands and output as appropriate for your system.

Verify that your scanner is group-writeable, and see which group is associated with its device. The devices for USB bus 009 are in /dev/bus/usb/009:

# ls -l /dev/bus/usb/009
total 0
crw-rw-r--  1 root root    189, 1024 Jul  1 16:02 001
crw-rw-r--  1 root root    189, 1025 Jul  1 16:02 002
crw-rw-r--+ 1 root scanner 189, 1028 Jul  1 16:18 005 

Notice the "+", indicating that the KDE display manager has set up some extended attributes for me. Let's see what they are:

# getfacl /dev/bus/usb/009/005
# file: dev/bus/usb/009/005
# owner: root
# group: scanner

It looks like I already have read/write access to the device! So I would not really need to add myself to the scanner group as shown below, but there's no harm in also doing that.

Add your user(s) to group scanner

You can do this with the usermod command, or simply by editing /etc/group. Add your user to the group associated with the detected scanner device, change scanner if necessary to lp or whatever group you saw in the ls output.

Note: you must log off and log back on for the change to take full effect. Run the id command and verify that you are now in the appropriate group.

Verify Your Sane Configuration

Notice that you have a set of files in /etc/sane.d named for the different models. I have a low-end USB scanner branded as Memorex on the cover and as Memorex MEM48U on the bottom of its case, but it was reported in the lsusb output as Ultima Electronics Corporation.

# lsusb
[... several lines deleted ...]
Bus 009 Device 005: ID 05d8:4005 Ultima Electronics Corp. MEM48U
[... several lines deleted ...] 

Notice the two hexadecimal strings: 05d8:4005. Those are manufacturer and product codes. Let's see if our system already knows what they mean:

# grep '05d8.*4005' /etc/sane.d/*.conf
/etc/sane.d/artec_eplus48u.conf:usb 0x05d8 0x4005 

Ahah! It's really from Artec, an E+ 48U scanner.

Look through its configuration file, you will see the comment "This scanner is also sold as Tevion MD 9693, Medion MD 9705, Medion MD 9693, Medion MD4394" regarding a product ID of 0x4003, and then "Since the Trust Easy Webscan 19200 uses a different product id, we add another usb section here" for product ID 0x4006", then that 0x4005 means a Memorex Mem48U, 0x4007 means Trust 240H Easy Webscan Gold, 0x4009 means UMAX AstraSlim SE, 0x4004 means Artec E+ Pro, 0x4010 means UMAX AstraSlim 1200 SE, and 0x4011 means Yakumo Scan50.

Notice that each stanza has a line like the following:

option artecFirmwareFile /usr/share/sane/artec_eplus48u/Artec48.usb 

Add the Needed Firmware File

Do you have that file? If you have the file but you are still getting the "invalid argument" error message, verify the ownership and permissions. Maybe you need to make it readable by at least group scanner if not the world.

If you are still puzzled because you have the file and it seems to be readable, you might try running scanimage through strace and verifying what is getting in the way. Who can predict all the things that might go wrong, possibly SELinux is getting in the way.

But most likely the problem is that the file is not there, you need to add it.

Ask yum to tell you which package provides that file:

# yum provides /usr/share/sane/artec_eplus48u/Artec48.usb 

Or, on Mageia or another urpm* based system, use urpmf:

# urpmf /usr/share/sane/artec_eplus48u/Artec48.usb 

If your distribution does not include this firmware file, don't panic. As long as you can track down the file, you can add it. Create the needed subdirectory under /usr/share/sane, download the file, extract it from a zip package if that's how it came, put it in the right place, and make it owned by root and world-readable. If you have the same model of scanner, use one of the following. If not, search for the firmware file for what you do have through Google.