1

Topic: errors from catch (Exception ex)

First I could not get the examples to compile using vars.. It kept complaining about tryOpen not being a member. So I have to use read class types. Now I get this... See comments in try catch. I can use HID.dll from my command line C application with a report ID of 18 using 4 and 2 as a write.  So I know the device is good.

  HidDeviceLoader loader = new HidDeviceLoader();
         HidDevice device = loader.GetDevices(0x16d0, 0x0d04).First();
         HidStream stream;
         device.TryOpen(out stream);

         var bytes = new byte[device.MaxOutputReportLength];
         bytes[0] = 18;
         bytes[1] = 4;
         bytes[2] = 1;
         int retry = 10;

         while (retry>0)
         {
             try
             {
                 stream.Write(bytes);
             }
             catch (TimeoutException)
             {
                 retry--;
                 //retry
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Timeout waiting for API to respond: " + ex.Message);
                 // ex.InnerException  - The parameter is incorrect.
                 // ex.message  operation failed early


                 return true;
                 //error out.
             }
             finally
             {
                 stream.Close();
             }
         }
         return false;