Page 1 of 1

BridgeGain not getting set

Posted: Wed Jul 03, 2019 10:02 am
by zdwiel
I've modified the VoltageRatioInput python example to set the Bridge Gain, but it doesn't seem to be actually setting. Here is the code and logs:

Code: Select all

# inside the onAttachHandler
print('bridge gain before', ph.getBridgeGain())
ph.setBridgeGain(BridgeGain.BRIDGE_GAIN_128)
print('bridge gain after', ph.getBridgeGain())

Code: Select all

# log:
bridge gain before 8
bridge gain after 8
After this, the code goes on to log some voltage ratios, so I know it is communicating with the hub ok.

Re: BridgeGain not getting set

Posted: Wed Jul 03, 2019 10:16 am
by zdwiel
Ok, so I figured out the problem. When the Phidgets documentation lists BridgeGain as an Enumeration, I had assumed it was a python Enum. In fact, they are just constants. The problem is that printing out the "enumeration" BridgeGain.BRIDGE_GAIN_128 displays the value 8. It would be nice if the enumeration could be more pythonic. For example from the python3 enum documentation:

Code: Select all

>>> from enum import Enum
>>> class Color(Enum):
...     RED = 1
...     GREEN = 2
...     BLUE = 3
>>> print(Color.RED)
Color.RED
>>> member = Color.RED
>>> member.name
'RED'
>>> member.value
1