当前位置: 首页>>代码示例>>Python>>正文


Python InterfaceKit.setRatiometric方法代码示例

本文整理汇总了Python中Phidgets.Devices.InterfaceKit.InterfaceKit.setRatiometric方法的典型用法代码示例。如果您正苦于以下问题:Python InterfaceKit.setRatiometric方法的具体用法?Python InterfaceKit.setRatiometric怎么用?Python InterfaceKit.setRatiometric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phidgets.Devices.InterfaceKit.InterfaceKit的用法示例。


在下文中一共展示了InterfaceKit.setRatiometric方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Interface

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setRatiometric [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()
开发者ID:cversek,项目名称:yes-o2ab,代码行数:62,代码来源:kit1018.py

示例2: exit

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setRatiometric [as 别名]
    exit(1)
else:
    displayDeviceInfo()

#print("Setting the data rate for each sensor index to 4ms....")
for i in range(interfaceKitHUB.getSensorCount()):
    try:
        interfaceKitHUB.setDataRate(i, 2)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))

print "\n"

#Make sure the ratiometric setting is set (required by sonar)
if not interfaceKitHUB.getRatiometric:
    interfaceKitHUB.setRatiometric(True)

#Register interupt callback
signal.signal(signal.SIGINT, signal_handler)

#Setup zmq sockets
context = zmq.Context()
distance_socket = context.socket(zmq.PUB)
distance_socket.setsockopt(zmq.LINGER, 100)
distance_socket.bind("ipc:///tmp/distance.ipc")
#distance_socket.bind("tcp://127.0.0.2:1000")

bumper_socket = context.socket(zmq.PUB)
bumper_socket.setsockopt(zmq.LINGER, 100)
bumper_socket.bind("ipc://tmp/bumper.ipc")
开发者ID:AustralianSynchrotron,项目名称:Australian-Synchrotron-Surveyor-Tunnel-Exploration-And-Fault-Detection-Robot,代码行数:32,代码来源:srv_irdist.py

示例3: PHIDGET_IFK

# 需要导入模块: from Phidgets.Devices.InterfaceKit import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit.InterfaceKit import setRatiometric [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)
开发者ID:asphotographics,项目名称:WeatherStation,代码行数:72,代码来源:lphidget.py


注:本文中的Phidgets.Devices.InterfaceKit.InterfaceKit.setRatiometric方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。