Home › Forums › TWAIN Classic › CAP_DEVICEONLINE always return false or suppress messagebox
- This topic has 1 reply, 1 voice, and was last updated 12 years, 6 months ago by brcbuzz.
- AuthorPosts
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 IfSo 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 TwRCDim 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 TryEnd Function
Please help… I would greatly appreciate any guidance.
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.ManagementObjectmoSearch = 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.GetFor 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
NextReturn False
Catch ex As Exception
Return False
End TryEnd Function
- AuthorPosts