1

Topic: HidSharp.Exceptions.DeviceIOException on HidDevice.Open, Windows only

I have a consistent issue specifically to Windows. On Linux, this exact code runs without issue, but on Windows it throws a DeviceIOException every time, but only for this one device. This is running on HidSharp 2.1.0, .NET Core 3.0.

using System;
using System.Linq;
using HidSharp;
using HidSharp.Reports.Input;

namespace HidTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var devices = HidSharp.DeviceList.Local.GetHidDevices();
            var tablets = devices.Where(d => d.GetFriendlyName() == "Intuos PS").ToList();
            tablets.OrderBy(t => t.GetFriendlyName());
            Device = tablets[0];
            Console.WriteLine(Device.GetMaxInputReportLength());
            var descriptor = Device.GetReportDescriptor();
            Console.WriteLine(descriptor);
            Reciever = descriptor.CreateHidDeviceInputReceiver();
            Reciever.Start(Device.Open());
            Reciever.Received += PacketReceived;
            Console.Read();
        }

        static HidDevice Device;
        static HidDeviceInputReceiver Reciever;

        static void PacketReceived(object sender, EventArgs e)
        {
            var buffer = new byte[Device.GetMaxInputReportLength()];
            Reciever.TryRead(buffer, 0, out var rpt);
            Console.WriteLine(BitConverter.ToString(buffer));
        }
    }
}

This throws this exception every time

Exception has occurred: CLR/HidSharp.Exceptions.DeviceIOException
An unhandled exception of type 'HidSharp.Exceptions.DeviceIOException' occurred in HidSharp.dll: 'Unable to open HID class device (\\?\hid#vid_056a&pid_030e&mi_02#8&123e7efa&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}).'
   at HidSharp.Platform.Windows.WinHidStream.Init(String path)
   at HidSharp.Platform.Windows.WinHidDevice.OpenDeviceDirectly(OpenConfiguration openConfig)
   at HidSharp.Device.OpenDeviceAndRestrictAccess(OpenConfiguration openConfig)
   at HidSharp.Device.Open(OpenConfiguration openConfig)
   at HidSharp.Device.Open()
   at HidSharp.HidDevice.Open()
   at HidTest.Program.Main(String[] args) in \\vmware-host\Shared Folders\Repos\hidtest\HidTest\Program.cs:line 20

2

Re: HidSharp.Exceptions.DeviceIOException on HidDevice.Open, Windows only

If it shows up to the OS as a mouse or keyboard, FWIW, Windows will block access to it for "security".

3

Re: HidSharp.Exceptions.DeviceIOException on HidDevice.Open, Windows only

Is there any workaround for this? I know that github.com/djpnewton/vmulti pulls it off without this issue in this project: github.com/hawku/TabletDriver

4

Re: HidSharp.Exceptions.DeviceIOException on HidDevice.Open, Windows only

I know this is much later, but just for other people this might help.... Yeah, what Zer said is right, some HID devices are touchy so even trying to access their FriendlyName or something via a LinQ query / enumeration using a DeviceList... looking for a match can throw access denied exceptions.  That way you are at the mercy of the order of the list as far as if the query internally hits a secured device or the one you seek first.  So, the safer way I found to do it is to use old school convert to an array of Devices and use a foreach loop with a try/catch .  If an exception occurs looking at a property on one of the devices, you can eat the exception b/c you know it is not the one you're looking for.  There are other ways too access too, if you look at the API for DeviceList, there are TryGet's and GetHidDevices with several filtering options available.