Quantcast
Channel: James's Programming Page
Viewing all articles
Browse latest Browse all 141

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

$
0
0

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);
                }
            }
        }

Viewing all articles
Browse latest Browse all 141

Trending Articles