public bool GetDeviceList(out List <DeviceId> deviceIds) { deviceIds = new List <DeviceId>(); uint bytesReturned; bool result = devIO.DeviceIoControl(IOCTL_BUSDOG_GET_DEVICE_LIST, IntPtr.Zero, 0, outBuffer, outBufferSize, out bytesReturned); if (result) { int index = 0; while (bytesReturned >= index + Marshal.SizeOf(typeof(BUSDOG_DEVICE_ID))) { BUSDOG_DEVICE_ID devId = (BUSDOG_DEVICE_ID) Marshal.PtrToStructure(new IntPtr(outBuffer.ToInt64() + index), typeof(BUSDOG_DEVICE_ID)); index += Marshal.SizeOf(typeof(BUSDOG_DEVICE_ID)); string hardwareId = Marshal.PtrToStringUni(new IntPtr(outBuffer.ToInt64() + index), devId.PhysicalDeviceObjectNameSize.ToInt32() / 2); index += devId.PhysicalDeviceObjectNameSize.ToInt32(); deviceIds.Add(new DeviceId(devId.DeviceId, Convert.ToBoolean(devId.Enabled), hardwareId)); } } else { System.Diagnostics.Debug.WriteLine(Marshal.GetLastWin32Error()); } return(result); }
void TraceBufRead() { try { DeviceIOCTL devIO = new DeviceIOCTL(busdogPath, true); while (true) { uint bytesReturned; // send the get trace buffer command to the driver bool result = devIO.DeviceIoControl( IOCTL_BUSDOG_GET_BUFFER, IntPtr.Zero, 0, outBuffer, outBufferSize, out bytesReturned); if (!result) { int err = Marshal.GetLastWin32Error(); // check if the I/O request is pending if (err == ERROR_IO_PENDING) { while (true) { // keep checking if the I/O request has been fufilled (abort after 500ms so our thread can be killed) if (devIO.WaitForOverlappedIo(500, out bytesReturned)) { result = true; break; } } } else System.Diagnostics.Debug.WriteLine(err); } if (result) { // we have a result so now we convert the buffer into a trace list and call the event if (FilterTraceArrived != null) FilterTraceArrived( this, new FilterTraceArrivedEventArgs(GetTraceList(outBuffer, outBufferSize, bytesReturned))); // stall trace stream to allow main thread to have a turn now and then Thread.Sleep(10); } } } catch (ThreadAbortException) { // We will cancel any pending IO on this thread before exiting devIO.CancelIo(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
void TraceBufRead() { try { DeviceIOCTL devIO = new DeviceIOCTL(busdogPath, true); while (true) { uint bytesReturned; // send the get trace buffer command to the driver bool result = devIO.DeviceIoControl( IOCTL_BUSDOG_GET_BUFFER, IntPtr.Zero, 0, outBuffer, outBufferSize, out bytesReturned); if (!result) { int err = Marshal.GetLastWin32Error(); // check if the I/O request is pending if (err == ERROR_IO_PENDING) { while (true) { // keep checking if the I/O request has been fufilled (abort after 500ms so our thread can be killed) if (devIO.WaitForOverlappedIo(500, out bytesReturned)) { result = true; break; } } } else { System.Diagnostics.Debug.WriteLine(err); } } if (result) { // we have a result so now we convert the buffer into a trace list and call the event if (FilterTraceArrived != null) { FilterTraceArrived( this, new FilterTraceArrivedEventArgs(GetTraceList(outBuffer, outBufferSize, bytesReturned))); } // stall trace stream to allow main thread to have a turn now and then Thread.Sleep(10); } } } catch (ThreadAbortException) { // We will cancel any pending IO on this thread before exiting devIO.CancelIo(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }