[sane-devel] Looking to add support for Avision AV50F plus scanner

Ove Laurum laurum.tech at gmail.com
Wed Sep 4 18:11:01 BST 2024


Thanks Ralph,

I found the code on GitLab. Very useful.

I also managed to add my scanner to the config file /etc/sane.d/avision.conf
usb 0x0638 0x2b6a

I didn't get much of a trace out until I ran it as root, see abbreviated
output below
SANE_DEBUG_AVISION=100 scanimage -L
(I don't think I can use the -d option unless the device is listed with
"scanimage -L")

When I do:
SANE_DEBUG_AVISION=50 sane-find-scanner
I get no trace, is that because the backend is not involved at this stage?

In the trace that I did get, it looks like the backend is opening the
correct device "libusb:001:003" and tries a first command which is
"Inquiry".
It builds the query and tries to write it but fails with error code 9.

I am running the command as root (not as sudo) so it should not be a
permissions issue unless the backend is run by a different user.
If I run as an unprivileged user then I do not even get this far. In that
case it tries to access the scanner but fails and is not even getting to
the stage of Attaching to the scanner.
Also worth noting is that my Canon LiDE220 works fine with sane, which is
another indicator that it is unlikely a permissions issue.

So based on the trace and on the source code it looks like it is:

   - Attaching to the scanner.
   - SANE_Status = SANE_STATUS_GOOD in reply to sanei_usb_open
   - starts building an inquiry
   - tries to send the inquiry
   - fails to do sanei_usb_write_bulk
   - sanei_usb.c responds with error

How can I see log entries from sanei_usb.c code?


That is it for tonight, I will sleep on it... Usually helps.

Any thoughts or observations are always welcome.

Tomorrow I will try to hook up wireshark to see what is actually being sent
on Linux and compare with Windows.

Thanks for all the help so far.

Kind regards Ove.

trace below:

The key lines of the SANE_DEBUG_AVISION=100 scanimage -L trace were:
sane_init:(Version: 1.0 Build: 297)
sane_reload_devices: parsing config line "usb 0x0638 0x2b6a"
sane_reload_devices: config file line 23: trying to attach USB:`usb 0x0638
0x2b6a'
attach:
attach: opening libusb:001:003
inquiry: length: 96
inquiry: inquiring ...
avision_cmd: Inquiry
filling command to have a length of 10, was: 6
Timeouts: write: 30000, read: 1000, status: 1000
try to write cmd, count: 10.
wrote 0 bytes
=== got error 9 trying to write, wrote: 0 ===
try to read status to clear the FIFO
avision_usb_status: timeout 500, 1 retries
==> (bulk read) going down ...
<== (bulk read) got: 0, status: 0
==> (interrupt read) going down ...
<== (interrupt read) got: 0, status: 0
=== got error 9 trying to read status. ===
inquiry: inquiry failed (Error during device I/O)
inquiry: inquiring ...
avision_cmd: Inquiry
filling command to have a length of 10, was: 6
Timeouts: write: 30000, read: 1000, status: 1000
try to write cmd, count: 10.
wrote 0 bytes
=== got error 9 trying to write, wrote: 0 ===
try to read status to clear the FIFO
avision_usb_status: timeout 500, 1 retries
==> (bulk read) going down ...
<== (bulk read) got: 0, status: 0
==> (interrupt read) going down ...
<== (interrupt read) got: 0, status: 0
=== got error 9 trying to read status. ===
inquiry: inquiry failed (Error during device I/O)
attach: 1st inquiry failed (Error during device I/O)
sane_get_devices:
sane_reload_devices: parsing config line "usb 0x0638 0x2b6a"
sane_reload_devices: config file line 23: trying to attach USB:`usb 0x0638
0x2b6a'
attach:
attach: opening libusb:001:003
attach: open failed (Invalid argument)




On Wed, 4 Sept 2024 at 15:13, Ralph Little <skelband at gmail.com> wrote:

> Hi,
>
> On Wed, Sep 4, 2024 at 6:28 AM Ove Laurum <laurum.tech at gmail.com> wrote:
>
>> Hello and thanks for your responses.
>>
>> The effort does not dissuade me, it will have to take the time it takes,
>> in the meantime I will just have to retain a windows VM for using the
>> scanner.
>> ...
>> Ralph, I was trying to find where the source code is, GIT hub? or
>> somewhere else? so that I can take a look at the code for some examples of
>> backends. I assume it's written in C.
>> I found
>> https://www.commandlinux.com/man-page/man-page/man-page/man5/sane-avision.5.html
>>
>> So I will start there trying to figure out how to read logs for the
>> scanner as per your suggestion.
>>
>>
> The SANE project is hosted at Gitlab, and you can find the source and
> currently reported issues here: https://gitlab.com/sane-project/backends
> The main website is here: http://www.sane-project.org/
>
> The SANE code is divided up into two main repositories: backends and
> frontends. You will find the backends contain all the code required to talk
> to scanners.
> Best way to start is to clone the backends repository and build it. On
> Linux, building is fairly straightforward and there are instructions in the
> INSTALL file.
>
> If you wish to generate a log file from a backend, each backenc man page
> does indeed contain instructions, but broadly each backend has its own
> environment variable that can be used to get debug messages at various
> numerical levels. One example might be:
>
> SANE_DEBUG_AVISION=50 scanimage -d {your device} {other parameters etc}
>
> Consult the man page (man sane-avision) for details as to what level of
> diag corresponds to which number.
>
> Personally, I would start with the avision backend. Many Avision devices
> use the protocol that is supported by that backend but it is not guaranteed
> in your case.
> The backends are designed to support specific protocols and often these
> protocols are shared amongst different manufacturers. Some scanners use
> scanner-on-a-chip hardware (for example from Genesys) so a backend may
> support a wide range of devices from different manufacturers. In other
> cases, they are more manufacturer specific (like Canon with the pixma
> backend for example).
>
>
>> The other thing I will have to do is to trace a successful scan operation
>> on Windows.
>> My goto tracer would be wireshark, I know I can trace USB ports in Linux
>> so I assume that is possible on Windows as well to get a trace of
>> successful scanning.
>> But is there a better tool to trace the USB traffic on Windows for the
>> purpose of establishing some form of API?
>>
>>
> Yes, we would usually do a scan on Windows and capture it using Wireshark.
> I don't know of any particular analysis tools that could help you here. The
> ones I have looked at I tend to print out and mark out with pen. Pretty old
> school. If this device is supported by the avision backend, then I would
> suspect that initial communications are pretty generic and get a little
> more specific later on. On communications that I have seen, the early USB
> exchanges establish the devices type and capabilities. The result of this
> early exchange is output in the diag stream so would be a good place to
> start.
>
> I don't know the backend very well, but I probably would start with the
> sane-avision man page and look into how to add the USB ids of your device
> to the backend's code or config file and just give it a try, capturing some
> detailed diag output. I would then study a trace gotten from a Windows scan
> to see how to go from there. If you are stuck at this point, I can spend a
> little time reminding myself how that backend works and help you out.
>
> There is a bit of a steep learning curve and each backend has its own way
> of doing things. Different scanners can have a completely different way of
> working, some are fairly high level like avision and pixma, while others
> are very low-level like genesys or rts8891.
>
> Cheers,
> Ralph
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/sane-devel/attachments/20240904/3ec433c9/attachment.htm>


More information about the sane-devel mailing list