Page 1 of 1

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

Posted: Thu Feb 06, 2020 12:29 pm
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

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

Posted: Mon Feb 10, 2020 9:27 am
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.

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

Posted: Mon Feb 10, 2020 2:37 pm
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