當前位置: 首頁>>代碼示例>>Python>>正文


Python InterfaceKit.setOutputState方法代碼示例

本文整理匯總了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.setOutputState方法的典型用法代碼示例。如果您正苦於以下問題:Python InterfaceKit.setOutputState方法的具體用法?Python InterfaceKit.setOutputState怎麽用?Python InterfaceKit.setOutputState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phidgets.Devices.InterfaceKit.InterfaceKit的用法示例。


在下文中一共展示了InterfaceKit.setOutputState方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Interface

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [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

示例2: set_bbias

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [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

示例3: operation

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [as 別名]
relay_receiver.setsockopt(zmq.SUBSCRIBE, "") #subscribe to all messages
#relay_receiver.setsockopt(zmq.RCVTIMEO, 500) #set a timeout of 500ms for a receive operation (prevent hangs)
print("SUB socket complete on ipc://tmp/shaft.ipc")

#The MEAT goes here...
print("going into forever loop mode")

while True:
    #first collect shaft movement messages...  
    try:
        relayed = relay_receiver.recv_json()
        print(relayed)
        

        if 'down' in relayed:
            interfaceKitLCD.setOutputState(0,True)
            interfaceKitLCD.setOutputState(1,False)
            print("going down")
            sleep(int(relayed['down']))

            interfaceKitLCD.setOutputState(0,False)
            interfaceKitLCD.setOutputState(1,False)

        elif 'up' in relayed:
            interfaceKitLCD.setOutputState(0,False)
            interfaceKitLCD.setOutputState(1,True)
            print("going up")
            sleep(int(relayed['up']))

            interfaceKitLCD.setOutputState(0,False)
            interfaceKitLCD.setOutputState(1,False)
開發者ID:AustralianSynchrotron,項目名稱:Australian-Synchrotron-Surveyor-Tunnel-Exploration-And-Fault-Detection-Robot,代碼行數:33,代碼來源:test_srv_relays.py

示例4: __init__

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [as 別名]
class IOTools:
    def __init__(self, onRobot):
        self.onRobot = onRobot

        # Camera
        self._openCam=False
        
        # Motor Control
        self._snMot=-1
        self._openMot=False
        self._attachedMot=False
        self._cur = [0, 0]

        # Servo
        self._snSer=-1
        self._openSer=False
        self._attachedSer=False
        self._limits = [0, 0]
        
        # IF Kit
        self._snIF=-1
        self._openIF=False
        self._attachedIF=False        
        self._inp = [0, 0, 0, 0, 0, 0, 0, 0]
        self._sen = [0, 0, 0, 0, 0, 0, 0, 0]
        
        # LEDs
        self._fistTime = True
        self._status = [0,0,0]
        self._mod = [8, 1, 1]
        self._rep = [-1, 5, 6]
        self._val = [True, False, False]
        self._ofs = [0, 0, 0]
        self._updaterThread = threading.Thread(target=self.__updateLED)
        self._stop = False
        self._updaterThread.setDaemon(True)
        self._updaterThread.start()

    def destroy(self):
        # LEDs
        self._stop = True
        if self._attachedIF:
            self._interfaceKit.setOutputState(0, 0)
            self._interfaceKit.setOutputState(1, 0)
            self._interfaceKit.setOutputState(2, 0)
        # Servo
        self.servoDisengage()
        # Camera
        self._openCam = False
        if self._openCam:
            self._cap.release()

    def open(self):
        self.__openIF()
        self.__openMot()
        self.__openSer()
        self.__openCam()

###################### Camera ######################
        
    def __openCam(self):
        if not os.path.exists('/dev/video0'):
            return False
        self._cap = cv2.VideoCapture()
        if not self._cap.open(-1):
            return False
        self._openCam = True

    def cameraGrab(self):
        if self._openCam:
            return self._cap.grab()
        else:
            return False

    def cameraRead(self):
        if self._openCam:
            (ret, img)=self._cap.retrieve()
            return img
        else:
            return False

    def cameraSetResolution(self, sz):
        """

        :rtype : object
        """
        if self._openCam:
            sz=sz.lower()
            if sz=='low':
                self._cap.set(3,160)
                self._cap.set(4,120)
            if sz=='medium':
                self._cap.set(3,640)
                self._cap.set(4,480)
            if sz=='high':
                self._cap.set(3,800)
                self._cap.set(4,600)
            if sz=='full':
                self._cap.set(3,1280)
                self._cap.set(4,720)
#.........這裏部分代碼省略.........
開發者ID:ArisKots1992,項目名稱:Robotics-Edinburgh,代碼行數:103,代碼來源:iotools.py

示例5: print

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [as 別名]
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    print("Exiting....")
    exit(1)
else:
    morse = morseEncode(message)

    while(True):
        send(morse)



# Wait for keypress to close the program
print("Press Enter to quit....")
chr = sys.stdin.read(1)

print("Closing...")

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

print("Done.")
exit(0)
開發者ID:benvl,項目名稱:IS,代碼行數:32,代碼來源:Morse.py

示例6: PowerControl

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [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

示例7: exit

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [as 別名]
        exit(2)
        break

    for i in range(interfaceKitHUB.getSensorCount()):
        try:
            #intval = interfaceKitHUB.getSensorValue(i)
            #if 0 reading, don't try and convert
            #if not intval:
            #    continue

            if i >= 6:
                #Sonar sensor range 0cm - 645cm
                #Plugged into analog input 6 & 7 for N (forward) and S (reverse)

                #turn on the sonar sensor via digital output 'i'
                interfaceKitHUB.setOutputState(i,True)
                #intval = interfaceKitHUB.getSensorValue(i)
                #sleep(0.1) # Wait for sonar to activate
                intval = interfaceKitHUB.getSensorRawValue(i) #Read sonar
                print intval, i
                distance_mm = (intval / 4.095 ) * 12.96 #convert raw value to mm
                #Check that value is within permissable range
                if distance_mm > 6450.0:
                    distance_mm = -1

                #turn off the sonar sensor via digital output 'i'
                interfaceKitHUB.setOutputState(i,False)
                sleep(0.4)
                #save value into array
                #message.append(distance_mm)
            else:
開發者ID:AustralianSynchrotron,項目名稱:Australian-Synchrotron-Surveyor-Tunnel-Exploration-And-Fault-Detection-Robot,代碼行數:33,代碼來源:srv_irdist.py

示例8: AttachHandler

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [as 別名]
#def AttachHandler(event):
#    attachedDevice = device
#    serialNumber = attachedDevice.getSerialNum()
#    deviceName = attachedDevice.getDeviceName()
#    print("Hello to Device " + str(deviceName) + ", Serial Number: " + str(serialNumber))

try:
   while not os.path.exists("/Users/u5212257/trigger"):
       sleep(0.05)
       print ".",
       sys.stdout.flush()
   print("Starting Camera_repeat_script.py")
   for iii in xrange(30):
       print iii+1
       interfaceKit.setOutputState (7, True)
       interfaceKit.setOutputState (0, True)
       sleep(0.38)

       interfaceKit.setOutputState (7, False)
       interfaceKit.setOutputState (0, False)
       sleep(0.38)

except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))

print("Setting the data rate for each sensor index to 16ms....")
for i in range(interfaceKit.getSensorCount()):
    try:
        interfaceKit.setDataRate(0, 16)
    except PhidgetException as e:
開發者ID:borevitzlab,項目名稱:plantspin,代碼行數:32,代碼來源:Camera_repeat_script.py

示例9: print

# 需要導入模塊: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 別名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setOutputState [as 別名]
try:
    interfaceKit.waitForAttach(1000)
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)

try:
    interfaceKit.setOutputState(relay, onoff)
except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))

print("Closing...")

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

print("Done.")
exit(0)
開發者ID:swarren,項目名稱:uboot-test-hooks,代碼行數:31,代碼來源:phidgets-relay.py


注:本文中的Phidgets.Devices.InterfaceKit.InterfaceKit.setOutputState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。