Page 1 of 1

setSensorType

Posted: Sat Aug 19, 2017 4:33 pm
by headcrash
I've run into an issue using the Phidget22 API (Python 2.7) setSensorType method. It works ok for me, but I have found I need a half-second sleep delay after using it before I can use a getSensorValue.

Without a delay I get a "Phidget Exception 51: Unknown or Invalid Value" error.

It does the same under both Linux and Windows. I have also tried it on both a 1018 Interface and a new VINT Hub with the same result.

No real surprise, but I get the same exact exception error if I use getSensorValue without first doing a setSensorType.

I'm wondering if this is normal? Also seems a little odd the device has to be attached before doing a setSensorType.

In any case, I do have my home heating system program converted over to the Phidget22 API and all is working ok.

Here's quick test.py that demonstrates the getSensorType issue by commenting out sleep(.5)

Code: Select all

from time import sleep
from Phidget22.Phidget import *
from Phidget22.Devices.VoltageRatioInput import *
    
x = VoltageRatioInput()
x.setDeviceSerialNumber(495394)
x.setIsHubPortDevice(1)
x.setHubPort(2)

x.openWaitForAttachment(5000)

x.setSensorType(0x2be8)
sleep(.5)

try:
    print x.getSensorValue()
    
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Press Enter to Exit...\n")
    readin = sys.stdin.read(1)
    exit(1)

x.close()

Re: setSensorType

Posted: Mon Aug 21, 2017 10:23 am
by Patrick
The delay is not normal, but we do know about this issue so it will be fixed.

As for setSensorType - this need to be called after attach because not a VoltageInput channels support sensor type, and we need an attach to know whether to return unsupported.

Generally, the attach event is a good place to put all your set up for a channel, as this covers the case of an unexpected detach-reattach.

-Patrick

Re: setSensorType

Posted: Thu Feb 08, 2018 2:25 pm
by theque42
It would be really nice if the API documentation for setSensorType mentioned that you have to set it AFTER attach.

I've been going crazy here... :roll:

At least it doesnt, for python.