Problem with getting property of sensor
Hello. I'm working with magnetometer sensor. The project supports .NET 4.0 so probably the "Windows-API-Code-Pack" platform is my only option. (By the way, why you changed the target framework of aybe's source?) Sensor.GetSupportedProperties returns of 7 values. There are correct ids among them, I checked it by https://docs.microsoft.com/en-us/windows-hardware/drivers/sensors/sensor-category-orientation. But when I call, for example, Sensor.GetProperty(new PropertyKey("1637d8a2-4248-4275-865d-558de84aedfd", 11)), which is supposed to be "SENSOR_DATA_TYPE_MAGNETIC_HEADING_COMPENSATED_MAGNETIC_NORTH_DEGREES" according to link above and is presented in GetSupportedProperties's results, it returns exception "not found property" or something like this. I would be very grateful, if you could suppose why it's happening. I've tried to debug source but there is COM-technology there that I cannot handle.
It seems that "properties" is only high-level properties of device, and its current values are contained in "DataReport". But how can I receive the needed values if DataReport[key] is an array? One of my device produce DataReport[1637D8A2-4248-4275-865D-558DE84AEDFD] that is array of 4 values, and another is 5-values array.
I found the problem. In SensorData.FromNativeReport the code
data.Add(key.FormatId, new List<object> { propValue.Value });
adds only key.FormatId and skips key.PropertyId. Therefore we cannot distinguish the values.
Thanks for reporting this, I'll get this fixed as soon as I can. I have not used the sensors stuff myself so I'll need to familiarize myself with it first.
To answer your question about the framework version, I changed it because the original purpose of this fork was to get a package in nuget with all the fixes that the company I work for could use instead of having to include binaries in our source control.
Also, sorry for the delay in responding, apparently github isn't sending me notification emails properly.
I believe it is handling the propertyID just not in the manner you're expecting. If I'm understanding the code that is there, the SensorData class is filling itself with values keyed off the Guid. If the Guid is already present, it's appending it to a List
I would expect that you could access what you're looking for using something like the following:
object value = data[new Guid("1637D8A2-4248-4275-865D-558DE84AEDFD")][11];
So if you're starting from a SensorReport, that stores a SensorData items in Values so it would perhaps be something like this:
object value = dataReport.Values[new Guid("1637D8A2-4248-4275-865D-558DE84AEDFD")][11];
Let me know if this doesn't make sense.
It doesn't work.
dataReport.Values[new Guid("1637D8A2-4248-4275-865D-558DE84AEDFD")]
is a plain array, sor example:
>reportValues[new Guid("1637D8A2-4248-4275-865D-558DE84AEDFD")]
Count = 5
[0]: 206.47661000000002
[1]: 66.422
[2]: -602.248
[3]: -117.19
[4]: 3
>reportValues[new Guid("1637D8A2-4248-4275-865D-558DE84AEDFD")][11]
"System.ArgumentOutOfRangeException" in mscorlib.dll
where [0]: 206.47661000000002 is actually have has PropertyId = 11. Information about PropertyId does not save anywhere. For now I apply a temporary solution
data[key.FormatId].Add(Tuple.Create(key.PropertyId, propValue.Value));,
e.i. simply turn it to tuple with PropertyId. Of course it is not proper way, just to make my current task can be done.
I also have stumbled upon a bug, I think it is better to open another issue for it. Thank you for your attention and supporting this library.