try to use a PhidgetBridge 4-Input: getVoltageRatio raise PhidgetException(result)

Supporting 2.7 and 3.2+
Post Reply
fajitas23
Phidgetsian
Posts: 9
Joined: Sun Jun 10, 2018 5:33 am
Contact:

try to use a PhidgetBridge 4-Input: getVoltageRatio raise PhidgetException(result)

Post by fajitas23 »

Hi, I'm trying to read the voltage ratio from a 1046_0B 'PhidgetBridge 4-Input'
https://www.phidgets.com/?tier=3&catid= ... rodid=1027
in Python.

The code example from
https://www.phidgets.com/?tier=3&catid= ... rodid=1027
works fine. The voltage ratio is printed to the console and changes when applying forces to my load cell.

Code: Select all

from Phidget22.Phidget import *
from Phidget22.Devices.VoltageRatioInput import *
import time

def onVoltageRatioChange(self, voltageRatio):
	print("VoltageRatio: " + str(voltageRatio))

def main():
	voltageRatioInput0 = VoltageRatioInput()

	voltageRatioInput0.setOnVoltageRatioChangeHandler(onVoltageRatioChange)

	voltageRatioInput0.openWaitForAttachment(5000)

	time.sleep(5)

	voltageRatioInput0.close()

main()
However, I would like to read the voltage directly, instead of relying on a event. The API function for this seems to be getVoltageRatio()
However, I can not run the example from the API docu
https://www.phidgets.com/?view=api&prod ... ang=Python

Code: Select all

from Phidget22.Phidget import *
from Phidget22.Devices.VoltageRatioInput import *

ch = VoltageRatioInput()
ch.openWaitForAttachment(1000)

voltageRatio = ch.getVoltageRatio()
print("VoltageRatio: " + str(voltageRatio))

ch.close()
The error message is
\Phidget22\Devices\VoltageRatioInput.py", line 306, in getVoltageRatio
raise PhidgetException(result)

line 7, in <module>
voltageRatio = ch.getVoltageRatio()
Any help appreciated
fraser
Engineering
Posts: 324
Joined: Thu Nov 19, 2009 4:41 pm
Contact:

Re: try to use a PhidgetBridge 4-Input: getVoltageRatio raise PhidgetException(result)

Post by fraser »

Use a try block to catch the exception and print out the error message. That will give you a better idea what is going wrong. If I had to guess though, you could try waiting a bit after the open call before fetching the ratio value. After an open call it can sometimes take a bit of time for the device to get the first value ready for polling. Just sleep or something for 50 ms to see if that helps.
User avatar
Patrick
Lead Developer
Posts: 3403
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: try to use a PhidgetBridge 4-Input: getVoltageRatio raise PhidgetException(result)

Post by Patrick »

You can also try giving waitForAttachment a longer timeout - it will try to wait for initial state to come in assuming you're on a newer version of the library and the input in question is receiving a valid signal.

-Patrick
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests