本文整理汇总了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.setSensorChangeTrigger方法的典型用法代码示例。如果您正苦于以下问题:Python InterfaceKit.setSensorChangeTrigger方法的具体用法?Python InterfaceKit.setSensorChangeTrigger怎么用?Python InterfaceKit.setSensorChangeTrigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phidgets.Devices.InterfaceKit.InterfaceKit
的用法示例。
在下文中一共展示了InterfaceKit.setSensorChangeTrigger方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InterfaceSource
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 别名]
class InterfaceSource(Source):
def __init__(self):
Source.__init__(self)
try:
self._device = InterfaceKit()
except RuntimeError as e:
print("Runtime Error: %s" % e.message)
try:
self._device.openPhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.detail))
self._device.setOnSensorChangeHandler(self.sensor_changed)
print("Phidget: Waiting for Connection")
self._device.waitForAttach(10000)
self._device.setSensorChangeTrigger(0, 0)
self._device.setDataRate(0, 1)
print("Phidget: Connected")
def sensor_changed(self, e):
if self.sink is not None:
self.sink([e.value])
示例2: PhidgetsEventThread
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 别名]
class PhidgetsEventThread(QtCore.QThread):
def __init__(self, parent=None):
super(PhidgetsEventThread, self).__init__(parent)
try:
self.interfaceKit = InterfaceKit()
self.interfaceKit.openPhidget()
self.interfaceKit.setOnAttachHandler(self.interfaceKitAttachedEvent)
self.interfaceKit.setOnDetachHandler(self.interfaceKitDetachEvent)
self.interfaceKit.setOnErrorhandler(self.interfaceKitErrorSlot)
self.interfaceKit.setOnInputChangeHandler(self.interfaceKitInputChangedEvent)
self.interfaceKit.setOnOutputChangeHandler(self.interfaceKitOutputChangedEvent)
self.interfaceKit.setOnSensorChangeHandler(self.interfaceKitSensorChangedEvent)
except RuntimeError as e:
print "Runtime Exception: %s" % (e.details)
print "Exiting..."
sys.exit(1)
except PhidgetException as e:
print "Phidget Exception %i: %s" % (e.code, e.details)
print "Exiting..."
sys.exit(1)
#===========================================================================
# On Interfacekit events, emit signals to main thread for updating GUI
#===========================================================================
def interfaceKitAttachedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitAttachedSlot"), event)
def interfaceKitDetachEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitDetachedSlot"), event)
def interfaceKitErrorSlot(self, event):
self.emit(QtCore.SIGNAL("interfaceKitErrorSlot"), event)
def interfaceKitInputChangedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitInputChangedSlot"), event)
def interfaceKitOutputChangedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitOutputChangedSlot"), event)
def interfaceKitSensorChangedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitSensorChangedSlot"), event)
def setSensorSensitivity(self, value):
try:
for i in range(self.interfaceKit.getSensorCount()):
self.interfaceKit.setSensorChangeTrigger(i, value)
except PhidgetException as e:
print "Could not set sensitivity: %s" % e.details
def run(self):
self.exec_()
示例3: Node
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 别名]
#.........这里部分代码省略.........
cls=self.__class__.__name__
)
def __conform__(self, protocol):
return json.dumps(self.json(), cls=ComplexEncoder)
def displayDeviceInfo(self):pass
#Event Handler Callback Functions
def inferfaceKitAttached(self, e):
attached = e.device
self.logger.info("InterfaceKit %i Attached!" % (attached.getSerialNum()))
def interfaceKitDetached(self, e):
detached = e.device
self.logger.info("InterfaceKit %i Detached!" % (detached.getSerialNum()))
def interfaceKitError(self, e):
try:
if e.eCode not in (36866,):
source = e.device
self.logger.info("InterfaceKit %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
except PhidgetException as e:
self.logger.exception(e)
def interfaceKitInputChanged(self, e):
input = self.get_input(e.index)
if not input: return
val = input.do_conversion(e.value)
ob = input.json()
self.publish(ob)
self.logger.info("%s Input: %s" % (input.display, val))
def interfaceKitSensorChanged(self, e):
sensor = self.get_sensor(e.index)
if not sensor: return
val = sensor.do_conversion(float(e.value)) if sensor else 0
ob = sensor.json()
self.publish(ob)
self.logger.info("%s Sensor: %s" % (sensor.display, val))
def interfaceKitOutputChanged(self, e):
output = self.get_output(e.index)
if not output: return
output.current_state = e.state
ob = output.json()
self.publish(ob)
self.logger.info("%s Output: %s" % (output.display, output.current_state))
def run(self):
if LIVE: self.init_kit()
while True: gevent.sleep(.1)
def init_kit(self):
try:
self.interface_kit.setOnAttachHandler(self.inferfaceKitAttached)
self.interface_kit.setOnDetachHandler(self.interfaceKitDetached)
self.interface_kit.setOnErrorhandler(self.interfaceKitError)
self.interface_kit.setOnInputChangeHandler(self.interfaceKitInputChanged)
self.interface_kit.setOnOutputChangeHandler(self.interfaceKitOutputChanged)
self.interface_kit.setOnSensorChangeHandler(self.interfaceKitSensorChanged)
except PhidgetException as e:
self.logger.exception(e)
self.logger.info("Opening phidget object....")
try:
self.interface_kit.openPhidget()
except PhidgetException as e:
self.logger.exception(e)
self.logger.info("Waiting for attach....")
try:
self.interface_kit.waitForAttach(10000)
except PhidgetException as e:
self.logger.exception(e)
try:
self.interface_kit.closePhidget()
except PhidgetException as e:
self.logger.exception(e)
self.logger.info("Exiting....")
exit(1)
self.logger.info("Exiting....")
else:
self.displayDeviceInfo()
self.logger.info("Initializing Sensors")
for i in range(self.interface_kit.getSensorCount()):
try:
sensor = self.get_sensor(i)
if sensor:
self.logger.info("Setting Up: %s" % sensor.display)
self.logger.info("Change: %s" % sensor.change)
self.logger.info("Data Rate: %s" % sensor.data_rate)
self.interface_kit.setSensorChangeTrigger(i, sensor.change)
self.interface_kit.setDataRate(i, sensor.data_rate)
except PhidgetException as e:
self.logger.exception(e)
示例4: SitwPhidgetsKey
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setSensorChangeTrigger [as 别名]
#.........这里部分代码省略.........
print("Waiting for attach....")
try:
self.interfaceKit.waitForAttach(10000)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
self.closePhidgets()
else:
self.displayDeviceInfo()
#get sensor count
try:
self.ChannelCount = self.interfaceKit.getSensorCount()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
self.closePhidgets()
sitwPara.KeyCount = 0 #no sensor has been detected
self.prtMsg(' ****** No sensor has been detected !!!\n')
print("Setting the data rate for each sensor index to 4ms....")
for i in range(sitwPara.KeyCount):
try:
self.interfaceKit.setDataRate(i, 4)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
### depends on the low light performance of the sensor
print("Setting the sensitivity for each sensor index to ???....")
for i in range(sitwPara.KeyCount):
try:
self.interfaceKit.setSensorChangeTrigger(i, 2) #~~~~*YL*~~~~
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
def closePhidgets(self):
#print("Press Enter to quit....")
#chr = sys.stdin.read(1)
#print("Closing...")
try:
self.interfaceKit.closePhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
#print("Done.")
#exit(1)
def initKeys(self):
self.KeyPressed = ''
self.ListValMat = []
for i in range(sitwPara.KeyCount):
self.ListValEnv = []
for j in range(self.SampleCount):
self.ListValEnv.append(self.readSensorValue(i))
self.ListValMat.append(self.ListValEnv)