Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Error Opening Data Source #23

Open
sganihar opened this issue May 27, 2015 · 3 comments
Open

Error Opening Data Source #23

sganihar opened this issue May 27, 2015 · 3 comments

Comments

@sganihar
Copy link

Hi,

I faced an issue in "TestAppWpf", Saying "error opening data source". Following are the steps to reproduce the issue:

  1. Select scanner with "ShowTainUI = true" and start scan
  2. When Scanner settings screen displays say "Cancel",
  3. try to start the scan again error pop ups: Saying "error opening data source".

If user says cancel in any stage, it should cancel the job and should be ready to re scan.

Please let me know if there is any fix for this.

Thanks and Regards,
Saira

@sohaiby
Copy link

sohaiby commented Jun 12, 2017

I am encountering the same error but in a different manner. I select the scanner and starts the scan (regardless of the scan settings). But if there's no paper in the scanner, it still executes the StartScan and OpenSource method without any exception and shows no error message. If you click on the scan button again, it shows the "Error Opening Data Source" error.

@sohaiby
Copy link

sohaiby commented Jun 12, 2017

On debugging, I found that the condition in DataSource.cs file settings.AbortWhenNoPaperDetectable is always coming as false and hence the condition

if (settings.AbortWhenNoPaperDetectable && !PaperDetectable)
                throw new FeederEmptyException();

will never throw exception if there's no paper. Moreover, after throwing this error, it fails to close the datasource in the Close method as it tries to Disable the UI first which is returning false as TwainResult and hence it don't pass through the next if condition.
I did the following workaround to get it working

  1. Replace && with || in the following condition (Open()/DataSource.cs)
if (settings.AbortWhenNoPaperDetectable && !PaperDetectable)
                throw new FeederEmptyException();
  1. Remove the if condition in following statement (Close()/DataSource.cs)
if (result != TwainResult.Failure)
                {
                    result = Twain32Native.DsmIdentity(
                        _applicationId,
                        IntPtr.Zero,
                        DataGroup.Control,
                        DataArgumentType.Identity,
                        Message.CloseDS,
                        SourceId);
                }

@dbertolini
Copy link

@sohaiby you saved my day!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants