I'm using Phidget 8/8/8 board to acquire temperature and RH signal from a sensor. I would like to have a 10-second sampling interval, but I only can specify the interval as 1ms up to 1000ms by the statement-setDataInterval(). What I want is 10 second sampling rate. I had try to use time.sleep(10) after the print function, but it doesn't work. For example, the second value it printed after 10 second is the value it sampled after default sampling interval (~250 ms) from the beginning. It seems I just delay the print function rather than changing the sampling interval.
Thanks in advance.
I use the sampling code downloaded from the phidget website:
Code: Select all
import sys
import time
from Phidget22.Devices.VoltageInput import *
from Phidget22.PhidgetException import *
from Phidget22.Phidget import *
from Phidget22.Net import *
try:
ch = VoltageInput()
ch.setDeviceSerialNumber(437701)
ch.setChannel(1)
#set channel 1 as the input voltage port
#ch.setHubPort(1)
except RuntimeError as e:
print("Runtime Exception %s" % e.details)
print("Press Enter to Exit...\n")
readin = sys.stdin.read(1)
exit(1)
def VoltageInputAttached(e):
try:
attached = e
print("\nAttach Event Detected (Information Below)")
print("===========================================")
print("Library Version: %s" % attached.getLibraryVersion())
print("Serial Number: %d" % attached.getDeviceSerialNumber())
print("Channel: %d" % attached.getChannel())
print("Channel Class: %s" % attached.getChannelClass())
print("Channel Name: %s" % attached.getChannelName())
print("Device ID: %d" % attached.getDeviceID())
print("Device Version: %d" % attached.getDeviceVersion())
print("Device Name: %s" % attached.getDeviceName())
print("Device Class: %d" % attached.getDeviceClass())
print("\n")
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Press Enter to Exit...\n")
readin = sys.stdin.read(1)
exit(1)
def VoltageInputDetached(e):
detached = e
try:
print("\nDetach event on Port %d Channel %d" % (detached.getHubPort(), detached.getChannel()))
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Press Enter to Exit...\n")
readin = sys.stdin.read(1)
exit(1)
def ErrorEvent(e, eCode, description):
print("Error %i : %s" % (eCode, description))
def VoltageChangeHandler(e, voltage):
print("Voltage: %f" % voltage)
time.sleep(10)
def SensorChangeHandler(e, sensorValue, sensorUnit):
print("Sensor Value: %f" % sensorValue)
try:
ch.setOnAttachHandler(VoltageInputAttached)
ch.setOnDetachHandler(VoltageInputDetached)
ch.setOnErrorHandler(ErrorEvent)
ch.setOnVoltageChangeHandler(VoltageChangeHandler)
ch.setOnSensorChangeHandler(SensorChangeHandler)
print("Waiting for the Phidget VoltageInput Object to be attached...")
ch.openWaitForAttachment(5000)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Press Enter to Exit...\n")
readin = sys.stdin.read(1)
exit(1)
print("Gathering data for 20 seconds...")
time.sleep(20)
try:
ch.close()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Press Enter to Exit...\n")
readin = sys.stdin.read(1)
exit(1)
print("Closed VoltageInput device")
exit(0)