Hi,
I am using your project generic_hid_vb_46.zip as a base point
I have a device connected to the system that is spitting out data
If I use basically your project I get the data but it is jumbled because there are repeats of the data.
If I modify the success = FileIO.ReadFile _
(readHandle, _
nonmanagedBuffer, _
inputReportBuffer.Length, _
numberOfBytesRead, _
nonmanagedOverlapped)
to have
'IntPtr.zero
in the overlapped then no data comes back.
I have a very similar project in vb6 that works for the most part, it was written like so (abbreviate).
UsbEventObject = CreateEvent(usbSecurity, CInt(True), CInt(False), "rdUsb")
HIDOverlapped.Offset = 0
HIDOverlapped.OffsetHigh = 0
HIDOverlapped.hEvent = UsbEventObject
Public Sub WaitForUsbRet()
Dim Result As Long
Dim ResultWait As Long
Dim res2 As Integer
Dim RecBuffer(65) As Byte
Dim rdNum As Long
Dim i As Integer
Dim res3 As Long
res2 = 1
Form1.lstBoxRec.AddItem "StartWait"
Do
' Form1.ShpStatus.BackColor = Form1.ShpStatus.BackColor + 1
DoEvents
RecBuffer(4) = 0
RecBuffer(5) = 0
Result = ReadFile _
(HIDHandle, _
RecBuffer(0), _
CLng(Capabilities.InputReportByteLength), _
rdNum, _
HIDOverlapped)
ResultWait = WaitForSingleObject(UsbEventObject, 500)
Select Case ResultWait
Case WAIT_TIMEOUT
' ' Timeout error.
' Form1.lstBoxRec.AddItem "Out"
CancelIo (ReadHandle)
Form1.devStatus = RET_USBDEVREVTOOLOW
DoEvents
Case WAIT_FAILED Or WAIT_ABANDONED
' Form1.lstBoxRec.AddItem "FAIL"
Form1.devStatus = RET_USBDEVREVTOOLOW
DoEvents
Case WAIT_OBJECT_0
' ' ' Success
' ' ' Use the report data.
' Form1.lstBoxRec.AddItem "Waited"
rdNum = (RecBuffer(4) + 6)
If rdNum > 65 Then rdNum = 65
If (rdNum > 5) Then
For i = 1 To rdNum
Form1.putInCircBuff (RecBuffer(i))
Next i
End If
' Form1.lstBoxRec.ListIndex = Form1.lstBoxRec.ListCount - 1
If (rdNum > 0) Then Form1.tmrCommHndl.Enabled = True
DoEvents
Form1.devStatus = RET_SUCCESS
Case Else
' Form1.lstBoxRec.AddItem "Else"
CancelIo (ReadHandle)
Form1.devStatus = RET_USBDEVREVTOOLOW
End Select
' res3 = ResetEvent(EventObject)
Loop Until res2 = 0
End Sub
I understand that the problems I am having with the vb.net project are basically my lack of understanding, such as making a friend function for the read and the fact that the application does not debug well in visual basic 2010 express.
Any advice you can give would be appreciated.
Thanks,
Martin