The TWAIN Forum

www.twainforum.org
It is currently Sat May 25, 2013 5:21 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Sep 13, 2011 9:14 am 
Offline

Joined: Fri Jul 15, 2011 12:20 pm
Posts: 4
I am desperate so I appreciate any help.

I have an application that uses the Twain_32.dll for scanning. This application used some of the code off of the solution located at “http://www.codeproject.com/KB/dotnet/twaindotnet.aspx?msg=3699574”. Anyway, my problem is that I have a modal form that the user clicks a button to begin scanning. If the scanner power is off then the scanner’s driver displays a message box with an error stating that the device is not ready. This would not be an issue except it gets placed behind the modal form and gives the appearance that the application freezes. The source code call is below…

rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds)
If rc <> TwRC.Success Then
Return False
End If


So when the DSMIdent call is being made then that is when the message box is being displayed so I cannot capture the value of “rc” at that time to prevent the message box from being displayed behind my modal form.


In trying to prevent this I attempted to check if the device is online with the code below. The problem with this is that is always returns false even if the scanner is online and ready.

Public Function IsDeviceOnline() As Boolean
Try
Dim rc As TwRC

Dim capDeviceOnline As New TwCapability(TwCap.CAP_DEVICEONLINE)

rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.DeviceEvent, capDeviceOnline)
If rc <> TwRC.Success Then
CloseSrc()
Return False
End If
Return True
Catch ex As Exception
Return False
End Try

End Function

Please help… I would greatly appreciate any guidance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2011 8:59 am 
Offline

Joined: Fri Jul 15, 2011 12:20 pm
Posts: 4
For anyone who has this problem and works in .NET then ignore tring to do this through the Twain drivers and go this direction.

Public Shared Function GetUSBDeviceStatus() As Boolean
Try
Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from Win32_USBControllerDevice")
moReturn = moSearch.Get
For Each mo In moReturn
Dim moReturnDevice As Management.ManagementObjectCollection
Dim moSearchDevice As Management.ManagementObjectSearcher
Dim moDevice As Management.ManagementObject
Dim strDeviceName As String = mo("Dependent").ToString.Replace(""""c, "")
Dim strDevice As String = strDeviceName.Substring(strDeviceName.IndexOf("=") + 1)

moSearchDevice = New Management.ManagementObjectSearcher("Select * From Win32_PnPEntity Where DeviceID = '" & strDevice & "'")
moReturnDevice = moSearchDevice.Get

For Each moDevice In moReturnDevice
If Not moDevice.Item("Service") Is Nothing AndAlso Not moDevice.Item("Status") Is Nothing Then
If moDevice.Item("Service").ToString.Trim.ToLower.Equals("usbscan") And moDevice.Item("Status").ToString.Trim.ToLower.Equals("ok") Then
Return True
End If
End If
Next
Next

Return False

Catch ex As Exception
Return False
End Try

End Function


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group