twain / twain-cs

A C# interface for TWAIN
172 stars 67 forks source link

Can't use scanner from demo app #41

Open Dialecticus opened 4 years ago

Dialecticus commented 4 years ago

Can't use demo project for scanning. Windows Scan from Micorosft Store and Twacker can use my HP LJ M1530 Scan scanner/printer, but TWAINCSScan produces log file below. Driver's GUI is shown, and I can initiate scanning, but when I click on Done (in driver's GUI) method NativeMethods.WindowsTwaindsmDsmEntryUserinterface returns FAILURE. Help..

000000 172336076056 S1 T00000001 V. ts:2020-06-09 17:23:36.078050 os:windows
000001 172336079050 S1 T00000001 V. TWAINCSScan v2.4.10.0
000002 172337448199 S1 T00000001 V. 
000003 172337449196 S1 T00000001 V. twn> DG_CONTROL/DAT_PARENT/MSG_OPENDSM
000004 172337507043 S1 T00000001 V. twn> SUCCESS
000005 172337510035 S3 T00000001 V. 
000006 172337511032 S3 T00000001 V. twn> DG_CONTROL/DAT_IDENTITY/MSG_GETDEFAULT
000007 172337514025 S3 T00000001 V. twn> 2,1,0,ENG,USA,1.0,1,9,0x3,Hewlett-Packard,HP LJ M1530 Scan,HP LJ M1530 Scan TWAIN
000008 172337515022 S3 T00000001 V. twn> SUCCESS
000009 172337515022 S3 T00000001 V. 
000010 172337516020 S3 T00000001 V. twn> DG_CONTROL/DAT_IDENTITY/MSG_GETFIRST
000011 172337516020 S3 T00000001 V. twn> 1,6,4,ENGLISH_USA,USA,6.4.63.22930,2,2,0x40000003,EPSON,EPSON Scan 2,EPSON DS-310
000012 172337517015 S3 T00000001 V. twn> SUCCESS
000013 172337517015 S3 T00000001 V. 
000014 172337518013 S3 T00000001 V. twn> DG_CONTROL/DAT_IDENTITY/MSG_GETNEXT
000015 172337518013 S3 T00000001 V. twn> 2,1,0,ENG,USA,1.0,1,9,0x3,Hewlett-Packard,HP LJ M1530 Scan,HP LJ M1530 Scan TWAIN
000016 172337518013 S3 T00000001 V. twn> SUCCESS
000017 172337519011 S3 T00000001 V. 
000018 172337519011 S3 T00000001 V. twn> DG_CONTROL/DAT_IDENTITY/MSG_GETNEXT
000019 172337519011 S3 T00000001 V. twn> 2,1,0,ENG,USA,1.0,1,9,0x3,Hewlett-Packard,HP LJ M1530 Scan,HP LJ M1530 Scan TWAIN
000020 172337520008 S3 T00000001 V. twn> ENDOFLIST
000021 172338855683 S3 T00000001 V. 
000022 172338856681 S3 T00000001 V. twn> DG_CONTROL/DAT_IDENTITY/MSG_SET
000023 172338856681 S3 T00000001 V. twn> 2,1,0,ENG,USA,1.0,1,9,0x3,Hewlett-Packard,HP LJ M1530 Scan,HP LJ M1530 Scan TWAIN
000024 172338857678 S3 T00000001 V. twn> SUCCESS
000025 172338857678 S3 T00000001 V. 
000026 172338857678 S3 T00000001 V. twn> DG_CONTROL/DAT_IDENTITY/MSG_OPENDS
000027 172338858675 S3 T00000001 V. twn> 2,1,0,ENG,USA,1.0,1,9,0x3,Hewlett-Packard,HP LJ M1530 Scan,HP LJ M1530 Scan TWAIN
000028 172339066123 S3 T00000001 V. twn> 2,1,0,ENG,USA,1.0,1,9,0x3,Hewlett-Packard,HP LJ M1530 Scan,HP LJ M1530 Scan TWAIN
000029 172339066123 S3 T00000001 V. twn> SUCCESS
000030 172339092053 S4 T00000001 V. 
000031 172339093097 S4 T00000001 V. twn> DG_CONTROL/DAT_CAPABILITY/MSG_SET
000032 172339093097 S4 T00000001 V. twn> ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,TWSX_MEMORY
000033 172339094048 S4 T00000001 V. twn> ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,TWSX_MEMORY
000034 172339095047 S4 T00000001 V. twn> SUCCESS
000035 172339096086 S4 T00000001 V. 
000036 172339097040 S4 T00000001 V. twn> DG_CONTROL/DAT_CAPABILITY/MSG_SET
000037 172339097040 S4 T00000001 V. twn> CAP_INDICATORS,TWON_ONEVALUE,TWTY_BOOL,TRUE
000038 172339098038 S4 T00000001 V. twn> CAP_INDICATORS,TWON_ONEVALUE,TWTY_BOOL,TRUE
000039 172339098038 S4 T00000001 V. twn> SUCCESS
000040 172339162863 S4 T00000001 V. 
000041 172339163862 S4 T00000001 V. twn> DG_CONTROL/DAT_CAPABILITY/MSG_GETCURRENT
000042 172339163862 S4 T00000001 V. twn> CAP_CUSTOMDSDATA,0,0
000043 172340755155 S4 T00000001 V. twn> FAILURE/CAPUNSUPPORTED
000044 172349683575 S4 T00000001 V. 
000045 172349684573 S4 T00000001 V. twn> DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS
000046 172349684573 S4 T00000001 V. twn> TRUE,FALSE,1443224
000047 172408083210 S4 T00000001 V. twn> FAILURE/65536
mlmcl62 commented 4 years ago

Hi. I've looked at the log and the code. I temporarily modified the code to force a value of TRUE for ShowUI, because that code path isn't regularly tested (if a scanner supports DAT_CUSTOMDSDATA it's not needed).

As noted the call to DAT_USERINTERFACE is returning TWRC_FAILURE. It's also not filling in the condition code, returning a value of 65536. The fact that it takes the driver 11 seconds to return the error seems like a long time.

I'm afraid that this is going to be on the driver behaving badly. However, it may be worth trying something. The twaincstst program has a checkbox that switches it to use the old TWAIN_32.DLL. I have yet to run into a driver that has a problem with TWAINDSM.DLL, but there's a first time for everything. You should be able to run that program, select the legacy DSM, and then click your way through the 'Send' button. When you see your scanner listed in the bottom text window change to DG_CONTROL / DAT_IDENTITY / MSG_OPENDS, and Send to open it. When it's open change to DG_CONTROL / DAT_USERINTERFACE / MSG_ENABLEDS and enter TRUE,FALSE,0 in the window on the right, and Send to bring the user interface up.

If the call still returns TWRC_FAILURE, then I'm not sure I have any other ideas. You could try contacting the scanner vendor to see if they can help. If that does work, let me know, and I can make a change to the app that'll let you select the DSM to use.

Dialecticus commented 4 years ago

I think the legacy driver is the key. The user interface is not up in twaincstst after the steps below, but I can complete the scan in twaincsscan when I replace false with true in twaincsscan\source\FormScan.cs(104). The scan is slanted at 45 degrees, though, but that's a different issue I guess.

DG_CONTROL/DAT_PARENT/MSG_OPENDSM: SUCCESS
527106

DG_CONTROL/DAT_IDENTITY/MSG_GETFIRST: SUCCESS
146,1,0,ENG,USA,1.0,1,9,0x3,Hewlett-Packard,HP LJ M1530 Scan,HP LJ M1530 Scan TWAIN

DG_CONTROL/DAT_USERINTERFACE/MSG_ENABLEDS: BADDEST
TRUE,FALSE,0