<div dir="ltr">Thanks Ralph,<div><br></div><div>I found the code on GitLab. Very useful.<br><div><br></div><div>I also managed to add my scanner to the config file /etc/sane.d/avision.conf</div><div>usb 0x0638 0x2b6a<br></div><div><br></div><div>I didn't get much of a trace out until I ran it as root, see abbreviated output below</div><div>SANE_DEBUG_AVISION=100 scanimage -L<br></div><div>(I don't think I can use the -d option unless the device is listed with "scanimage -L")</div><div><br></div><div>When I do:</div><div>SANE_DEBUG_AVISION=50 sane-find-scanner</div><div>I get no trace, is that because the backend is not involved at this stage?</div><div><br></div><div>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".</div><div>It builds the query and tries to write it but fails with error code 9.</div><div><br></div><div>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.</div><div>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.</div><div>Also worth noting is that my Canon LiDE220 works fine with sane, which is another indicator that it is unlikely a permissions issue.<br></div><div><br></div><div>So based on the trace and on the source code it looks like it is: </div><div><ul><li>Attaching to the scanner.</li><li><code>SANE_Status</code> = <code>SANE_STATUS_GOOD</code> in reply to <code>sanei_usb_open</code></li><li>starts building an inquiry</li><li>tries to send the inquiry</li><li>fails to do <code>sanei_usb_write_bulk</code></li><li>sanei_usb.c responds with error</li></ul></div><div>How can I see log entries from sanei_usb.c code?</div><div><br></div><div><br></div><div>That is it for tonight, I will sleep on it... Usually helps.</div><div><br></div><div>Any thoughts or observations are always welcome.</div><div><br></div><div>Tomorrow I will try to hook up wireshark to see what is actually being sent on Linux and compare with Windows.</div><div><br></div><div>Thanks for all the help so far.</div><div><br></div><div>Kind regards Ove.</div><div><br></div><div>trace below:</div><div><br></div><div>The key lines of the SANE_DEBUG_AVISION=100 scanimage -L trace were:</div><div>
        
        
        



<table cellspacing="0" border="0" style="font-family:"Liberation Sans";font-size:x-small">
        <colgroup width="687"></colgroup>
        <tbody><tr>
                <td height="17" align="left">sane_init:(Version: 1.0 Build: 297)</td>
        </tr>
        <tr>
                <td height="17" align="left" bgcolor="#FFFF00">sane_reload_devices: parsing config line "usb 0x0638 0x2b6a"</td>
        </tr>
        <tr>
                <td height="17" align="left" bgcolor="#FFFF00">sane_reload_devices: config file line 23: trying to attach USB:`usb 0x0638 0x2b6a'</td>
        </tr>
        <tr>
                <td height="17" align="left">attach:</td>
        </tr>
        <tr>
                <td height="17" align="left">attach: opening libusb:001:003</td>
        </tr>
        <tr>
                <td height="17" align="left">inquiry: length: 96</td>
        </tr>
        <tr>
                <td height="17" align="left">inquiry: inquiring ...</td>
        </tr>
        <tr>
                <td height="17" align="left">avision_cmd: Inquiry</td>
        </tr>
        <tr>
                <td height="17" align="left">filling command to have a length of 10, was: 6</td>
        </tr>
        <tr>
                <td height="17" align="left">Timeouts: write: 30000, read: 1000, status: 1000</td>
        </tr>
        <tr>
                <td height="17" align="left">try to write cmd, count: 10.</td>
        </tr>
        <tr>
                <td height="17" align="left">wrote 0 bytes</td>
        </tr>
        <tr>
                <td height="17" align="left">=== got error 9 trying to write, wrote: 0 ===</td>
        </tr>
        <tr>
                <td height="17" align="left">try to read status to clear the FIFO</td>
        </tr>
        <tr>
                <td height="17" align="left">avision_usb_status: timeout 500, 1 retries</td>
        </tr>
        <tr>
                <td height="17" align="left">==> (bulk read) going down ...</td>
        </tr>
        <tr>
                <td height="17" align="left"><== (bulk read) got: 0, status: 0</td>
        </tr>
        <tr>
                <td height="17" align="left">==> (interrupt read) going down ...</td>
        </tr>
        <tr>
                <td height="17" align="left"><== (interrupt read) got: 0, status: 0</td>
        </tr>
        <tr>
                <td height="17" align="left">=== got error 9 trying to read status. ===</td>
        </tr>
        <tr>
                <td height="17" align="left">inquiry: inquiry failed (Error during device I/O)</td>
        </tr>
        <tr>
                <td height="17" align="left">inquiry: inquiring ...</td>
        </tr>
        <tr>
                <td height="17" align="left">avision_cmd: Inquiry</td>
        </tr>
        <tr>
                <td height="17" align="left">filling command to have a length of 10, was: 6</td>
        </tr>
        <tr>
                <td height="17" align="left">Timeouts: write: 30000, read: 1000, status: 1000</td>
        </tr>
        <tr>
                <td height="17" align="left">try to write cmd, count: 10.</td>
        </tr>
        <tr>
                <td height="17" align="left">wrote 0 bytes</td>
        </tr>
        <tr>
                <td height="17" align="left">=== got error 9 trying to write, wrote: 0 ===</td>
        </tr>
        <tr>
                <td height="17" align="left">try to read status to clear the FIFO</td>
        </tr>
        <tr>
                <td height="17" align="left">avision_usb_status: timeout 500, 1 retries</td>
        </tr>
        <tr>
                <td height="17" align="left">==> (bulk read) going down ...</td>
        </tr>
        <tr>
                <td height="17" align="left"><== (bulk read) got: 0, status: 0</td>
        </tr>
        <tr>
                <td height="17" align="left">==> (interrupt read) going down ...</td>
        </tr>
        <tr>
                <td height="17" align="left"><== (interrupt read) got: 0, status: 0</td>
        </tr>
        <tr>
                <td height="17" align="left">=== got error 9 trying to read status. ===</td>
        </tr>
        <tr>
                <td height="17" align="left">inquiry: inquiry failed (Error during device I/O)</td>
        </tr>
        <tr>
                <td height="17" align="left">attach: 1st inquiry failed (Error during device I/O)</td>
        </tr>
        <tr>
                <td height="17" align="left">sane_get_devices:</td>
        </tr>
        <tr>
                <td height="17" align="left" bgcolor="#FFFF00">sane_reload_devices: parsing config line "usb 0x0638 0x2b6a"</td>
        </tr>
        <tr>
                <td height="17" align="left" bgcolor="#FFFF00">sane_reload_devices: config file line 23: trying to attach USB:`usb 0x0638 0x2b6a'</td>
        </tr>
        <tr>
                <td height="17" align="left">attach:</td>
        </tr>
        <tr>
                <td height="17" align="left">attach: opening libusb:001:003</td>
        </tr>
        <tr>
                <td height="17" align="left">attach: open failed (Invalid argument)<br><br><br><br></td>
        </tr>
</tbody></table></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 4 Sept 2024 at 15:13, Ralph Little <<a href="mailto:skelband@gmail.com">skelband@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 4, 2024 at 6:28 AM Ove Laurum <<a href="mailto:laurum.tech@gmail.com" target="_blank">laurum.tech@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello and thanks for your responses.<div><br></div><div>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.<br>...<br><div>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.<br></div><div>I found <a href="https://www.commandlinux.com/man-page/man-page/man-page/man5/sane-avision.5.html" target="_blank">https://www.commandlinux.com/man-page/man-page/man-page/man5/sane-avision.5.html</a> </div><div>So I will start there trying to figure out how to read logs for the scanner as per your suggestion.</div><div><br></div></div></div></blockquote><div><br></div><div>The SANE project is hosted at Gitlab, and you can find the source and currently reported issues here: <a href="https://gitlab.com/sane-project/backends" target="_blank">https://gitlab.com/sane-project/backends</a></div><div></div><div>The main website is here: <a href="http://www.sane-project.org/" target="_blank">http://www.sane-project.org/</a></div><div><br></div><div>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.</div><div>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.</div><div><br></div><div>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:</div><div><br></div><div>SANE_DEBUG_AVISION=50 scanimage -d {your device} {other parameters etc}</div><div><br></div><div>Consult the man page (man sane-avision) for details as to what level of diag corresponds to which number.</div><div><br></div><div>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.</div><div>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).</div><div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div></div><div>The other thing I will have to do is to trace a successful scan operation on Windows.</div><div><div>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.</div><div>But is there a better tool to trace the USB traffic on Windows for the purpose of establishing some form of API?</div></div><div><br></div></div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>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.<br></div><div><br></div><div>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.</div><div><br></div><div>Cheers,</div><div>Ralph<br></div></div></div>
</blockquote></div>