sjamesr / jfreesane

Java API to talk to the SANE scanning daemon
Apache License 2.0
60 stars 25 forks source link

Touching a SaneOption while cycling #107

Closed jurivrljicak closed 3 years ago

jurivrljicak commented 3 years ago

Hi, I have a question.

Given

device.getOption("source").setStringValue("Automatic Document Feeder");

while (true) {
  try {
    BufferedImage image = device.acquireImage();
    process(image);
  } 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;
    }
  }
}

I noticed that if process(image) involves touching a SaneOption (say a simple read stringValue) an exception in thrown (SaneStatus.STATUS_NO_DOCS). Am I right? Is this a bug or is this a desired behavior?

thanks

sjamesr commented 3 years ago

jfreesane is a client to the SANE server, so we can only support what SANE itself supports. The code flow in the SANE specification shows that options are set in the "device setup" phase.

I'm not an expert, but from what I can tell, the sane daemon effectively leaves it to the backend driver to deal with option handling. I would say that modifying options in the middle of a scan is unexpected and different drivers are free to behave in a manner they choose (including returning STATUS_NO_DOCS).

jurivrljicak commented 3 years ago

great, thanks!