本文整理汇总了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.getSensorValue方法的典型用法代码示例。如果您正苦于以下问题:Python InterfaceKit.getSensorValue方法的具体用法?Python InterfaceKit.getSensorValue怎么用?Python InterfaceKit.getSensorValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phidgets.Devices.InterfaceKit.InterfaceKit
的用法示例。
在下文中一共展示了InterfaceKit.getSensorValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SimplePhidget
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorValue [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: System
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorValue [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()
示例3: PhidgetSensorHandler
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorValue [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
示例4: __init__
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorValue [as 别名]
class Pot:
__sensorPort = 1
__sampleRate = 4 # Maybe too high?
__potMin = 242
__potZero = 490
__potMax = 668
def __init__(self):
#Create an interfacekit object
try:
self.interfaceKit = InterfaceKit()
except RuntimeError as e:
print("Runtime Exception: %s" % e.details)
print("Exiting....")
exit(1)
try:
self.interfaceKit.openPhidget()
self.interfaceKit.waitForAttach(10000)
self.interfaceKit.setDataRate(self.__sensorPort, self.__sampleRate)
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
try:
self.interfaceKit.closePhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
def __del__(self):
try:
self.interfaceKit.closePhidget()
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
print("Exiting....")
exit(1)
def getRawPot(self):
try:
resp = self.interfaceKit.getSensorValue(self.__sensorPort)
except PhidgetException as e:
# suppress print (makes testing harder) #TODO restore!!
resp = float('nan')
#print("Skipping reading - phidget Exception %i: %s" % (e.code, e.details))
return resp
#def recconect(self):
def getPot(self):
rawSensor = self.getRawPot()
value = 0.0
if rawSensor > self.__potMax:
#warnings.warn("Pot measuremens out of bounds.")
return 1.0
if rawSensor < self.__potMin:
#warnings.warn("Pot measuremens out of bounds.")
return -1.0
if rawSensor >= self.__potZero:
value = float(rawSensor - self.__potZero) / (self.__potMax - self.__potZero)
else:
value = float(rawSensor - self.__potZero) / (self.__potZero - self.__potMin)
return value
示例5: dict
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorValue [as 别名]
kit.openPhidget()
#kit.enableLogging(6,'phid_log.out')
kit.waitForAttach(2000)
s = dict()
s['sens'] = np.zeros((1,2))
s['start_time'] = time.time()
sec_of_dat = 600
f_s = 60
err_ind = []
for i in range(sec_of_dat*f_s):
s['tic'] = time.time()
sensdat = np.zeros((1,2))
try:
sensdat[0,0] = kit.getSensorValue(0)/1000.
sensdat[0,1] = kit.getSensorValue(1)/1000.
except:
print time.time() - s['start_time'], i
print kit.isAttached()
err_ind.extend([i])
try:
print kit.getSensorRawValue(2), kit.getSensorValue(2)
except:
print 'novalue'
s['sens'] = np.vstack((s['sens'], sensdat))
left_over_time = np.max([0, 1000/60. - (time.time() - s['tic'])])
time.sleep(left_over_time/1000.)
kit.closePhidget()
示例6: SitwPhidgetsKey
# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import getSensorValue [as 别名]
#.........这里部分代码省略.........
def interfaceKitInputChanged(self, e):
source = e.device
print("InterfaceKit %i: Input %i: %s" % (source.getSerialNum(), e.index, e.state))
def interfaceKitSensorChanged(self, e):
if not self.KeyMatReady:
return
#source = e.device
#print("InterfaceKit %i: Sensor %i: %i" % (source.getSerialNum(), e.index, e.value))
if not self.KeySearch:
self.KeySearch = True
self.dtSearchStart = datetime.datetime.now()
def interfaceKitOutputChanged(self, e):
source = e.device
print("InterfaceKit %i: Output %i: %s" % (source.getSerialNum(), e.index, e.state))
def readSensorValue(self, channel_id):
val = 0.0
try:
val = self.interfaceKit.getSensorValue(channel_id)
#val = self.interfaceKit.getSensorRawValue(channel_id) / 4.095
except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details))
#val = 1.478777 * float(val) + 33.67076 #------ for 1142_0: Lux = m * SensorValue + b
#val = math.exp(0.02385 * float(val) - 0.56905) #------ for 1143_0: Lux = math.exp(m * SensorValue + b)
#val = math.exp(sitwPara.List_mb[channel_id][0] * float(val) + sitwPara.List_mb[channel_id][1]) #------ for 1143_0: Lux = math.exp(m * SensorValue + b)
return val
def CheckEnv(self, event):
for i in range(sitwPara.KeyCount):
ValIns = self.readSensorValue(i)
ValEnv = sum(self.ListValMat[i]) / len(self.ListValMat[i])
if (float(ValIns) / float(ValEnv)) > 0.70 or self.ctEvn >= 2: #natural change or the big change keeps for long time
self.ListValMat[i].pop(0)
self.ListValMat[i].append(ValIns)
self.ctEvn = 0
else:
self.ctEvn += 1 #ignore those suddenly changes
###test
#for val in self.ListValMax:
# print val, '->', sum(val)/len(val)
#print '-------------------------------------------------------'