本文整理汇总了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.openPhidget方法的典型用法代码示例。如果您正苦于以下问题:Python InterfaceKit.openPhidget方法的具体用法?Python InterfaceKit.openPhidget怎么用?Python InterfaceKit.openPhidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phidgets.Devices.InterfaceKit.InterfaceKit
的用法示例。
在下文中一共展示了InterfaceKit.openPhidget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SimplePhidget
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [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)
示例2: InterfaceSource
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
class InterfaceSource(Source):
def __init__(self):
Source.__init__(self)
try:
self._device = InterfaceKit()
except RuntimeError as e:
print("Runtime Error: %s" % e.message)
try:
self._device.openPhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.detail))
self._device.setOnSensorChangeHandler(self.sensor_changed)
print("Phidget: Waiting for Connection")
self._device.waitForAttach(10000)
self._device.setSensorChangeTrigger(0, 0)
self._device.setDataRate(0, 1)
print("Phidget: Connected")
def sensor_changed(self, e):
if self.sink is not None:
self.sink([e.value])
示例3: Interface
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [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()
示例4: __init__
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
class PhidgetInterface:
def __init__(self):
rospy.loginfo("Initializing PhidgetInterface")
self.batteryVoltage = 0
self.forwardRange = 1
self.aftRange = 2
self.interfaceKit = InterfaceKit()
self.forwardRangeMessage = Range()
self.forwardRangeMessage.header.frame_id = 'infrared_forward'
self.forwardRangeMessage.radiation_type = Range.INFRARED
self.forwardRangeMessage.field_of_view = 0.018
self.forwardRangeMessage.min_range = 0.2
self.forwardRangeMessage.max_range = 0.8
self.forwardRangeMessage.range = 0.0
self.aftRangeMessage = Range()
self.aftRangeMessage.header.frame_id = 'infrared_aft'
self.aftRangeMessage.radiation_type = Range.INFRARED
self.aftRangeMessage.field_of_view = 0.018
self.aftRangeMessage.min_range = 0.2
self.aftRangeMessage.max_range = 0.8
self.aftRangeMessage.range = 0.0
self.sensorPublisher = rospy.Publisher('bogies', Range)
self.interfaceKit.setOnAttachHandler(self.interfaceKitAttached)
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)
try:
self.interfaceKit.openPhidget()
except PhidgetException, e:
rospy.logerror("openPhidget() failed")
rospy.logerror("code: %d" % e.code)
rospy.logerror("message", e.message)
raise
try:
self.interfaceKit.waitForAttach(10000)
except PhidgetException, e:
rospy.logerror("waitForAttach() failed")
rospy.logerror("code: %d" % e.code)
rospy.logerror("message", e.message)
raise
示例5: PhidgetsEventThread
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
class PhidgetsEventThread(QtCore.QThread):
def __init__(self, parent=None):
super(PhidgetsEventThread, self).__init__(parent)
try:
self.interfaceKit = InterfaceKit()
self.interfaceKit.openPhidget()
self.interfaceKit.setOnAttachHandler(self.interfaceKitAttachedEvent)
self.interfaceKit.setOnDetachHandler(self.interfaceKitDetachEvent)
self.interfaceKit.setOnErrorhandler(self.interfaceKitErrorSlot)
self.interfaceKit.setOnInputChangeHandler(self.interfaceKitInputChangedEvent)
self.interfaceKit.setOnOutputChangeHandler(self.interfaceKitOutputChangedEvent)
self.interfaceKit.setOnSensorChangeHandler(self.interfaceKitSensorChangedEvent)
except RuntimeError as e:
print "Runtime Exception: %s" % (e.details)
print "Exiting..."
sys.exit(1)
except PhidgetException as e:
print "Phidget Exception %i: %s" % (e.code, e.details)
print "Exiting..."
sys.exit(1)
#===========================================================================
# On Interfacekit events, emit signals to main thread for updating GUI
#===========================================================================
def interfaceKitAttachedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitAttachedSlot"), event)
def interfaceKitDetachEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitDetachedSlot"), event)
def interfaceKitErrorSlot(self, event):
self.emit(QtCore.SIGNAL("interfaceKitErrorSlot"), event)
def interfaceKitInputChangedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitInputChangedSlot"), event)
def interfaceKitOutputChangedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitOutputChangedSlot"), event)
def interfaceKitSensorChangedEvent(self, event):
self.emit(QtCore.SIGNAL("interfaceKitSensorChangedSlot"), event)
def setSensorSensitivity(self, value):
try:
for i in range(self.interfaceKit.getSensorCount()):
self.interfaceKit.setSensorChangeTrigger(i, value)
except PhidgetException as e:
print "Could not set sensitivity: %s" % e.details
def run(self):
self.exec_()
示例6: run
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
def run():
kit = InterfaceKit()
try:
try:
kit.openPhidget()
kit.setOnAttachHandler(attached)
kit.setOnDetachHandler(detached)
if not kit.isAttached():
print "Please attach the interface kit!"
raw_input()
except PhidgetException as e:
print ("Phidget exception %i: %s" % (e.code,e.detail))
except RuntimeError as e:
print ("Runtime error: %s" % e.message)
except Exception as e:
print ("Unknown error: %s" % (e.message))
stop(kit)
示例7: __init__
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [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()
示例8: set_bbias
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [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
示例9: PhidgetSensorHandler
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
class PhidgetSensorHandler(AbstractSensorHandler):
def __init__(self):
self.device = None
self._attach_timeout = None
self._data_rate = None
self._sensors = None
def _try_init(self):
if all([self._data_rate, self._attach_timeout, self._sensors]):
try:
from Phidgets.Devices.InterfaceKit import InterfaceKit
from Phidgets.PhidgetException import PhidgetException
self.interface_kit = InterfaceKit()
self.interface_kit.setOnAttachHandler(lambda e: self._attach(e))
self.interface_kit.setOnDetachHandler(lambda e: self._detach(e))
self.interface_kit.setOnErrorhandler(lambda e: self._error(e))
self.interface_kit.setOnSensorChangeHandler(lambda e: self._sensor_change(e))
self.interface_kit.openPhidget()
self.interface_kit.waitForAttach(self._attach_timeout)
for i in range(self.interface_kit.getSensorCount()):
self.interface_kit.setDataRate(i, self._data_rate)
logging.info("Phidget Sensor Handler Initalized")
for s in self._sensors:
if s.port_num is not None:
s.current_data = self.interface_kit.getSensorValue(s.port_num)
logging.debug("Setting Initial Value for Sensor {} to {}".format(s.port_num, s.current_data))
else:
logging.warn("Cannot set Initial Value for Sensor {}".format(s.port_num))
except ImportError:
self.interface_kit = None
logging.error('Phidget Python Module not found. Did you install python-phidget?')
except PhidgetException as e:
self.interface_kit = None
logging.error("Could not Initalize Phidget Kit: {}".format(e.details))
def _read_sensors(self):
ready_sensors = []
for s in self._sensors:
if s.data is not None:
ready_sensors.append(s)
return ready_sensors
def _set_sensors(self, v):
logging.debug('Adding Phidget Sensors :: {}'.format(v))
self._sensors = v
self._try_init()
sensors = property(_read_sensors, _set_sensors)
attach_timeout = property(lambda self: self._attach_timeout,
lambda self, v: self._set_config('attach_timeout', v))
data_rate = property(lambda self: self._data_rate,
lambda self, v: self._set_config('data_rate', v))
def _set_config(self, prop, value):
if prop == 'data_rate':
self._data_rate = value
elif prop == 'attach_timeout':
self._attach_timeout = value
self._try_init()
def _attach(self, e):
self.device = e.device
logging.info("Phidget InterfaceKit {} Attached".format(self.device.getSerialNum()))
def _detach(self, e):
logging.warn("Phidget InterfaceKit {} Removed".format(e.device.getSerialNum()))
self.device = None
def _error(self, e):
logging.error("Phidget Error {} :: {}".format(e.eCode, e.description))
def _sensor_change(self, e):
# logging.debug("Phidget Analog Sensor Change :: Port: {} / Data: {}".format(e.index, e.value))
for s in self._sensors:
if s.port_type == 'analog' and s.port_num == e.index:
# Set a default ID if none given in config file
if s.id is None:
# Default ID is kit serial number::port
s.id = '{}:{}:{}'.format(self.device.getSerialNum(),
s.port_type, s.port_num)
s.current_data = e.value
示例10: print
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
# interfaceKitLCD.setOnInputChangeHandler(interfaceKitLCDInputChanged)
# interfaceKitLCD.setOnOutputChangeHandler(interfaceKitOutputChanged)
# interfaceKitLCD.setOnSensorChangeHandler(interfaceKitSensorChanged)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
print("Opening phidget object....")
try:
# Open interfaceKit by serial number to avoid conflicts with future interface kits...
# As displayed by displayDeviceInfo()
# interfaceKitLCD.openPhidget(serial=120517)
interfaceKitHUB.openPhidget(serial=337662)
#Connect to phidgets webservice
# interfaceKitHUB.openRemote('odroid',serial=337662)
# print("interfaceKitHuB connected to webservice: %s" % interfaceKitHUB.isAttachedToServer())
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
#if not interfaceKitHUB.isAttachedToServer():
# sleep(2)
print("Waiting for attach....")
开发者ID:AustralianSynchrotron,项目名称:Australian-Synchrotron-Surveyor-Tunnel-Exploration-And-Fault-Detection-Robot,代码行数:32,代码来源:srv_irdist.py
示例11: SitwPhidgetsKey
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
#.........这里部分代码省略.........
dc.SetBrush(wx.Brush((0, 255*self.ListValBrt[i], 255*self.ListValBrt[i])))
if self.KeyPressed == sitwPara.List_Action[i]:
dc.SetPen(wx.Pen(strColorPen1, 5))
else:
dc.SetPen(wx.Pen(strColorPen2, 1))
#dc.SetPen(wx.TRANSPARENT_PEN)
dc.DrawRoundedRectangleRect(rect, 8)
def initPhidgets(self):
try:
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))
示例12: PHIDGET_IFK
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [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)
示例13: exit
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
exit(1)
try:
interfaceKit.setOnAttachHandler(interfaceKitAttached)
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)
try:
interfaceKit.openPhidget()
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)
else:
print("Interface Kit initialized.")
示例14: setup_phidgets
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [as 别名]
def setup_phidgets():
global interfaceKits
interfaceKits = InterfaceKits()
"Print Creating phidget manager"
try:
manager = Manager()
except RuntimeError as e:
output("Runtime Exception: %s" % e.details)
output("Exiting....")
exit(1)
try:
manager.setOnAttachHandler(ManagerDeviceAttached)
manager.setOnDetachHandler(ManagerDeviceDetached)
manager.setOnErrorHandler(ManagerError)
except PhidgetException as e:
output("Phidget Exception %i: %s" % (e.code, e.details))
output("Exiting....")
exit(1)
output("Opening phidget manager....")
logging.info("Opening phidget manager....")
try:
manager.openManager()
#manager.openRemote("hydropi","hydropi")
except PhidgetException as e:
output("Phidget Exception %i: %s" % (e.code, e.details))
logging.error("Phidget Exception %i: %s" % (e.code, e.details))
output("Exiting....")
logging.error("Exiting....")
exit(1)
# Wait a moment for devices to attache......
output("\nWaiting one sec for devices to attach....\n\n")
logging.info("Waiting one sec for devices to attach....")
time.sleep(1)
output("Phidget manager opened.")
attachedDevices = manager.getAttachedDevices()
for attachedDevice in attachedDevices:
output("Found %30s - SN %10d" % (attachedDevice.getDeviceName(), attachedDevice.getSerialNum()))
if attachedDevice.getDeviceClass() == PhidgetClass.INTERFACEKIT:
output(" %s/%d is an InterfaceKit" % ( attachedDevice.getDeviceName(),attachedDevice.getSerialNum()))
#Create an interfacekit object
try:
newInterfaceKit = InterfaceKit()
except RuntimeError as e:
output("Runtime Exception: %s" % e.details)
output("Exiting....")
exit(1)
output(" Opening...")
try:
newInterfaceKit.openPhidget()
except PhidgetException as e:
output("Phidget Exception %i: %s" % (e.code, e.details))
output("Exiting....")
output(" Setting handlers...")
try:
newInterfaceKit.setOnAttachHandler(interfaceKitAttached)
newInterfaceKit.setOnDetachHandler(interfaceKitDetached)
newInterfaceKit.setOnErrorhandler(interfaceKitError)
except PhidgetException as e:
output("Phidget Exception %i: %s" % (e.code, e.details))
output("Exiting....")
exit(1)
output(" Attaching...")
try:
newInterfaceKit.waitForAttach(5000)
except PhidgetException as e:
output("Phidget Exception %i: %s" % (e.code, e.details))
try:
newInterfaceKit.closePhidget()
except PhidgetException as e:
output("Phidget Exception %i: %s" % (e.code, e.details))
output("Exiting....")
exit(1)
output("Exiting....")
exit(1)
output(" Setting the data rate for each sensor index to 1000ms....")
for i in range(newInterfaceKit.getSensorCount()):
try:
newInterfaceKit.setDataRate(i, 1000)
except PhidgetException as e:
output("Phidget Exception %i: %s" % (e.code, e.details))
interfaceKits.kitList.append(newInterfaceKit)
display_device_info(manager)
return manager
示例15: PowerControl
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import openPhidget [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):
#.........这里部分代码省略.........