Automatic document feeder with hpaio backend

35 views
Skip to first unread message

Danilo Câmara

unread,
Sep 29, 2014, 3:01:28 PM9/29/14
to jfreesan...@googlegroups.com
I'm trying to scan from the ADF with hpaio backend using the latest source from the truncated_image_hack branch. The test case code is:

import java.io.IOException;
import java.net.InetAddress;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

import au.com.southsky.jfreesane.SaneDevice;
import au.com.southsky.jfreesane.SaneException;
import au.com.southsky.jfreesane.SaneSession;
import au.com.southsky.jfreesane.SaneStatus;

public class Test {

   
private static final Logger myLogger = Logger.getLogger("au.com.southsky.jfreesane");

   
public static void main(String[] args) throws IOException, SaneException {
       
// Turn up logging levels
       
for (Handler handler : Logger.getLogger("").getHandlers()) {
            handler
.setLevel(Level.FINE);
       
}
        myLogger
.setLevel(Level.FINE);

       
SaneSession session = null;
       
SaneDevice device = null;
       
try {
           
InetAddress address = InetAddress.getByName("localhost");
            session
= SaneSession.withRemoteSane(address);

            device
= session.getDevice("hpaio:/usb/Deskjet_4620_series?serial=CN582736YP47TN");

            device
.open();

            device
.getOption("source").setStringValue("ADF");     // [Flatbed], ADF
            device
.getOption("mode").setStringValue("Color");     // [Lineart], Gray, Color
            device
.getOption("resolution").setIntegerValue(200);  // 100, 200, 300, 600 (75)

           
while (true) {
               
try {
                    device
.acquireImage();

               
} catch (SaneException e) {
                   
if (e.getStatus() == SaneStatus.STATUS_NO_DOCS) {
                       
// this is the out of paper condition that we expect
                       
break;
                   
} else {
                       
// some other exception that was not expected
                       
throw e;
                   
}
               
}
           
}

       
} finally {
           
if (device != null) try { device.close(); } catch (IOException e) { e.printStackTrace(); }
           
if (session != null) try { session.close(); } catch (IOException e) { e.printStackTrace(); }
       
}
   
}
}

The output ends with:
...
FINE
: Reached end of records
Sep 29, 2014 2:38:50 PM au.com.southsky.jfreesane.FrameInputStream readFrame
WARNING
: truncated read (got 11,674,368, expected 14,187,600 bytes)
Sep 29, 2014 2:38:50 PM au.com.southsky.jfreesane.FrameInputStream readFrame
WARNING
: padded image with 2,513,232 null bytes
Exception in thread "main" au.com.southsky.jfreesane.SaneException: STATUS_DEVICE_BUSY
    at au
.com.southsky.jfreesane.SaneSession.acquireImage(SaneSession.java:134)
    at au
.com.southsky.jfreesane.SaneDevice.acquireImage(SaneDevice.java:91)
    at
Test.main(Test.java:39)
ABRT problem creation
: 'success'

Maybe the STATUS_DEVICE_BUSY happens because the scanner is loading/ejecting the next pages in the ADF.

I try set A4 paper size (0, 0)->(210, 297). The padding reduced to 168,606 bytes and the exception was thrown. I could not find a size near A4 that didn't cause padding. The size (0, 0)->(130, 185) didn't cause padding but the exception happened anyway.

The full log is attached.

Regards
Test.log
saned.log

Danilo Câmara

unread,
Sep 29, 2014, 3:10:59 PM9/29/14
to jfreesan...@googlegroups.com
If I try to wait after the first image is acquired, the next pages are ejected.

James Ring

unread,
Sep 29, 2014, 3:20:18 PM9/29/14
to Danilo Câmara, jfreesane-discuss

I suspect there may be a spurious call to cancel() in there, will take a look when I get home. I'm going to add better logging in the process!

sent from my phone

On Sep 29, 2014 12:11 PM, "Danilo Câmara" <dfca...@gmail.com> wrote:
If I try to wait after the first image is acquired, the next pages are ejected.

--
You received this message because you are subscribed to the Google Groups "jfreesane-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jfreesane-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Ring

unread,
Sep 29, 2014, 3:49:56 PM9/29/14
to Danilo Câmara, jfreesane-discuss
Does it work with scanadf?

On Mon, Sep 29, 2014 at 12:10 PM, Danilo Câmara <dfca...@gmail.com> wrote:
> If I try to wait after the first image is acquired, the next pages are
> ejected.
>

Danilo Câmara

unread,
Sep 29, 2014, 5:32:18 PM9/29/14
to jfreesan...@googlegroups.com, dfca...@gmail.com
scanadf works

James Ring

unread,
Sep 30, 2014, 4:23:56 PM9/30/14
to Danilo Câmara, jfreesane-discuss
Can you try commenting out line 181 of SaneSession.java:

cancelDevice(handle);

And see if that works?

Danilo Câmara

unread,
Sep 30, 2014, 6:14:47 PM9/30/14
to jfreesan...@googlegroups.com, dfca...@gmail.com
Yes, it works.

Thank you very much.

James Ring

unread,
Sep 30, 2014, 6:16:32 PM9/30/14
to Danilo Câmara, jfreesane-discuss
Ok, it confirms my suspicion that we're sending sane_cancel at the
wrong time. Unfortunately it's not a quick fix, I'll have to sit down
and think about how to do it better. Referring to
http://www.sane-project.org/html/doc013.html, I think we need to keep
track of whether the device is in setup or image acquisition mode.
When in acquisition mode, any action taken by the user other than
acquireImage should cause cancel() to be sent first.
Reply all
Reply to author
Forward
0 new messages