当前位置: 首页>>代码示例>>Python>>正文


Python InterfaceKit.getOutputState方法代码示例

本文整理汇总了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
开发者ID:WasatchPhotonics,项目名称:Foreman,代码行数:104,代码来源:ControlPower.py

示例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):
#.........这里部分代码省略.........
开发者ID:WasatchPhotonics,项目名称:Phidgeter,代码行数:103,代码来源:relay.py


注:本文中的Phidgets.Devices.InterfaceKit.InterfaceKit.getOutputState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。