dynarithmic / twain_library

Dynarithmic TWAIN Library, Version 5.x
Apache License 2.0
56 stars 24 forks source link

Various duplex scanning issues (scanning session is stuck after scanning a set of pages). #81

Open dynarithmic opened 9 months ago

dynarithmic commented 9 months ago

There is currently an issue with duplex scanning that has been discovered.

  1. If DTWAIN_EnableDuplex is not called by the application, however the scanner user-interface allows duplex scanning, the scanning session may hang after scanning the pages if duplex scanning is chosen by the user.
  2. If DTWAIN_EnableDuplex is called, but the call to the DTWAIN_Acquire... function specifies a set number of sheets of paper instead of DTWAIN_ACQUIREALL, the scanning session may hang after scanning the pages.

For 1., DTWAIN currently expects the application to know beforehand if duplex scanning is done, and thus the application calls DTWAIN_EnableDuplex accordingly. However this will not work if the scanner user interface is allowed to change from simplex scanning to duplex scanning after the scanner user-interface is displayed.

For 2., a workaround is to either specify DTWAIN_ACQUIREALL when scanning duplex, or double the number of images that will be acquired (for example, if you want to scan just 2 pages, the number of images to acquire in the DTWAIN_Acquire... call should be 4, for 3 pages, it would be 6, etc.)

Both items will be addressed in the next version of DTWAIN. Please note that for item 2, if you choose the workaround of doubling the number of pages instead of choosing DTWAIN_ACQUIREALL, this may need to be reverted back to the actual number of pages in your application for DTWAIN versions greater than 5.4.2. At this moment, it won't be determined if this will be necessary or not.

dynarithmic commented 9 months ago

Looking deeper into the issue, here are the scenarios when scanning in duplex mode:

For UI mode

If the device user-interface (UI) is shown, then aspects of the device such as using the duplexer cannot be controlled by the application, since the user is controlling the device using the various options in the UI. For example, if the UI is enabled and the user chooses to scan using duplex, there is no way for the programmer to intervene and set the scanner to simplex.

If the UI is enabled, it is best for the application to always expect a call to DTWAIN_EnableDuplex to be ignored if the UI itself has the option of selecting the duplex unit. Thus it is best to make sure that the NumPages parameter is set to DTWAIN_ACQUIREALL (or a high enough value) so as to cover all the pages that will be scanned in the call to DTWAIN_AcquireFile, DTWAIN_AcquireNative, etc.

For non-UI mode

When not showing the UI, the programmer has complete control (assuming there are no bugs in the device's TWAIN driver) whether to scan duplex, the number of pages to scan, etc. It is expected that the programmer sets every aspect of the scanning session correctly.

The current issue with non-UI mode and duplex is if there are more pages in the feeder than pages specified in the DTWAIN_Acquire... function call, the duplex scanning can get "stuck", with the TWAIN session hanging on the last page that was scanned.

There is a discrepancy in the number of pages and the actual number of images when scanning duplex, and this is not clearly outlined as to what the parameter value should be in the set of DTWAIN_Acquire... function calls that sets the number of pages to acquire.

For example, the NumPages parameter to the call to DTWAIN_AcquireFile specifies the number of pages, however this should be the number of images, not pages, if scanning duplex.

Thus_ for the meantime, please use DTWAIN_ACQUIREALL as the number of pages to scan until this is addressed.