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


Python InterfaceKit.closePhidget方法代码示例

本文整理汇总了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.closePhidget方法的典型用法代码示例。如果您正苦于以下问题:Python InterfaceKit.closePhidget方法的具体用法?Python InterfaceKit.closePhidget怎么用?Python InterfaceKit.closePhidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phidgets.Devices.InterfaceKit.InterfaceKit的用法示例。


在下文中一共展示了InterfaceKit.closePhidget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SimplePhidget

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
class SimplePhidget():

    def __init__(self):     
        try:
            self.interfaceKit = InterfaceKit()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            exit(1)

        print("Connecting to Phidget.")

        try:
            self.interfaceKit.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            exit(1)

        print("Connection opened.")

        try:
            self.interfaceKit.waitForAttach(10000)
        except PhidgetException as e:
            try:
                self.interfaceKit.closePhidget()
            except PhidgetException as e:
                exit(1)
            exit(1)
        print("Attached to phidget interface.")

    def getSensorValue(self, sensor):
        return self.interfaceKit.getSensorValue(sensor)
开发者ID:veiset,项目名称:home-pie,代码行数:33,代码来源:read_sensor_data.py

示例2: Interface

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
class Interface(Model):
    def __init__(self, serial_number):
        self._phidget = InterfaceKit()
        self._serial_number = serial_number
        self._is_initialized = False
    
    def initialize(self):
        if not self._is_initialized:
            self._phidget.openPhidget(serial = self._serial_number)
            self._phidget.waitForAttach(ATTACH_TIMEOUT)
            self._phidget.setRatiometric(False) #note the default is True!
            self._is_initialized = True
            
    def identify(self):
        if not self._is_initialized:
            self.initialize()
        name = self._phidget.getDeviceName()
        serial_number = self._phidget.getSerialNum()
        return "%s, Serial Number: %d" % (name, serial_number)
    
    def read_sensor(self, index):
        """ reads the raw value from the sensor at 'index' 
            returns integer in range [0,4095]
        """
        if not self._is_initialized:
            self.initialize()
        return self._phidget.getSensorRawValue(index)
    
    def read_all_sensors(self):
        """ reads all the sensors raw values, indices 0-7
            returns list of 8 integers in range [0,4095]
        """
        if not self._is_initialized:
            self.initialize()
        values = []
        for i in range(8):
            values.append(self.read_sensor(i))
        return values    
    
    def read_digital_input(self,index):
        """ reads the digital input at 'index' 
            returns True if grounded, False if open (pulled-up to 5V)
        """
        if not self._is_initialized:
            self.initialize()
        return self._phidget.getInputState(index)
    
    def write_digital_output(self,index,state):
        if not self._is_initialized:
            self.initialize()
        return self._phidget.setOutputState(index,state)
    
    def shutdown(self):
        if not self._is_initialized:
            self.initialize()
        self._phidget.closePhidget()
        self._is_initialized = False
    
    def __del__(self):
        self.shutdown()
开发者ID:cversek,项目名称:yes-o2ab,代码行数:62,代码来源:kit1018.py

示例3: instanciarIK

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
 def instanciarIK (self, nroSerie):
     """
     Método utilizado para instanciar un objeto de tipo InterfaceKit de la API de Phidgets, que permite interactuar con la placa controladora y sus puertos"""
     try:
         ik= InterfaceKit()
         ik.openRemoteIP(self.__ipWS, self.__puertoWS, nroSerie)
         ik.waitForAttach(5000)
         return ik
     except :
         ik.closePhidget()
         return None
开发者ID:dbayure,项目名称:SGIA,代码行数:13,代码来源:Herramientas.py

示例4: setup_interfaceKit

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
def setup_interfaceKit():
    #Create an interfacekit object
    try:
        interfaceKit = InterfaceKit()
    except RuntimeError as e:
        print("Runtime Exception: %s" % e.details)
        print("Exiting....")
        exit(1)

    try:
        interfaceKit.setOnAttachHandler(inferfaceKitAttached)
        interfaceKit.setOnDetachHandler(interfaceKitDetached)
        interfaceKit.setOnErrorhandler(interfaceKitError)
        interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
        interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
        interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    print("Opening phidget object....")

    try:
        #interfaceKit.openPhidget()
        interfaceKit.openRemoteIP(IP, port=5001)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    print("Waiting for attach....")

    try:
        interfaceKit.waitForAttach(10000)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        try:
            interfaceKit.closePhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        print("Exiting....")
        exit(1)
    return interfaceKit
开发者ID:psas,项目名称:launch-tower-comm,代码行数:48,代码来源:kv-ph-demo.py

示例5: __init__

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
class pumpUSB:  # pragma: no cover
    def __init__(self):
        print ("Initiating pumps")
        try:
            self.interfaceKit = InterfaceKit()
        except RuntimeError as e:
            print ("Runtime Exception a: %s" % e.details)
            print ("Exiting....")
            exit(1)
        try:
            self.interfaceKit.openPhidget()
        except PhidgetException as e:
            print ("Phidget Exception b %i: %s" % (e.code, e.details))
            print ("Exiting....")
            exit(1)

        try:
            self.interfaceKit.waitForAttach(1000)
        except PhidgetException as e:
            print ("Phidget Exception c %i: %s" % (e.code, e.details))
            raise Exception("Timeout")
            try:
                self.interfaceKit.closePhidget()
            except PhidgetException as e:
                print ("Phidget Exception d %i: %s" % (e.code, e.details))
                print ("Exiting....")
                exit(1)
        self.pumplist = []
        for i in range(0, 4):
            self.pumplist.append(onePump(self.interfaceKit, i))
        print ("Pumps ready")

    def getPump(self, index):
        return self.pumplist[index]

    def getSwitch(self, index):
        """ yes it is the same as getPump, standard name use """
        return self.pumplist[index]

    def close(self):
        self.interfaceKit.closePhidget()
开发者ID:cloudymike,项目名称:hopitty,代码行数:43,代码来源:pumpUSB.py

示例6: set_bbias

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
def set_bbias(state):
    """Set back bias to state"""

    state_dict = {"On" : True,
                  "Off" : False}
    setting = state_dict[state]

    ## Attach to Phidget controller
    relay = InterfaceKit()
    relay.openPhidget()
    relay.waitForAttach(10000)

    ## Check if successful
    if relay.isAttached():
        print "Done!"
    else:
        print "Failed to connect to Phidget controller"

    ## Set output to 0 and close
    relay.setOutputState(0, setting)
    print "BSS is now {0}".format(state)
    relay.closePhidget()

    return
开发者ID:Snyder005,项目名称:ccdcontroller,代码行数:26,代码来源:ccdsetup.py

示例7: print

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
    print("Exiting....")
    exit(1)

#if not interfaceKitHUB.isAttachedToServer():
#    sleep(2)

print("Waiting for attach....")

try:
    interfaceKitHUB.waitForAttach(10000)
    #interfaceKitLCD.waitForAttach(10000)

except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        interfaceKitHUB.closePhidget()
        #interfaceKitLCD.closePhidget()
        
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    displayDeviceInfo()

#print("Setting the data rate for each sensor index to 4ms....")
for i in range(interfaceKitHUB.getSensorCount()):
    try:
        interfaceKitHUB.setDataRate(i, 2)
开发者ID:AustralianSynchrotron,项目名称:Australian-Synchrotron-Surveyor-Tunnel-Exploration-And-Fault-Detection-Robot,代码行数:33,代码来源:srv_irdist.py

示例8: main

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
def main():
    
    
    
    try:
        interfaceKit = InterfaceKit()
    except RuntimeError as e:
        print("Runtime Exception: %s" % e.details)
        print("Exiting....")
        exit(1)

    try:
        interfaceKit.setOnAttachHandler(inferfaceKitAttached)
        interfaceKit.setOnDetachHandler(interfaceKitDetached)
        interfaceKit.setOnErrorhandler(interfaceKitError)
        interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
        interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
        interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    print("Opening phidget object....")

    try:
        interfaceKit.openPhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    print("Waiting for attach....")

    try:
        interfaceKit.waitForAttach(10000)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        try:
            interfaceKit.closePhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        print("Exiting....")
        exit(1)

    print("Setting the data rate for each sensor index to 4ms....")
    for i in range(interfaceKit.getSensorCount()):
        try:
            interfaceKit.setDataRate(i, 4)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))

    sys.exit(app.exec_())
    try:
        interfaceKit.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
开发者ID:Dillon-Benson,项目名称:Phidgets-InterfaceKit-Gui,代码行数:63,代码来源:interfaceKit.py

示例9: print

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
    try:
        interfaceKit.openRemoteIP("192.168.128.2", port=5001, serial=SERIAL_NUM)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    print("Waiting for attach....")

    try:
        interfaceKit.waitForAttach(10000)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        try:
            interfaceKit.closePhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        print("Exiting....")
        exit(1)

    while True:
        sleep(1)

    try:
        interfaceKit.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
开发者ID:psas,项目名称:launch-tower-comm,代码行数:32,代码来源:ignition-relay-watchdog.py

示例10: System

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
class System(DataSourceSystem):
    '''
    Generic DataSourceSystem interface for the Phidgets board: http://www.phidgets.com/products.php?category=0&product_id=1018_2
    '''
    update_freq = 1000

    def __init__(self, n_sensors=2, n_inputs=1):
        '''
        Docstring

        Parameters
        ----------

        Returns
        -------
        '''
        self.n_sensors = n_sensors
        self.n_inputs = n_inputs
        self.interval = 1. / self.update_freq

        self.sensordat = np.zeros((n_sensors,))
        self.inputdat = np.zeros((n_inputs,), dtype=np.bool)
        self.data = np.zeros((1,), dtype=self.dtype)

        self.kit = InterfaceKit()
        self.kit.openPhidget()
        self.kit.waitForAttach(2000)
    
    def start(self):
        '''
        Docstring

        Parameters
        ----------

        Returns
        -------
        '''
        self.tic = time.time()

    def stop(self):
        '''
        Docstring

        Parameters
        ----------

        Returns
        -------
        '''
        pass
    
    def get(self):
        '''
        Docstring

        Parameters
        ----------

        Returns
        -------
        '''
        toc = time.time() - self.tic
        if 0 < toc < self.interval:
            time.sleep(self.interval - toc)
        try:
            for i in range(self.n_sensors):
                self.sensordat[i] = self.kit.getSensorValue(i) / 1000.
            for i in range(self.n_inputs):
                self.inputdat[i] = self.kit.getInputState(i)
        except:
            print 'sensor_error'
        self.data['sensors'] = self.sensordat
        self.data['inputs'] = self.inputdat
        self.tic = time.time()
        return self.data
    
    def sendMsg(self, msg):
        '''
        Docstring

        Parameters
        ----------

        Returns
        -------
        '''
        pass

    def __del__(self):
        '''
        Docstring

        Parameters
        ----------

        Returns
        -------
        '''
        self.kit.closePhidget()
开发者ID:carmenalab,项目名称:brain-python-interface,代码行数:102,代码来源:phidgets.py

示例11: __init__

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
class Pot:

    __sensorPort = 1
    __sampleRate = 4 # Maybe too high?

    __potMin = 242
    __potZero = 490
    __potMax = 668


    def __init__(self):
        #Create an interfacekit object
        try:
            self.interfaceKit = InterfaceKit()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)

        try:
            self.interfaceKit.openPhidget()
            self.interfaceKit.waitForAttach(10000)
            self.interfaceKit.setDataRate(self.__sensorPort, self.__sampleRate)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            try:
                self.interfaceKit.closePhidget()
            except PhidgetException as e:
                print("Phidget Exception %i: %s" % (e.code, e.details))
                print("Exiting....")
                exit(1)


    def __del__(self):
        try:
            self.interfaceKit.closePhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)

    def getRawPot(self):
        try:
            resp = self.interfaceKit.getSensorValue(self.__sensorPort)
        except PhidgetException as e:
            # suppress print (makes testing harder) #TODO restore!!
            resp = float('nan')
            #print("Skipping reading - phidget Exception %i: %s" % (e.code, e.details))
        return resp

    #def recconect(self):


    def getPot(self):
        rawSensor = self.getRawPot()
        value = 0.0

        if rawSensor > self.__potMax:
            #warnings.warn("Pot measuremens out of bounds.") 
            return 1.0
        if rawSensor < self.__potMin: 
            #warnings.warn("Pot measuremens out of bounds.")
            return -1.0

        if rawSensor >= self.__potZero:
            value = float(rawSensor - self.__potZero) / (self.__potMax - self.__potZero)
        else:
            value = float(rawSensor - self.__potZero) / (self.__potZero - self.__potMin)

        return value
开发者ID:71ananab,项目名称:Software,代码行数:72,代码来源:pot.py

示例12: dict

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
s = dict()    
s['sens'] = np.zeros((1,2))
s['start_time'] = time.time()
sec_of_dat = 600
f_s = 60
err_ind = []
for i in range(sec_of_dat*f_s):
    s['tic'] = time.time()

    sensdat = np.zeros((1,2))
    try:
        sensdat[0,0] = kit.getSensorValue(0)/1000.
        sensdat[0,1] = kit.getSensorValue(1)/1000.
    except:
        print time.time() - s['start_time'], i
        print kit.isAttached()
        err_ind.extend([i])

    try:
        print kit.getSensorRawValue(2), kit.getSensorValue(2)
    except:
        print 'novalue'

    s['sens'] = np.vstack((s['sens'], sensdat))
    left_over_time = np.max([0, 1000/60. - (time.time() - s['tic'])])
    time.sleep(left_over_time/1000.)
kit.closePhidget()
plt.plot(np.array(err_ind)/float(f_s))


开发者ID:carmenalab,项目名称:brain-python-interface,代码行数:30,代码来源:test_phidgets_joystick_acqu.py

示例13: SitwPhidgetsKey

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]

#.........这里部分代码省略.........
            self.interfaceKit = InterfaceKit()
        except RuntimeError as e:
            print("Runtime Exception: %s" % e.details)
            print("Exiting....")
            exit(1)
        
        try:
            self.interfaceKit.setOnAttachHandler(self.inferfaceKitAttached)
            self.interfaceKit.setOnDetachHandler(self.interfaceKitDetached)
            self.interfaceKit.setOnErrorhandler(self.interfaceKitError)
            self.interfaceKit.setOnInputChangeHandler(self.interfaceKitInputChanged)
            self.interfaceKit.setOnOutputChangeHandler(self.interfaceKitOutputChanged)
            self.interfaceKit.setOnSensorChangeHandler(self.interfaceKitSensorChanged)
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        
        print("Opening phidget object....")
        
        try:
            self.interfaceKit.openPhidget()
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
            print("Exiting....")
            exit(1)
        
        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))
        
        
开发者ID:screensinthewild,项目名称:Phidgets-Light-Keypad,代码行数:67,代码来源:SitwPhidgetsKey.py

示例14: PHIDGET_IFK

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
class PHIDGET_IFK(object):
    """ Phidget InterfaceKit """
    def __init__(self, serialNumber=None, waitForAttach=1000, **kargs):

        self.interfaceKit = InterfaceKit()

        if 'remoteHost' in kargs:
            self.interfaceKit.openRemote(kargs['remoteHost'], serialNumber)
        else:
            self.interfaceKit.openPhidget(serialNumber)
    
        self.ratiometric = 1
        if 'ratiometric' in kargs:
            self.ratiometric = kargs['ratiometric'] 

        h = [
            'onAttachHandler',
            'onDetachHandler',
            'onErrorhandler',
            'onInputChangeHandler',
            'onOutputChangeHandler',
            'onSensorChangeHandler'
            ]

        for event in h:
            self.__dict__[event] = None
            if event in kargs:
                self.__dict__[event] = kargs[event]

        self.interfaceKit.setOnAttachHandler(self.attached)
        self.interfaceKit.setOnDetachHandler(self.detached)
        self.interfaceKit.setOnErrorhandler(self.error)
        self.interfaceKit.setOnInputChangeHandler(self.inputChanged)
        self.interfaceKit.setOnOutputChangeHandler(self.outputChanged)
        self.interfaceKit.setOnSensorChangeHandler(self.sensorChanged)


        if waitForAttach > 0:
            try:
                self.interfaceKit.waitForAttach(waitForAttach)
            except PhidgetException as e:
                #print("Phidget Exception %i: %s" % (e.code, e.details))
                try:
                    self.interfaceKit.closePhidget()
                except PhidgetException as e2:
                    pass
                raise e



    def attached(self, e):
        self.interfaceKit.setRatiometric(self.ratiometric)
        time.sleep(0.05)
        if self.onAttachHandler: self.onAttachHandler(e)

    def detached(self, e):
        if self.onDetachHandler: self.onDetachHandler(e)

    def error(self, e):
        error = {'code': e.eCode, 'description': e.description}
        if self.onErrorhandler: self.onErrorhandler(error, e)

    def outputChanged(self, e):
        if self.onInputChangeHandler: self.onInputChangeHandler(e.index, e.state, e)

    def inputChanged(self, e):
        if self.onInputChangeHandler: self.onInputChangeHandler(e.index, e.state, e)

    def sensorChanged(self, e):
        if self.onInputChangeHandler: self.onInputChangeHandler(e.index, e.value, e)
开发者ID:asphotographics,项目名称:WeatherStation,代码行数:72,代码来源:lphidget.py

示例15: PowerControl

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import closePhidget [as 别名]
class PowerControl(object):
    ''' PowerControl class wraps language around the 1014_2 -
    PhidgetInterfaceKit 0/0/4 4 relay device. '''
    def __init__(self):
        #log.info("Start of power control object")
        pass

    def open_phidget(self):
        ''' Based on the InterfaceKit-simple.py example from Phidgets, create an
        relay object, attach the handlers, open it and wait for the attachment.
        This function's primarily purpose is to replace the prints with log
        statements.  '''
        try:
            self.interface = InterfaceKit()
        except RuntimeError as e:
            log.critical("Phidget runtime exception: %s" % e.details)
            return 0


        try:
            self.interface.setOnAttachHandler( self.interfaceAttached )
            self.interface.setOnDetachHandler( self.interfaceDetached )
            self.interface.setOnErrorhandler(  self.interfaceError    )
        except PhidgetException as e:
            log.critical("Phidget Exception %i: %s" % (e.code, e.details))
            return 0


        try:
	    #print "Force open relay serial: 290968"
            self.interface.openPhidget()
        except PhidgetException as e:
            log.critical("Phidget Exception %i: %s" % (e.code, e.details))
            return 0


        #log.info("Waiting for attach....")
        try:
            self.interface.waitForAttach(100)
        except PhidgetException as e:
            log.critical("Phidget Exception %i: %s" % (e.code, e.details))
            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):
#.........这里部分代码省略.........
开发者ID:WasatchPhotonics,项目名称:Foreman,代码行数:103,代码来源:ControlPower.py


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