1 (edited by johnbizios 2019-11-12 21:01:05)

Topic: Issue with Exponent...

Hi -

I've run into an issue retrieving the ReportDescriptor from a UPS device.  HidSharp throws an exception of:

ArgumentOutOfRangeException("value", "Value range is [0, 15]

in the method DecodeExponent.

When I step into the code, I see that the value being passed in is 0xFFFFFFFF (4294967295)

If I modify the code that validates the value to ignore the check for a valid range for the exponent, all the other values in the returned ReportDescriptor look valid.  And I get good values for Exponent in other reports.

As I'm new to HID and trying to understand, was curious as to what a -1 for Unit Exponent might indicate. I'm assuming it's an undefined value and if I use a tool like USBlyzer and look at the HID Report Descriptor it returns, there is no value for Unit but it does not throw an exception.

Any help or information anyone could provide would be greatly appreciated.

Thanks in advance.

2

Re: Issue with Exponent...

It indicates that the integer value read should be multiplied by 0.1 to get the physical value.

Looking into this, there is an ambiguity in the USB HID specification and it sounds like your device takes the alternate interpretation from HIDSharp. I've added handling for that alternative interpretation. Please try this version of HIDSharp and see if it fixes your problem:

https://www.zer7.com/files/oss/hidsharp … -11-20.zip

Thanks!

James

3

Re: Issue with Exponent...

Hi James -

Thanks for this.  It does fix my error.

When do you expect to update the NUGET package to reflect this edit?

Kind regards -

... john ...

4

Re: Issue with Exponent...

Hi James again -

Apologies, but I tested your fix on a different UPS device that was not reporting the UnitExponent as a -1.

When I plugged in my other UPS that had the -1, your code did not work.

The issue is in the method:

public static int DecodeExponent(uint value)
        {
            if (value > 15) { throw new ArgumentOutOfRangeException("value", "Value range is [0, 15]."); }
            return value >= 8 ? (int)value - 16 : (int)value;
        }

The parameter is a uint value,  which when it comes in as a -1 makes it > 15 and throws the exception.

Not sure if this is what you intended.

Thanks again for looking into this.

... john ...

5

Re: Issue with Exponent...

Could you give me a stack trace for that? The new version shouldn't call DecodeExponent for values outside that range. (Assuming it's being called from ParseMainData.)