Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with DTWAIN_AcquireFile and DTWAIN_IsUIControllable #53

Closed
rokoduran opened this issue Apr 18, 2023 · 5 comments
Closed

Issue with DTWAIN_AcquireFile and DTWAIN_IsUIControllable #53

rokoduran opened this issue Apr 18, 2023 · 5 comments

Comments

@rokoduran
Copy link

rokoduran commented Apr 18, 2023

Hello there,

I am currently trying to perform a file acquisition:

int status = 0;
// Begin file acquisition
var uiFlag = TwainAPI.DTWAIN_IsUIControllable(_selectedSource); 

var success = TwainAPI.DTWAIN_AcquireFile(_selectedSource, "placeholder." + foundType.fType, foundType.DTWAINType, 
    TwainAPI.DTWAIN_USENATIVE | TwainAPI.DTWAIN_USELONGNAME, TwainAPI.DTWAIN_PT_DEFAULT, 
    TwainAPI.DTWAIN_ACQUIREALL, 0, 1, ref status);
if (status == 0)
{
    throw new Exception("File acquisition failed!");
}

This code acquires properly with a status of 1000 only and ONLY if I set ShowExceptions = 1 for DTWAIN logging and it shows an exception upon calling DTWAIN_IsUIControllable.

image
(No idea what this nullptr error refers to, the source and the DTWAIN states are all properly set up at this point)

If I don't call DTWAIN_IsUIControllable or turn ShowExceptions to 0, the acquisition status instantly goes to 1002 / acquisition cancelled.

The C# DTwain demo acquires successfully for the same driver. (also using the exact same AcquireFile parameters and setup)

@dynarithmic
Copy link
Owner

dynarithmic commented Apr 18, 2023

Can you produce a full TWAIN log? The DTWAIN_IsUIControllable is equivalent to calling DTWAIN_GetCapValues using the CAP_UICONTROLLABLE capability:

DTWAIN_ARRAY a;
TwainAPI.DTWAIN_GetCapValues(source, CAP_UICONTROLLABLE, DTWAIN_CAPGET, ref a);

This operation should never fail if the TWAIN source is compliant.

From here, it looks like this function failed for some reason, but shouldn't fail given that this capability has to be supported by the TWAIN driver.

@dynarithmic
Copy link
Owner

Right now, no check is done on the internal code to check if DTWAIN_GetCapValues fails for this call, so I will put the check in there. But again, this should never fail, unless there is an underlying problem with the driver.

@dynarithmic
Copy link
Owner

dynarithmic commented Apr 19, 2023

I made a change to check for the failure of DTWAIN_IsUIControllable in the development-32bit and development-64bit branches.

The change only checks for failure and probably prevents the exception being thrown, but it would be better to get a TWAIN log to see the failure actually get detected by the TWAIN DSM and driver. As mentioned in the previous comment, this failure should never occur if the TWAIN driver is compliant as of TWAIN 1.6 and above.

@rokoduran
Copy link
Author

rokoduran commented Apr 19, 2023

Hi again!
First of all, thank you so much for the quick responses.

I did some snooping around and found an older issue with near identical scenario as mine, barring the UIControllable: #46

I forgot to mention that the driver in mind was indeed a WIA driver, but I gave it no heed considering it worked in the demo.
By using

[SourceXferWaitInfo]
WIA-* = 1000

in the dtwain32.ini and using the dtwain32u.dll from the experimental branch you mentioned in that issue, my problem was solved and I can now use the WIA driver in my project.

BTW,
Regarding the IsUIControllable issue, I tried using the bins from the updated dev branch - the exception is now gone but I still can't use the driver (remember that the driver only worked if the exception was shown, presumably because it causes a stall, similiar to the waiting now done due to the .ini).

For all intents and purposes you can consider this solved, unless you still want to see the log/ more info?

Thank you again

@dynarithmic
Copy link
Owner

I will keep the issue open until the 5.3.0.4 version of DTWAIN is released.

It looks like the stock WIA-Twain bridge is broken, much more than it was in the past. So I guess the workaround for a WIA based driver when using it for TWAIN access is for the application to make a choice between using or not using the UI when accessing the scanner without help from DTWAIN_IsUIControllable().

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

No branches or pull requests

2 participants