我正在尝试读取从与笔记本电脑连接的USB设备发送的数据。 设备发送数据,如下所述:
52-30-30-45-46-30-34-31
41-33-35-32-31-43-41-30
32-0D
我能够获得第一个和第二个有效负载,但是第三次线程停止却什么也没得到。
我正在使用异步过程读取数据。下面,我提到一些代码捕捉以供参考。过程是连续读取过程
ReadFinished = NativeMethods.CreateEvent(IntPtr.Zero, true, false, "killread");
// Create event used to signal a read has completed
IntPtr eventObject = NativeMethods.CreateEvent(IntPtr.Zero, false, false, "");
// Clear out any waiting input data
NativeMethods.HidD_FlushQueue(handle);
// Allocate memory for the input buffer and overlapped structure.
IntPtr nonManagedBuffer = Marshal.AllocHGlobal(InputReportLength);
IntPtr nonManagedOverlapped = Marshal.AllocHGlobal(Marshal.SizeOf(hidOverlapped));
Marshal.StructureToPtr(hidOverlapped, nonManagedOverlapped, false);
UInt32 numberOfBytesRead = 0;
Boolean success = NativeMethods.ReadFile(handle, nonManagedBuffer, (UInt32)InputReportLength, ref numberOfBytesRead, nonManagedOverlapped);
// Timeout set to infinite - will not return until signalled
Int32 result = NativeMethods.WaitForMultipleObjects(2, events, false, 0xFFFFFFFF);
// If read completed successfully, get the data
NativeMethods.GetOverlappedResult(handle, nonManagedOverlapped, ref numberOfBytesRead, true);
以上所有这些方法都在处理中使用。
我试图把所有的细节。请让我知道是否需要其他详细信息。
预先感谢。