with PhidgetBridge 4 input, I am using the setDataInterval() API to set the sample rate of the acquisition.
I am trying to run the code inside a while loop to acquire the data for long time. I have set the frequency of 1 Hz but when I print the result with the time it appears to not be 1 Hz but 4 Hz (256 ms between each point)
Here is my code :
Code: Select all
from Phidget22.Phidget import *
from Phidget22.Devices.VoltageRatioInput import *
import time
start_time = round(time.time()*1000)
def onVoltageRatioChange(self, voltageRatio):
print(str(round(time.time()*1000) - start_time) + " : " + str(voltageRatio))
def main():
while True:
voltageRatioInput0 = VoltageRatioInput()
voltageRatioInput0.setChannel(1)
voltageRatioInput0.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
voltageRatioInput0.openWaitForAttachment(5000)
voltageRatioInput0.setDataInterval(1000)
voltageRatioInput0.close()
main()
Code: Select all
1888 : -0.000284235924
2144 : -0.000284283422
2400 : -0.000284277834
2656 : -0.000284262002
2912 : -0.000284207053
3168 : -0.000284248963
3424 : -0.000284295529
3680 : -0.000284306705
3936 : -0.000284236856
The code :
Code: Select all
from Phidget22.Phidget import *
from Phidget22.Devices.VoltageRatioInput import *
import time
start_time = round(time.time()*1000)
def onVoltageRatioChange(self, voltageRatio):
print(str(round(time.time()*1000) - start_time) + " : " + str(voltageRatio))
def main():
#while True:
voltageRatioInput0 = VoltageRatioInput()
voltageRatioInput0.setChannel(1)
voltageRatioInput0.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
voltageRatioInput0.openWaitForAttachment(5000)
voltageRatioInput0.setDataInterval(1000)
time.sleep(10)
voltageRatioInput0.close()
main()
Code: Select all
597 : -0.000283599
1117 : -0.000283599
2157 : -0.000284255482
3117 : -0.000284262933
4117 : -0.000284257345
5117 : -0.000284262002
6117 : -0.000284257345
7117 : -0.000284252688
8117 : -0.000284258276
9117 : -0.000284264795
10117 : -0.000284259208