I m trying to read the data that is send from a USB device connected with laptop. device send data as mention below:
52-30-30-45-46-30-34-31
41-33-35-32-31-43-41-30
32-0D
I am able to get first and second payload but the thread stop in third time did not get any thing.
I m using asynchronous process to read the data. Below I have mention some code snap for the reference. Process is continuous read process
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);
above all these method are used in process. I tried to put all the detail. Please let me know if require any other details. Thanks in advance.
User contributions licensed under CC BY-SA 3.0