setSensorType

Supporting 2.7 and 3.2+
Post Reply
headcrash
Phidgetsian
Posts: 8
Joined: Fri Aug 11, 2017 10:46 am
Contact:

setSensorType

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

Re: setSensorType

Post 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
theque42
Fresh meat
Posts: 4
Joined: Mon Jan 29, 2018 11:24 am
Contact:

Re: setSensorType

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests