0

I'm writig a dotnet application to communicate with a telemetry device for bulk transfer . I'm using [libusbdotnet v2][1] [1]: https://github.com/LibUsbDotNet/LibUsbDotNet/tree/v2. I'm able to enumerate my devices it gives me the VID,PID of all devices but the device seems to null for all device device and i'm not able to open by device.

   public void listdevices()
    {
        // Dump all devices and descriptor information to console output.
        UsbRegDeviceList allDevices = UsbDevice.AllDevices;
        foreach (UsbRegistry usbRegistry in allDevices)
        {
             Console.WriteLine("Device" + usbRegistry.Device); //this is always null
            Console.WriteLine("DeviceName"+UsbDevice.HasLibUsbDriver);
            Console.WriteLine("DevicePath" + usbRegistry.DevicePath);
              var devaddr_str = usbRegistry.DevicePath.Split('.').Last();
            int devaddr = Int32.Parse(devaddr_str);
            Console.WriteLine("DeviceAddress" + devaddr);
            if(devaddr==36)
            {
                //MyUsbDevice = usbRegistry.Device;
                  string vid="";
                    string pid="";
                    string rev="";
                foreach (KeyValuePair<string, object> kvp in usbRegistry.DeviceProperties)
            {
               if(kvp.Key.Contains("Hardware"))
               {
                   string[] arr = Array.ConvertAll((object[])kvp.Value, Convert.ToString);
                   string[] hdlist = arr[0].Split("&");
                  
                   foreach (var item in hdlist)
                   {
                                if(item.Contains("Vid"))
                                    vid=item.Replace("Vid_","");
                                if(item.Contains("Pid"))
                                    pid=item.Replace("Pid_","");
                                if(item.Contains("Rev"))
                                    rev=item.Replace("Rev__","");
                       Console.WriteLine(item.ToString());
                   }
                   
               }
            }
                Console.WriteLine("vid"+vid+" pid"+pid);
                // int vid_int = Int32.Parse(vid);
                // int pid_int = Int32.Parse(pid);
                UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(rev); 
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder); //this is also null
            
            // If the device is open and ready
            if (MyUsbDevice == null) throw new Exception("Device Not Found.");
                //  if (MyUsbDevice == null) throw new Exception("Device Not Found.");
            }

I tried using usbfinder with VID and PID even but still the device is null and device not found exceltion is thrown

I'm working in linux and For all devices i'm able to find below details

Device null
DevicePathusbdev1.109
Device Vendor ID7358
Device Product ID3
Device full name
Key = Mfg, Value = 
Key = DeviceDesc, Value = 
Key = SerialNumber, Value = 
Device hardwareVid_1CBE&Pid_0003&Rev_0256
Key = HardwareId, Value = System.String[]
Key = SymbolicName, Value = Vid_1CBE&Pid_0003&Rev_0256{00000000-0000-0000-0000-000000000000 }##

When i'm able to list the devices why i'm not able to open it is there anyother thing i have to do other than what is mentioned in readme of library for linux users.

BTW the devices communicate well with c code so there is no issue with device.

jasmi
  • 1
  • 3

0 Answers0