Loading...

Detecting device connectivity/presence

Support for GdTwain ActiveX and GdTwain Pro ActiveX/SDK.

Detecting device connectivity/presence

Postby guruross » Tue Jul 22, 2008 11:32 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 having difficulty with device detection. Is there a method to detect whether a device is present?

For example, I have previously installed a Canon scanner but it is not currently connected. The TwainSelectSource, TwainGetSourceCount and TwainGetSourceName methods return or show this device, among others, as an option. How can I seemlessly test for it's presence? I am working on an extended functionality Source Manager dialog and attempting to open this particular Canon scanner device (TwainOpenSource) shows an error dialog indicating the device is not available, interupting my silent background scan of devices. I would like to be able to show the disconnected state of devices in this dialog without additional popups (I have already set the following properties).
TwainSetErrorMessage False
TwainSetHideUI True
TwainSetIndicators False

I understand that some TWAIN drivers may not honor the above requests, I am just trying to find the best way to detect device connection status.

Thank you for any assistance you may be able to provide.
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Detecting device connectivity/presence

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

I found the Capacities interface and am trying the below, however I don't know if it will work yet because I can't even open a source now (see my other thread for that issue).

Here's a concise snippet of the logic, for your reference.
Code: Select all
  Dim gdiItem As GdPicturePro5.cImaging
  Set gdiItem = New GdPicturePro5.cImaging
  gdiItem.SetLicenseNumber "0000000000000000000000000"     ' ---zeroed out for example
  gdiItem.TwainLogStart "C:\TWAIN.log"
  gdiItem.TwainSetApplicationInfo App.Major, App.Minor, TWLG_ENGLISH_USA, TWCY_USA, "", BRANDING_COMPANYSHORT, BRANDING_APPNAME, BRANDING_APPNAME
  If gdiItem.TwainIsAvailable Then
    Dim lngPtr As Long
    For lngPtr = 1 To gdiItem.TwainGetSourceCount
      Dim strSourceName As String
      strSourceName = gdiItem.TwainGetSourceName(lngPtr)
      If gdiItem.TwainOpenSource(strSourceName) Then
        If gdiItem.TwainGetCapCurrentString(CAP_DEVICEONLINE, strAvailable) Then
          ' query source
        End If
        gdiItem.TwainCloseSource
      End If
    Next
  End If
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Detecting device connectivity/presence

Postby Loïc » Wed Jul 23, 2008 9:57 am

Hi,

Very interesting post !

I think the best way to test if a device is both installed & on-line is to open the source and check the on-line statue through the CAP_DEVICEONLINE capability (In fact what you already done :mrgreen: ).


I give you a code snipet which raise the state of all the installed TWAIN devices:


Code: Select all
Dim nCpt As Long
Dim strSourceName As String
Dim nDeviceOnline As Double

For nCpt = 1 To Imaging1.TwainGetSourceCount
    strSourceName = Imaging1.TwainGetSourceName(nCpt)
    If Imaging1.TwainOpenSource(strSourceName) Then
       Call Imaging1.TwainGetCapCurrentNumeric(CAP_DEVICEONLINE, nDeviceOnline)
       If nDeviceOnline = 1 Then
           MsgBox "Source " & strSourceName & " seems to be online !"
       Else
          MsgBox "Source " & strSourceName & " seems to be offline !"
       End If
    Else
       MsgBox "Source " & strSourceName & " can't be opened !"
    End If
    Imaging1.TwainCloseSource
Next nCpt


You can see that I changed your portion:

Code: Select all
If gdiItem.TwainGetCapCurrentString(CAP_DEVICEONLINE, strAvailable) Then
          ' query source
 End If


By the this one:

Code: Select all
 
Call Imaging1.TwainGetCapCurrentNumeric(CAP_DEVICEONLINE, nDeviceOnline)
If nDeviceOnline = 1 Then
   MsgBox "Source " & strSourceName & " seems to be online !"
Else
   MsgBox "Source " & strSourceName & " seems to be offline !"
End If


If you brows the TWAIN specifications to the capability CAP_DEVICEONLINE (9-373)
You can see that this capability communicate using a Boolean value. In this case, you have to use the TwainGetCapCurrentNumeric() method instead the TwainGetCapCurrentString(). The nDeviceOnline parameter is a "Byref" output parameter which catch the value returned by the CAP_DEVICEONLINE capability.

I hope I was clear enought.

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: Detecting device connectivity/presence

Postby guruross » Wed Jul 23, 2008 5:24 pm

Thank you, I'll give that a shot. I noted the capacity was a boolean type but wasn't sure how that would transfer to the GdPicture methods. Is there a way to do this without first opening the source? Some sources generate a user-visible UI when attempting to open them while they are not physically present, which is highly undesirable.
User avatar
guruross
 
Posts: 45
Joined: Tue Jul 22, 2008 11:14 pm
Location: Redding, CA, USA

Re: Detecting device connectivity/presence

Postby ctn » Wed Dec 10, 2008 12:24 pm

Hi all

Just to add some comments:

I think the best way to test if a device is both installed & on-line is to open the source and check the on-line statue through the CAP_DEVICEONLINE capability (In fact what you already done :mrgreen: ).


The connection error message is going to be displayed during this method call:

Code: Select all
gdTwain.TwainOpenSource(_sourceName);


So its not possible to open the source and check the "CAP_DEVICEONLINE" status.

Br,
ctn
ctn
 
Posts: 57
Joined: Thu Dec 04, 2008 6:20 pm

Re: Detecting device connectivity/presence

Postby Loïc » Wed Dec 10, 2008 5:59 pm

Hi,

If you can't open the source you can't communicate with it.
Therefore it is not useful to ask to the source if it is attached, powered on, and communicating (you already have your answer on the open failure).

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: Detecting device connectivity/presence

Postby ctn » Wed Dec 10, 2008 6:20 pm

Hi

Yes you are right, but to avoid the window pop up (even if TwainSetHideUI = true) in case of a communication failure I would like to check this before open any sources.

My intension is just to avoid any window pop up and user interactions because I m writing a console application.

Br,
Toan
ctn
 
Posts: 57
Joined: Thu Dec 04, 2008 6:20 pm

Re: Detecting device connectivity/presence

Postby Loïc » Wed Dec 10, 2008 8:41 pm

My intension is just to avoid any window pop up and user interactions because I m writing a console application.


Ok ! Unfortunately you can't control the error messagebox you gave. You can only ask to the TWAIN driver to don't display the GUI of its parameters before acquiring an image.


The only way I can see is to write a hook to catch all the messagebox of the system in order to identify the ones from your TWAIN driver for clicking automatically on the YES button... It is a hard task which I never done this.


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


Return to GdTwain [Pro] ActiveX

Who is online

Users browsing this forum: No registered users and 1 guest