Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIDDevice.Removed Event occurs when not unplugged #98

Open
simplifirepyroneil opened this issue May 4, 2018 · 0 comments
Open

HIDDevice.Removed Event occurs when not unplugged #98

simplifirepyroneil opened this issue May 4, 2018 · 0 comments

Comments

@simplifirepyroneil
Copy link

I have a custom HID USB device that after running for hours will suddenly return all 0x0 bytes on reads then the HIDDevice.Removed event occurs about a third of a second later. The ManagementEventWatcher does not show any arrival/removal event for the device. Restart the app and all is well again.

The reader loop does check the read result for HidDeviceData.ReadStatus.Success and when it blows up it still has the read status as success.

Couple of questions - What is causing the reads to return a report that has not had data read into it? What is causing the removal event to be generated?

Opening looks like this:

     _ClockDevice = DerivedHidDevices<HidFastReadDevice>.Enumerate(VendorId, ProductId).FirstOrDefault();
     if (_ClockDevice != null)
     {
        _ClockDevice.OpenDevice();

        _ClockDevice.Inserted += DeviceAttachedHandler;
        _ClockDevice.Removed += DeviceRemovedHandler;

        _ClockDevice.MonitorDeviceEvents = true;

        UseExternalClock = true;
        USBConnected = true;
        FSKDevicePresent = true;
        ReaderTask = new Task(Reader, TaskCreationOptions.LongRunning);
        ReaderTask.Start();
     }

Reader task:
while (FSKDevicePresent && UseExternalClock)
{
HidReport report = await _ClockDevice?.FastReadReportAsync();
if (report == null || report.ReportId != 0 || report.ReadStatus != HidDeviceData.ReadStatus.Success )
continue;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant