我正在使用 phidget bridge 4 输入来读取称重传感器。我正在尝试以 1 Hz 的频率获取数据,因此我time.sleep(1)
在 while 循环内根据需要每秒读取数据。为了确保我处于 1 Hz,我正在打印我的值,而actuel time - the time of the beginning of the script
它在每个循环中似乎超过 1000 毫秒。
代码 :
from Phidget22.Phidget import *
from Phidget22.Devices.VoltageRatioInput import *
import time
start_time = round(time.time()*1000)
A1 = -6.147057832630E-06
B1 = -0.000288253826519
def onVoltageRatioChange(self, voltageRatio):
Masse = (voltageRatio - (B1) ) / (A1)
self.masse = Masse
def runningChannel(channel, dataInterval):
voltageRatioInput = VoltageRatioInput()
voltageRatioInput.setChannel(channel)
voltageRatioInput.setOnVoltageRatioChangeHandler(onVoltageRatioChange)
voltageRatioInput.openWaitForAttachment(5000)
voltageRatioInput.close()
return voltageRatioInput.masse
if __name__ == '__main__':
while True:
print(str(round(time.time()*1000) - start_time) + " : " + str(runningChannel(1, 1000)))
time.sleep(1)
安慰 :
0 : -0.6478727917378451
1353 : -0.7766034823455521
2530 : -0.648175863557032
3914 : -0.7572446275502878
5089 : -0.6493878254748858
6474 : -0.6990053837124224
7650 : -0.6493878254748858
9033 : -0.8542015809786906
10209 : -0.6509030218913868