本文整理汇总了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.getInputState方法的典型用法代码示例。如果您正苦于以下问题:Python InterfaceKit.getInputState方法的具体用法?Python InterfaceKit.getInputState怎么用?Python InterfaceKit.getInputState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phidgets.Devices.InterfaceKit.InterfaceKit
的用法示例。
在下文中一共展示了InterfaceKit.getInputState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Interface
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getInputState [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: System
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getInputState [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()