Page 1 of 1
Get sensor info from libs
Posted: Tue Aug 03, 2021 11:04 am
by berkinet
Is there a way to get basic product info from the libs for a given Phidget product? For example, min & max allowed data interval, min and max allowed sensor values, formula, etc.
So for example, for a 3502 Current sensor, I would get back something like:
- Product: SENSOR_TYPE_3502
Formula: (voltage / 0.1, 4); // RMS Amps'
Max input value: (sensorValue < 50.0)); // RMS Amps',
Unit: PHIDUNIT_AMPERE
Plus anything else
BTW, thanks to Patrick I now know where this info is located for regular analog/voltageRatio sensors. But, I was wondering if there was a way to get it dynamically.
Thanks
Re: Get sensor info from libs
Posted: Tue Aug 03, 2021 3:44 pm
by mparadis
You might be able to get the "Product" line from iterating on the VoltageSensorType and VoltageRatioSensorType enums (although I don't know how to do this in python).
The formula is baked into the libraries in the file that Patrick showed you, and it's not exposed in the API so I don't think you can get it.
The unit could possibly be grabbed by calling getSensorUnit after setting the sensor type but that seems like a pain.
I have to say, I'm getting curious as to what kind of program you're writing based on the questions you're asking. A custom Phidget Control Panel of some sort?
Re: Get sensor info from libs
Posted: Tue Aug 03, 2021 5:30 pm
by berkinet
I am writing a plug-in for the Indigo home automation system.
https://www.indigodomo.com/
I did one for Phidgets21 several years ago and am finally getting around to doing one for P22.
Re: Get sensor info from libs
Posted: Tue Aug 03, 2021 5:43 pm
by berkinet
… and thanks for the response. The key info I need is the unit (fir data presentation) and range (for configuration validation), and I have already scraped that from the source. I was just wondering if there might be a better way to get it.
Re: Get sensor info from libs
Posted: Thu Aug 05, 2021 3:08 pm
by berkinet
And, a follow-on question. For voltage and voltageRatio devices connected to standard (non-VINT) ports, is it possible to getSensorUnit() before the device has a sensor change trigger event. Example. I open a current sensing phidget on a circuit that is currently off. I would like to know the sensorUnit will be "ampere," and, indeed, if I wait for a sensor change event I will get that information. But, I would like to get it earlier. If there were a way to force a sensor change event, that would be perfect. But, I can't find it. Calling getSensorUnit() before the first sensor change results in...
Code: Select all
VoltageInput.py", line 191, in getSensorUnit
raise PhidgetException(result)
PhidgetException: PhidgetException 0x33 (Unknown or Invalid Value)
The value is unknown.
I know this information is available in the libs as previously discussed. But, if there were a way to get it from the device, that would be much cleaner.
Re: Get sensor info from libs
Posted: Mon Aug 09, 2021 10:35 am
by Patrick
If you set your sensor type in the attach handler, then the initial event will initialize the sensor unit/value. As long as the initial value is in range of your sensor - you will always get an initial sensor event after attach.
Also, any time you change the sensor type, the library sends a sensor event right away, so you can listen for that event.
-Patrick
Re: Get sensor info from libs
Posted: Mon Aug 09, 2021 10:41 am
by berkinet
Perfect!