Get sensor info from libs

Supporting 2.7 and 3.2+
Post Reply
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Get sensor info from libs

Post 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
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Get sensor info from libs

Post 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?
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: Get sensor info from libs

Post 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.
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: Get sensor info from libs

Post 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.
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: Get sensor info from libs

Post 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.
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Get sensor info from libs

Post 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
berkinet
Phidget Mastermind
Posts: 212
Joined: Thu Sep 17, 2009 12:17 pm
Contact:

Re: Get sensor info from libs

Post by berkinet »

Perfect!
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests