I am using a phidget bridge input in order to receive data from many load cell, then I'd like to make computation between the different signal I receive.
Here is what I tried but I got an error :
t = channel0 + channel1
UnboundLocalError: local variable 'channel0' referenced before assignment
Code: Select all
A0 = 1
B0 = 0
offset = 0 # 10.45
channel0 = 0
channel1 = 0
def onVoltageRatioChange(self, voltageRatio):
Masse = (voltageRatio - (B0) ) / (A0) + offset
if(self.getChannel() == 0):
channel0 = voltageRatio
if(self.getChannel() == 1):
channel1 = voltageRatio
t = channel0 + channel1
print(t)
def main():
voltageRatioInput0 = VoltageRatioInput()
voltageRatioInput1 = VoltageRatioInput()
voltageRatioInput2 = VoltageRatioInput()
voltageRatioInput3 = VoltageRatioInput()
voltageRatioInput0.setChannel(0)
voltageRatioInput1.setChannel(1)
voltageRatioInput2.setChannel(2)
voltageRatioInput3.setChannel(3)
voltageRatioInput0.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
voltageRatioInput1.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
voltageRatioInput2.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
voltageRatioInput3.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
voltageRatioInput0.openWaitForAttachment(TIME_OUT)
voltageRatioInput1.openWaitForAttachment(TIME_OUT)
voltageRatioInput2.openWaitForAttachment(TIME_OUT)
voltageRatioInput3.openWaitForAttachment(TIME_OUT)
voltageRatioInput0.setDataInterval(DATA_INTERVAL)
voltageRatioInput1.setDataInterval(DATA_INTERVAL)
voltageRatioInput2.setDataInterval(DATA_INTERVAL)
voltageRatioInput3.setDataInterval(DATA_INTERVAL)
while True:
time.sleep(10)
voltageRatioInput0.close()
voltageRatioInput1.close()
voltageRatioInput2.close()
voltageRatioInput3.close()
main()