本文整理匯總了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.getOutputState方法的典型用法代碼示例。如果您正苦於以下問題:Python InterfaceKit.getOutputState方法的具體用法?Python InterfaceKit.getOutputState怎麽用?Python InterfaceKit.getOutputState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phidgets.Devices.InterfaceKit.InterfaceKit
的用法示例。
在下文中一共展示了InterfaceKit.getOutputState方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PowerControl
# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getOutputState [as 別名]
#.........這裏部分代碼省略.........
try:
self.interface.closePhidget()
except PhidgetException as e:
log.critical("Close Exc. %i: %s" % (e.code, e.details))
return 0
return 1
#Event Handler Callback Functions
def interfaceAttached(self, e):
attached = e.device
#log.info("interface %i Attached!" % (attached.getSerialNum()))
def interfaceDetached(self, e):
detached = e.device
log.info("interface %i Detached!" % (detached.getSerialNum()))
def interfaceError(self, e):
try:
source = e.device
log.critical("Interface %i: Phidget Error %i: %s" % \
(source.getSerialNum(), e.eCode, e.description))
except PhidgetException as e:
log.critical("Phidget Exception %i: %s" % (e.code, e.details))
def close_phidget(self):
try:
self.interface.closePhidget()
except PhidgetException as e:
log.critical("Phidget Exception %i: %s" % (e.code, e.details))
return 0
return 1
def change_relay(self, relay=0, status=0):
''' Toggle the status of the phidget relay line to low(0) or high(1)'''
try:
self.interface.setOutputState(relay, status)
#self.emit_line_change(relay, status)
except Exception as e:
log.critical("Problem setting relay on %s" % e)
return 0
return 1
''' Convenience functions '''
def zero_on(self):
#log.info("Zero relay on")
return self.change_relay(relay=ZERO_RELAY, status=1)
def zero_off(self):
return self.change_relay(relay=ZERO_RELAY, status=0)
def one_on(self):
#log.info("one relay on")
return self.change_relay(relay=ONE_RELAY, status=1)
def one_off(self):
return self.change_relay(relay=ONE_RELAY, status=0)
def two_on(self):
#log.info("two relay on")
return self.change_relay(relay=TWO_RELAY, status=1)
def two_off(self):
return self.change_relay(relay=TWO_RELAY, status=0)
def three_on(self):
#log.info("two relay on")
return self.change_relay(relay=THREE_RELAY, status=1)
def three_off(self):
return self.change_relay(relay=THREE_RELAY, status=0)
def toggle_line(self, line=0):
''' Read the internal state of the specified line, then set the opposite
state for a toggle function'''
if not self.open_phidget():
log.critical("Problem opening phidget")
return 0
try:
curr_state = self.interface.getOutputState(line)
except Exception as e:
log.critical("Problem getting relay on %s" % e)
self.close_phidget()
return 0
if not self.change_relay(line, not curr_state):
log.critical("Problem changing relay")
return 0
if not self.close_phidget():
log.criticla("Problem closing phidget")
return 0
return 1
示例2: Relay
# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getOutputState [as 別名]
class Relay(object):
""" Relay class wraps language around the 1014_2 -
PhidgetInterfaceKit 0/0/4 4 relay device. Also works for
SSR relays."""
def __init__(self, in_serial=None):
# http://victorlin.me/posts/2012/08/26/\
# good-logging-practice-in-python
self.log = logging.getLogger(__name__)
if in_serial != None:
# On odroid C1, int conversion raises null byte in argument
# strip out the null byte first
in_serial = in_serial.strip('\0')
self._serial = int(in_serial)
else:
self._serial = None
self.log.debug("Start of phidgeter with serial: %s" % in_serial)
def change_relay(self, relay=0, status=0):
""" Toggle the status of the phidget relay line to low(0) or
high(1) status
"""
self.interface.setOutputState(relay, status)
return 1
def open_phidget(self):
self.log.debug("Attempting to open phidget")
self.interface = InterfaceKit()
if self._serial != None:
self.log.debug("Attempt to open serial: %s" % self._serial)
self.interface.openPhidget(self._serial)
else:
self.log.debug("Attempt to open first found")
self.interface.openPhidget()
wait_interval = 10300
self.log.debug("Wait for attach %sms" % wait_interval)
self.interface.waitForAttach(wait_interval)
self.log.info("Opened phidget")
return 1
def close_phidget(self):
self.log.debug("Attempting to close phidget")
self.interface.closePhidget()
self.log.info("Closed phidget")
return 1
def open_operate_close(self, relay, status):
""" Open the phidget, change the relay to status, close phidget.
"""
self.open_phidget()
result = self.change_relay(relay, status)
self.close_phidget()
return result
def open_toggle_close(self, relay):
""" Find the current status of the specified relay, and set the
status to the opposite.
"""
self.open_phidget()
curr_state = self.interface.getOutputState(relay)
result = self.change_relay(relay, not curr_state)
self.close_phidget()
return result
def zero_on(self):
return self.open_operate_close(relay=0, status=1)
def zero_off(self):
return self.open_operate_close(relay=0, status=0)
def zero_toggle(self):
return self.open_toggle_close(relay=0)
def one_on(self):
return self.open_operate_close(relay=1, status=1)
def one_off(self):
return self.open_operate_close(relay=1, status=0)
def one_toggle(self):
return self.open_toggle_close(relay=1)
def two_on(self):
return self.open_operate_close(relay=2, status=1)
def two_off(self):
return self.open_operate_close(relay=2, status=0)
def two_toggle(self):
return self.open_toggle_close(relay=2)
def three_on(self):
#.........這裏部分代碼省略.........