1 (edited by azrael_yavuz 2021-03-05 08:12:57)

Topic: Unable to open HID class device (OK) exception while open on Linux

I have an issue on Linux. When I call Open method it throws "Unable to open HID class device (OK)". But when I check CanOpen, it is true but cannot open. I also use TryOpen method  but it didnt work. On windows side it works without any issue. I use HidSharpCore 1.2.1.1 at .net 5.0. 

Please help me to solve this issue.

private static object lo = new object();
        public byte[] WriteAndWaitResponse(byte[] data)
        {

            lock (lo)
            {
                byte[] result;
                Console.WriteLine("vid:" + vendorId + " pid:" + productId);

                if (!DeviceList.Local.TryGetHidDevice(out Dev, vendorId, productId))
                {
                    Console.WriteLine("Cannot GetHidDevice");
                    return null;
                }

                HidStream stream = null;
                if (Dev.CanOpen)
                {
                    
                    try
                    {
                        OpenConfiguration configuration = new OpenConfiguration();
                        stream = Dev.Open();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    if(stream == null)
                    {
                        Console.WriteLine("Try Open failed");
                    }
                }
                else
                {
                    Console.WriteLine("Cannot Open");
                }

                try
                {
                    stream.Write(data);
                    Console.WriteLine("data:" + data.Length);
                    Thread.Sleep(100);
                    result = stream.Read();
                    Console.WriteLine("result:" + result.Length);

                    return result;
                }
                catch (Exception ex)
                {

                    throw new RealDeviceException("error while writing to USB", ex);
                }
            }
        }

2

Re: Unable to open HID class device (OK) exception while open on Linux

Naive idea. Have you tried changing your if to check the out parameter (device dev) rather than the return vale of try open? Without a specific stack trace its hard to say what your problem is here. The fact this works on Windows suggests that its an issue with linuxsupport or a config or permission issue, maybe another library or process interfering.

https://github.com/OpenTabletDriver/Ope … issues/452

Check that link for a potential solution.

3

Re: Unable to open HID class device (OK) exception while open on Linux

Having exactly the same error running on Ubuntu 20.10 arm64

Here's the stack trace:

at HidSharp.Platform.Linux.LinuxHidStream.DeviceHandleFromPath(String path, HidDevice hidDevice, oflag oflag)
   at HidSharp.Platform.Linux.LinuxHidDevice.TryParseReportDescriptor(ReportDescriptor& parser, Byte[]& reportDescriptor)
   at HidSharp.Platform.Linux.LinuxHidDevice.RequiresGetInfo()
   at HidSharp.Platform.Linux.LinuxHidDevice.OpenDeviceDirectly(OpenConfiguration openConfig)
   at HidSharp.Device.OpenDeviceAndRestrictAccess(OpenConfiguration openConfig)
   at HidSharp.Device.Open(OpenConfiguration openConfig)
   at HidSharp.Device.Open()
   at HidSharp.HidDevice.Open()