本文整理汇总了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()
示例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
示例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)
#.........这里部分代码省略.........
示例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)
示例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):
#.........这里部分代码省略.........
示例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:
示例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)