This project has moved and is read-only. For the latest updates, please go here.

Saraff.Twain.TwainException It worked!

Apr 24, 2015 at 4:15 PM
Hello,

I am not sure about the actual reason for the Exception below. Could you please help me with it?

Saraff.Twain.TwainException It worked!
at Saraff.Twain.Twain32._GetAllSorces()
at Saraff.Twain.Twain32.OpenDSM()

When I use your library on my development machine there is no issues with OpenDSM() method. But when I tried it on a clean virtual machine I caught the error above.

Do you have any thoughts or suggestions about it?

Thanks in advance!

Regards,
Gennady
Apr 24, 2015 at 7:17 PM
Hello, GennadyBaranov.
For more info write value of the TwainException.ReturnCode.
Apr 27, 2015 at 7:44 AM
Edited Apr 28, 2015 at 2:45 PM
Hi Saraff,

ReturnCode = Failure.

By the way, I have tried your sample apps. They are also failing with the same error on virtual machine and working well on my development PC.


I think I was able to find out the reason. Please find my thoughts below:
  1. I have just installed drivers for my scanner to the virtual machine but have never attached device. So, I am getting the exception described in my previous post. The following lines from your library which are throwing exception(OpenDSM -> _GetAllSorces Method):
       for(TwRC _rc=this._dsmEntry.DsmInvoke(this._AppId,TwDG.Control,TwDAT.Identity,TwMSG.GetFirst,ref _item); _rc!=TwRC.Success&&_rc!=TwRC.EndOfList; ) {
            throw new TwainException(this._GetTwainStatus(),_rc);
        }
    
  2. After I have attached the device, the library works well. It shows 2 "devices" - my scanner and the same one but with WIA interface.
  3. Note, that If I detach device it also works well, shows me my scanner as offline device, so I can manage this situation. So, this error is observed only before first device attach.
So, the main question is this exception thrown in OpenDSM(_GetAllSorces) related to the driver manufacturer or Saraff.Twain.Net really throws such error when we try to initialize Data Source Manager but have not attached devices instead of just having empty sources collection? What do you think?


Thanks
Apr 28, 2015 at 6:21 PM
Hello, GennadyBaranov.
I think it's a problem of a TWAIN drivers (DSM), as:

DG_CONTROL / DAT_IDENTITY / MSG_GETFIRST

Call

DSM_Entry(pOrigin, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, pSourceIdentity);

Description

The application may obtain a list of all Sources that are currently available on the system which
match the application’s supported groups (DGs, that the application specified in the
SupportedGroups field of its TW_IDENTITY structure). To obtain the complete list of all available
Sources requires invocation of a series of operations. The first operation uses MSG_GETFIRST to
find the first Source on “the list” (whichever Source the Source Manager finds first). All the
following operations use DG_CONTROL / DAT_IDENTITY / MSG_GETNEXT to get the identity
information, one at a time, of all remaining Sources.
If the application wants to cause a specific Source to be opened, one whose ProductName the
application knows, it must first establish the existence of the Source using the MSG_GETFIRST/
MSG_GETNEXT operations. Once the application has verified that the Source is available, it can
request that the Source Manager open the Source using DG_CONTROL / DAT_IDENTITY /
MSG_OPENDS. The application must not execute this operation without first verifying the
existence of the Source because the results may be unpredictable.

Return Codes

TWRC_SUCCESS
TWRC_FAILURE
    TWCC_NODS /* No Sources can be found */
    TWCC_LOWMEMORY /* Not enough memory to perform this operation */
7-62 TWAIN 2.2 Specification
Marked as answer by SARAFF on 5/6/2015 at 11:30 AM