本文整理汇总了Python中Phidgets.Devices.InterfaceKit.waitForAttach方法的典型用法代码示例。如果您正苦于以下问题:Python InterfaceKit.waitForAttach方法的具体用法?Python InterfaceKit.waitForAttach怎么用?Python InterfaceKit.waitForAttach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phidgets.Devices.InterfaceKit
的用法示例。
在下文中一共展示了InterfaceKit.waitForAttach方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
class phidget:
def __init__(self, id, port):
self.id = id
self.port = port
self.serial_numbers = (262305, # 4-port, shelf 6
262295, # 4-port, shelf 6
318471, # 8-port, shelf 2
312226, # 8-port, shelf 4
259764, # 4-port, shelf 8
319749, # 8-port, shelf 10
259763, # 4-port, shelf 6
)
self.serial_num = self.serial_numbers[id]
self.lockfile = "/var/run/lock/phidget-%s.lock" %self.id
self.lock_fp = open(self.lockfile, "w")
self.lock_fd = self.lock_fp.fileno()
fcntl.lockf(self.lock_fd, fcntl.LOCK_EX)
if debug:
print "[%.2f] Aquired lock for Phidget %s" %(time.time(), self.id)
try:
self.device = InterfaceKit()
except RuntimeError as e:
print("Runtime Error: %s" % e.message)
try:
self.device.openPhidget(serial=self.serial_num)
except PhidgetException as e:
print ("Phidget Exception %i: %s" % (e.code, e.detail))
fcntl.lockf(self.lock_fd, fcntl.LOCK_UN)
exit(1)
self.device.waitForAttach(10000)
#print ("Phidget %d attached!" % (self.device.getSerialNum()))
#print ("Phidget has %d inputs, %d outputs, %d sensors"
# %(self.device.getInputCount(), self.device.getOutputCount(), self.device.getSensorCount()))
def close(self):
self.device.closePhidget()
fcntl.lockf(self.lock_fd, fcntl.LOCK_UN)
if debug:
print "[%.2f] Released lock for Phidget %s" %(time.time(), self.id)
def on(self):
self.device.setOutputState(self.port, 1)
def off(self):
self.device.setOutputState(self.port, 0)
def cmd(self, cmd):
if cmd == 'on':
self.on()
if cmd == 'off':
self.off()
示例2: main
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
def main():
parser = argparse.ArgumentParser(description='read sensor values from a Phidgets device')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-d', '--digital', metavar='<input id>', type=int, help='read from a digital input')
group.add_argument('-a', '--analog', metavar='<sensor id>', type=int, help='read from an analog sensor')
parser.add_argument('-t', '--temperature-sensor', action='store_const', const=True, default=False, help='device is a temperature sensor, output in degrees celcius. must be reading an analog sensor')
parser.add_argument('-m', '--precision-light-sensor-multiplier', metavar='<multiplier>', type=float, help='\'m\' value from the underside of the precision light sensor. must be reading an analog sensor')
parser.add_argument('-b', '--precision-light-sensor-boost', metavar='<boost>', type=float, help='\'b\' value from the underside of the precision light sensor. must be reading an analog sensor')
cli_args = parser.parse_args()
try:
device = InterfaceKit()
except RuntimeError as e:
print("Runtime Error: %s" % e.message)
exit(2)
try:
device.openPhidget()
device.waitForAttach(1000)
if cli_args.digital != None:
if cli_args.digital < device.getInputCount():
print device.getInputState(cli_args.digital)
else:
parser.print_usage()
print('%s: error: input id out of range (maximum is %d)' % (sys.argv[0], device.getInputCount()-1))
elif cli_args.analog != None:
if cli_args.analog < device.getSensorCount():
if cli_args.temperature_sensor == True:
print (float(device.getSensorValue(cli_args.analog)) * 0.2222) - 61.1111
elif (cli_args.precision_light_sensor_multiplier == None) != (cli_args.precision_light_sensor_boost == None):
parser.print_usage()
print('%s: error: you must supply both precision light sensor arguments')
elif cli_args.precision_light_sensor_multiplier != None and cli_args.precision_light_sensor_boost != None:
print (cli_args.precision_light_sensor_multiplier * float(device.getSensorValue(cli_args.analog)) + cli_args.precision_light_sensor_boost)
else:
print device.getSensorValue(cli_args.analog)
else:
parser.print_usage()
print('%s: error: sensor id out of range (maximum is %d)' % (sys.argv[0], device.getSensorCount()-1))
device.closePhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
try:
device.closePhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting...")
exit(1)
exit(0)
示例3: init
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
def init():
notifo = Notifo(user="pcondosta", secret="xc53e5cdc470b9adb5165adcd4aeb597549136d7c")
db=MySQLdb.connect(host="localhost",user="pete",passwd="",db="security")
c=db.cursor()
interfaceKit = InterfaceKit()
interfaceKit.openPhidget()
interfaceKit.waitForAttach(10000)
security_state = interfaceKit.getInputState(0)
sec_state(security_state)
FD,BSDR,BSLR = getSensor()
updateMysql(FD,"FD")
updateMysql(BSDR,"BSDR")
updateMysql(BSLR,"BSLR")
示例4: PhidgetTextLCD
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
class PhidgetTextLCD(object):
"""
A class modelled after a Phidget InterfaceKit with an integrated LCD.
It contains a list of objects, which are subclasses of Sensor object.
Attributes:
analog_sensors: a list containing objects of one of subclasses of Sensor
data_dir: a string of directory path to save sensor reading data in
"""
def __init__(self, analog_sensors, data_dir):
"""Initializes the members."""
self.__interfaceKit = InterfaceKit()
self.__textLCD = TextLCD()
self.__data_dir = data_dir
# instantiate classes according to actual sensor port configuration
self.sensors = []
for sensor in analog_sensors:
a_sensor = self.__Factory(sensor)
self.sensors.append(a_sensor)
try:
# Interface Kit
self.__interfaceKit.openPhidget()
self.__interfaceKit.waitForAttach(10000)
print "%s (serial: %d) attached!" % (
self.__interfaceKit.getDeviceName(), self.__interfaceKit.getSerialNum())
# get initial value from each sensor
i = 0
for sensor in self.sensors:
#print sensor.product_name
#print sensor.value
sensor.value = self.__interfaceKit.getSensorValue(i)
i += 1
self.__interfaceKit.setOnSensorChangeHandler(self.__SensorChanged)
# Text LCD
self.__textLCD.openPhidget()
self.__textLCD.waitForAttach(10000)
print "%s attached!" % (self.__textLCD.getDeviceName())
self.__textLCD.setCursorBlink(False)
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
sys.exit(1)
示例5: exit
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
return 0
print "Opening phidget object...."
try:
interfaceKit.openPhidget()
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
print "Exiting...."
exit(1)
print "Waiting for attach...."
try:
interfaceKit.waitForAttach(10000)
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
try:
interfaceKit.closePhidget()
except PhidgetException, e:
print "Phidget Exception %i: %s" % (e.code, e.message)
print "Exiting...."
exit(1)
print "Exiting...."
exit(1)
print "Output Count: "+str(interfaceKit.getOutputCount())
time.sleep(3)
示例6: print
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
print('<center><b><font size="16" color="#0000ff">FULL INTERFACEKIT</font></b></center><br>')
print('<font size="4">THIS PROJECT WILL DEVELOP IN A FULL FUNCTIONAL WEB APPLICATION TO CONTROL THE PHIDGETS SBC</font>')
print('<br>© J J Slabbert')
print('<br><a href="mailto:[email protected]">[email protected]</a><br><br>')
# Create, Open, and Attach the Interface Kit
try:
ifk = InterfaceKit()
except RuntimeError as e:
errors = errors + "<h5>Runtime Exception on object creation: " + e.details + "</h5>\n"
try:
ifk.openRemoteIP('192.168.10.106',5001)
except PhidgetException as e:
errors = errors + "<h5>Phidget Exception on Open: " + e.details + "</h5>\n"
try:
ifk.waitForAttach(10000)
except PhidgetException as e:
errors = errors + "<h5>Phidget Exception on Attach: " + e.details + "</h5>\n"
errors = errors + "<h5>If Phidget is 'Not Physically Attached' it may be in use</h5>\n"
print('<table><tr><td>')
# Generating the Sensor Value Table
print('<b>Analog Sensor Values</b>')
print('<table border="1"><tr><td>Sensor Number</td><td>Sensor Value</td></tr>\n')
for i in range (0,8):
try:
print ('<tr><td>'+str(i)+'</td><td>'+str(ifk.getSensorValue(i))+'</td></tr>\n')
except:
示例7: print
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
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(86400000) # wait a day
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)
chr = sys.stdin.read(1)
print("Closing...")
示例8: AttachHandler
# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import waitForAttach [as 别名]
if e.value > 0 and e.value < 301:
device.setOutputState(0, 1)
device.setOutputState(1, 0)
device.setOutputState(2, 0)
if e.value > 300 and e.value < 601:
device.setOutputState(0, 0)
device.setOutputState(1, 1)
device.setOutputState(2, 0)
if e.value > 601 and e.value < 999:
device.setOutputState(0, 0)
device.setOutputState(1, 0)
device.setOutputState(2, 1)
try:
device.openPhidget()
device.waitForAttach(10000)
except PhidgetException as e:
print('Phidget Exception')
exit(1)
def AttachHandler(event):
attachedDevice = event.device
serialNumber = attachedDevice.getSerialNum()
deviceName = attachedDevice.getDeviceName()
print("Hello to Device " + str(deviceName) + ", Serial Number: " + str(serialNumber))
device.setOnSensorChangeHandler(sensorChanged)
try:
device.setOnAttachHandler(AttachHandler)
except PhidgetException as e:
pass