Loading...

Soft and hard errors scanning TWAIN sources

Support for GdTwain ActiveX and GdTwain Pro ActiveX/SDK.

Soft and hard errors scanning TWAIN sources

Postby guruross » Tue Jul 22, 2008 11:46 pm

Our company has just evaluated and licensed the GdPicture ActiveX control and related technologies. I am working on updating our product to use the GdPicture-based TWAIN interfaces in place of the previous 3rd party control (PajantImage). In doing this, I am getting some soft and hard errors.

I am working on an extended functionality Source Manager dialog and use the TwainGetSourceCount, TwainGetSourceName, TwainOpenSource, and TwainCloseSource methods to scan through all available sources, querying each one to determine what features it provides. I am encountering two issues with this.

After the first time I have opened, used the dialog, and closed it, subsequent instantiations have a TwainGetSourceCount of 0 (zero), preventing any listing of sources. The entire TWAIN interface appears to be relatively non-responsive, although the TwainGetState method returns the value of 3 (TWAIN_SM_OPEN) even though the Source Manager dialog was never opened.

On a related note, even just using the standard Source Manager (TwainSelectSource) to choose a source, then acquire and image (TwainAcquireToGdPictureImage) after which I close the image and source (CloseNativeImage and TwainCloseSource) leaves the TWAIN interface in the TWAIN_SM_OPEN state which it never returns from (even after an explicit TwainCloseSourceManager call), which prevents any further TWAIN interactions.

Worse, with the intial instantiation of the extended custom source manager dialog I am working on, as the loop opens and tests each source, I get hard crash errors the close my VB IDE when testing some methods on some sources. One example is the TwainGetAvailableXResolutions method when querying the Microsoft LifeCam source, though other sources can produce errors for simple boolean method tests (e.g. Logitech webcam that is intermittently accessed by webcam software - may be generating conflict?).

Any assistance on these issues and errors would be much appreciated.
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Soft and hard errors scanning TWAIN sources

Postby guruross » Wed Jul 23, 2008 1:24 am

Additional Information:

OS = Windows XP SP3
Dev = Visual Basic 6.0 SP6
GdPicture = 5.5.0.3
GdTWAIN = 4.2.0.8
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Soft and hard errors scanning TWAIN sources

Postby Loïc » Wed Jul 23, 2008 11:25 am

Hi,

It is hard to help you on these subjects without getting some code snippets you are using.

Please, for each of your problems do the following steps:

- Create a small isolated code which raise the behavior and give the description of this behavior
- Wrap this code into the TwainLogStart() & TwainLogStop() methods and give me the log file content (if it is too long, send it to esupport (at) gdpicture (dot) com)

ie:

Code: Select all
imaging1.TwainLogStart("behaviourN.log")

code which raise behaviourN

imaging1.TwainLogStop()


Best regards,

Loïc Carrère
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4441
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Soft and hard errors scanning TWAIN sources

Postby guruross » Wed Jul 23, 2008 7:41 pm

I have pulled out my GdTwain related code into a test project and it is working great. I'll try to figure out what could be interferring with it in the context of the production project. Thanks for your help.
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Soft and hard errors scanning TWAIN sources

Postby guruross » Wed Jul 23, 2008 11:47 pm

The test code works great on it's own, but once copied verbatim back into the production code, the TWAIn Source Manager, as accessed via GdTWAIN, reports no devices. Here is the log from the Production code. I'll followup with an email containing more sources, etc.

Code: Select all
#GdTwain Log Start. Version: 428

RC:   TWRC_SUCCESS
CC:   TWCC_SUCCESS
State: 1
-------------------
Start: OpenSourceManager.
RC:   TWRC_SUCCESS
CC:   TWCC_SUCCESS
State: 1
-------------------
DSM library loaded: C:\WINDOWS\TWAIN_32.DLL
RC:   TWRC_SUCCESS
CC:   TWCC_SUCCESS
State: 1
-------------------
Entry point of the DSM found.
RC:   TWRC_SUCCESS
CC:   TWCC_SUCCESS
State: 1
-------------------
End: OpenSourceManager.
RC:   TWRC_SUCCESS
CC:   TWCC_SUCCESS
State: 3
-------------------
Start: CloseSourceManager.
RC:   TWRC_FAILURE
CC:   TWCC_BUMMER
State: 3
-------------------
End: CloseSourceManager.
RC:   TWRC_FAILURE
CC:   TWCC_BUMMER
State: 3
-------------------
#GdTwain Log Stop.


As you can see, it appears to initialize and start just fine, however the TwainGetSourceCount has a value of 0 when tested and then when the application is closed, the Source Manager indicates the TWCC_BUMMER state (for no apparent reason).
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Soft and hard errors scanning TWAIN sources

Postby Loïc » Thu Jul 24, 2008 2:00 pm

Hi,

It is a strange behaviour. I never seen that.

Are you able to send me this project or a project based on this one which raise the error ?

Best regards,

Loïc Carrère
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4441
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Soft and hard errors scanning TWAIN sources

Postby guruross » Thu Jul 24, 2008 7:12 pm

I had a break-through on the source of this issue. When I instantiate two GdPicturePro5.cImaging objects and initialize the TWAIN component on both of them (TwainSetApplicationInfo), I get a zero sources count from both objects. If I initialize GdTWAIN on just one, I get all the TWAIN sources.

With a better understanding of the underlying architecture, this may seem self-evident, however it seems that I can only have one cImaging object initialized for TWAIN at any given time within the context of my application - Is this true?

Here's a sample to illustrate the issue. Once two objects have been initialized TWAIN, it never recovers even after clearing both objects.

Code: Select all
' 1) Make a form
' 2) Add components for:
'        GdPicture5
' 3) Add references for:
'        Microsoft Scripting Runtime (scrrun.dll)
' 4) Add a CommandButton control
' 5) Paste this code into the form code window
' 6) Replace the following constant with your license
Private Const GDPICTUREREGCODE As String = "0000000000000000000000000"

Private Const BRANDING_APPNAME = "TWAIN Test"
Private Const BRANDING_COMPANYTITLE = "My Company"
Private Const BRANDING_COMPANYSHORT = "MyCo"


Private Sub Command1_Click()
    Dim gdiItem1 As GdPicturePro5.cImaging
    Dim gdiItem2 As GdPicturePro5.cImaging
   
    Debug.Print "** FIRST OBJ **"
   
    Set gdiItem1 = GetNewGDIControl
    Set gdiItem2 = GetNewGDIControl

    InitializeGdTWAIN gdiItem1
    Debug.Print "1] Sources = " & gdiItem1.TwainGetSourceCount & ", Default = " & gdiItem1.TwainGetDefaultSourceName
   
    Debug.Print "** WITH SECOND OBJ **"
   
    InitializeGdTWAIN gdiItem2
    Debug.Print "2] Sources = " & gdiItem2.TwainGetSourceCount & ", Default = " & gdiItem2.TwainGetDefaultSourceName
    Debug.Print "1] Sources = " & gdiItem1.TwainGetSourceCount & ", Default = " & gdiItem1.TwainGetDefaultSourceName
   
    gdiItem2.TwainCloseSource
    gdiItem2.TwainCloseSourceManager
    gdiItem2.TwainUnloadSourceManager
    Set gdiItem2 = Nothing
   
    gdiItem1.TwainCloseSource
    gdiItem1.TwainCloseSourceManager
    gdiItem1.TwainUnloadSourceManager
   
    Set gdiItem1 = Nothing
   
    Debug.Print "** BOTH UNINSTANTIATED - FIRST OBJ AGAIN **"
   
    Set gdiItem1 = GetNewGDIControl
    InitializeGdTWAIN gdiItem1
    Debug.Print "1] Sources = " & gdiItem1.TwainGetSourceCount & ", Default = " & gdiItem1.TwainGetDefaultSourceName
   
End Sub

Public Function GetNewGDIControl() As GdPicturePro5.cImaging
    ' Instantiate new GdPicture object and set license property
    Dim gdiItem As GdPicturePro5.cImaging
    Set gdiItem = New GdPicturePro5.cImaging
    gdiItem.SetLicenseNumber GDPICTUREREGCODE
    Set GetNewGDIControl = gdiItem
End Function

Public Function InitializeGdTWAIN(ByRef gdiItem As GdPicturePro5.cImaging) As Boolean
    InitializeGdTWAIN = False
   
    ' Start TWAIN logging
    Dim fsoSystem As FileSystemObject
    Set fsoSystem = New FileSystemObject
    Dim intPtr As Integer
    intPtr = 1
    Do While fsoSystem.FileExists("C:\GDTWAIN" & Format(intPtr, "0000") & ".log")
        intPtr = intPtr + 1
    Loop
    gdiItem.TwainLogStart "C:\GDTWAIN" & Format(intPtr, "0000") & ".log"
    ' Set TWAIN App Info
    gdiItem.TwainSetApplicationInfo App.Major, App.Minor, TWLG_ENGLISH_USA, TWCY_USA, "", BRANDING_COMPANYSHORT, BRANDING_APPNAME, BRANDING_APPNAME
   
    If (gdiItem.TwainGetState = TWAIN_ERROR) Or (Not gdiItem.TwainGetLastResultCode = TWRC_SUCCESS) Then
        Debug.Print "Error initializing GdTWAIN:" _
            & " GDSTAT=" & gdiItem.GetStat _
            & " (TWAINSTAT=" & gdiItem.TwainGetState _
            & " - RESULT=" & gdiItem.TwainGetLastResultCode _
            & " - CONDITION=" & gdiItem.TwainGetLastConditionCode & ")"
        Exit Function
    End If
   
    InitializeGdTWAIN = True
End Function
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Soft and hard errors scanning TWAIN sources

Postby guruross » Thu Jul 24, 2008 9:04 pm

Based on my new insights, I have fixed up the production code to manage the TWAIN state bit better, however I'm still running into issues where a device will fail or some other aspect of the code will not complete and leave the TWAIN interface in a bad state. How do you reset the TWAIN connection (Source Manager?) once it is in a bad state?

Here's some of my interpreted debug output and attached is the pertinent TWAIN log.

Code: Select all
' States listed in following order:
'   GetStat, TwainGetState, TwainGetLastResultCode, TwainGetLastConditionCode
'
[closing source] Error initializing GdTWAIN: Twain Error (Source Open - Failed - General Failure)
[closing source manager] Error initializing GdTWAIN: Twain Error (Source Open - Failed - General Failure)
[unloading source manager] Error initializing GdTWAIN: Twain Error (Source Open - Failed - General Failure)
[initializing twain] Error initializing GdTWAIN: OK (Source Open - Failed - General Failure)
[closing source] Error initializing GdTWAIN: OK (Source Open - Failed - General Failure)
[closing source manager] Error initializing GdTWAIN: OK (Source Open - Failed - General Failure)
[unloading source manager] Error initializing GdTWAIN: OK (Source Open - Failed - General Failure)
[initializing twain] Error initializing GdTWAIN: OK (Source Open - Failed - General Failure)
Attachments
TWAIN_good2bad.zip
Log of TWAIN interactions, goes into "BUMMER" state while cataloging sources, never recovers
(1.13 KiB) Downloaded 82 times
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Soft and hard errors scanning TWAIN sources

Postby Loïc » Fri Jul 25, 2008 11:42 am

Hi,

This part of the log:

Code: Select all
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_GET ->RC: TWRC_SUCCESS
-------------------
Start: OpenSource.    <- WARNING, Here a source is already open. A call to TwainCloseSource() could be a good idea ;)
RC:   TWRC_SUCCESS
CC:   TWCC_SUCCESS
State: 4
-------------------
Start: CloseSource.
RC:   TWRC_SUCCESS
CC:   TWCC_SUCCESS
State: 4
-------------------
End: CloseSource.
RC:   TWRC_FAILURE
CC:   TWCC_BUMMER
State: 4
-------------------


tell me that you are trying to open a specific source without closing the one which are currently open.
I suggest you to close first the source which is open before opening another one.

If you want to close the DSM (Data Source Manager which is a hook to TWAIN_32.dll) you need to use the TwainCloseSourceManager() method.If success, the twain state must be <= 2 (TWAIN_SM_LOADED).
if you want to unload the DSM (a simple call to the FreeLibrary API into the TWAIN_32.DLL) you need to use the TwainUnloadSourceManager() method.


Best regards,

Loïc Carrère
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4441
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Soft and hard errors scanning TWAIN sources

Postby Loïc » Fri Jul 25, 2008 12:01 pm

I had a break-through on the source of this issue. When I instantiate two GdPicturePro5.cImaging objects and initialize the TWAIN component on both of them (TwainSetApplicationInfo), I get a zero sources count from both objects. If I initialize GdTWAIN on just one, I get all the TWAIN sources.


You found a bug from the gdtwain.dll

This problem will be fixed for the next release.

I've uploaded a beta version of gdtwain.dll which fix this problem. It can be downloaded from this link: http://www.gdpicture.com/ressources/betas/gdtwain.dll


Best regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4441
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Soft and hard errors scanning TWAIN sources

Postby guruross » Fri Jul 25, 2008 5:30 pm

Great! Thank you for being so responsive, the beta DLL appears to be working pretty well at first glance.
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA


Return to GdTwain [Pro] ActiveX

Who is online

Users browsing this forum: No registered users and 1 guest