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


Python InterfaceKit.setOnAttachHandler方法代码示例

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


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

示例1: SensorThread

# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import setOnAttachHandler [as 别名]
class SensorThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        # Create
        try:
            print "Setting up sensor interface"
            self.device = InterfaceKit()	
        except RuntimeError as e:
            print("Runtime Error: %s" % e.message)
         
        # Open
        try:
            # Hook our function above into the device object
            self.device.setOnSensorChangeHandler(sensorChanged)
            self.device.openPhidget()
        except PhidgetException as e:
            print ("Phidget Exception %i: %s" % (e.code, e.detail))		
            exit(1)

    def run(self):
        self.running = True
        print "Sensors> Waiting for attach"
        try:
            self.device.setOnAttachHandler(AttachHandler)
        except PhidgetException as e:
            print "Phidget Exception %i" % (e.code)		
        pass
    
    def stop(self):
        self.running = False
        self.device.closePhidget()
开发者ID:tspinelli,项目名称:CarSeat,代码行数:33,代码来源:Seat.py

示例2: HomeMonDaemon

# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import setOnAttachHandler [as 别名]
class HomeMonDaemon(daemon.BaseDaemon):
    """ Serves one device
    """
    def __init__(self):
        daemon.BaseDaemon.__init__(self)
        self.ikit = None
        
        self.deviceName = None
        self.inputs = None
        self.outputs = None
    
        self.state = states['init']
    
    def init(self):
        """ Init 
        """
        try:
            self.ikit = InterfaceKit()
            
            self.ikit.setOnAttachHandler(self.inferfaceKitAttached)
            self.ikit.setOnDetachHandler(self.interfaceKitDetached)
            self.ikit.setOnErrorhandler(self.interfaceKitError)
            self.ikit.setOnInputChangeHandler(self.interfaceKitInputChanged)
            self.ikit.setOnOutputChangeHandler(self.interfaceKitOutputChanged)
            self.ikit.setOnSensorChangeHandler(self.interfaceKitSensorChanged)
        except Exception,e:
            pass
开发者ID:jldupont,项目名称:jldupont.com,代码行数:29,代码来源:daemon.py

示例3: __init__

# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import setOnAttachHandler [as 别名]
class PhidgetsInterfaceKit:
    def __init__(self):
        rospy.init_node('interface_kit', anonymous=True)
        self.name = rospy.get_param('~name', '')
        self.serial = rospy.get_param('~serial_number', -1)
        
        if self.serial == -1:
            rospy.logwarn('No serial number specified. This node will connect to the first interface kit attached.')
        self.interface_kit = InterfaceKit()

    def initialize(self):
        try:
            self.interface_kit.setOnAttachHandler(self.interfaceKitAttached)
            self.interface_kit.setOnDetachHandler(self.interfaceKitDetached)
            self.interface_kit.setOnErrorhandler(self.interfaceKitError)
            self.interface_kit.setOnSensorChangeHandler(self.interfaceKitSensorChanged)
            self.interface_kit.openPhidget(self.serial)
        except PhidgetException, e:
            rospy.logfatal('Phidget Exception %i: %s' % (e.code, e.message))
            sys.exit(1)
开发者ID:Kenkoko,项目名称:ua-ros-pkg,代码行数:22,代码来源:interface_kit.py

示例4: open

# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import setOnAttachHandler [as 别名]

if __name__ == '__main__':

#    f = open('sonar.txt','a')
#    f.write('********************************\n')
#    f.close()

    # Create
    try:
        device = InterfaceKit()	
    except RuntimeError as e:
        print("Runtime Error: %s" % e.message)
        
    try:
        device.setOnAttachHandler(AttachHandler)
        device.setOnDetachHandler(DetachHandler)
        device.openPhidget()
        device.setOnSensorChangeHandler(sensorChanged)
    except PhidgetException as e: 
        LocalErrorCatcher(e)

    try:
        pub = rospy.Publisher('sonar', Float32)
        rospy.init_node('sonar')
    except rospy.ROSInterruptException:
        pass

    print("Phidget Simple Playground (plug and unplug devices)");
    print("Press Enter to end anytime...");
    character = str(raw_input())
开发者ID:JXS2012,项目名称:QuadController,代码行数:32,代码来源:sonar.py

示例5: interfaceKitInputChanged

# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import setOnAttachHandler [as 别名]
def interfaceKitInputChanged(e):
    print "Input %i: %s" % (e.index, e.state)
    return 0

def interfaceKitSensorChanged(e):
    print "Sensor %i: %i" % (e.index, e.value)
    return 0

def interfaceKitOutputChanged(e):
    print "Output %i: %s" % (e.index, e.state)
    return 0

#Main Program Code
try:
    interfaceKit.setOnAttachHandler(inferfaceKitAttached)
    interfaceKit.setOnDetachHandler(interfaceKitDetached)
    interfaceKit.setOnErrorhandler(interfaceKitError)
    interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
    interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
    interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
except PhidgetException, e:
    print "Phidget Exception %i: %s" % (e.code, e.message)
    print "Exiting...."
    exit(1)

print "Opening phidget object...."

try:
    interfaceKit.openPhidget()
except PhidgetException, e:
开发者ID:jldupont,项目名称:pyjld,代码行数:32,代码来源:test2.py

示例6: __init__

# 需要导入模块: from Phidgets.Devices import InterfaceKit [as 别名]
# 或者: from Phidgets.Devices.InterfaceKit import setOnAttachHandler [as 别名]
class Sonar:
    def __init__(self):
        try:
            self.device = InterfaceKit()
        except RuntimeError as e:
            print("Runtime Error: %s" % e.message)

        self.height = 0
        self.vel = 0
        self.last_hit_time = 0
        self.lock = Lock()

        num = [0.0181,0.0543,0.0543,0.0181]
        den = [1,-1.76,1.1829,-0.2781]

        self.vzfilter = IIRfilter(num,den)

        try:
            self.device.setOnAttachHandler(self.AttachHandler)
            self.device.setOnDetachHandler(self.DetachHandler)
            self.device.openPhidget()
            self.device.setOnSensorChangeHandler(self.sensorChanged)
        except PhidgetException as e:
            self.LocalErrorCatcher(e)

    def AttachHandler(self,event):
        attachedDevice = event.device
        serialNumber = attachedDevice.getSerialNum()
        deviceName = attachedDevice.getDeviceName()
        attachedDevice.setRatiometric(True)
        attachedDevice.setSensorChangeTrigger(5,1)
        print("Hello to Device " + str(deviceName) + ", Serial Number: " + str(serialNumber))

    def DetachHandler(self,event):
        detachedDevice = event.device
        serialNumber = detachedDevice.getSerialNum()
        deviceName = detachedDevice.getDeviceName()
        print("Goodbye Device " + str(deviceName) + ", Serial Number: " + str(serialNumber))

    def sensorChanged(self,e):
    #    f = open('sonar.txt','a')
        with self.lock:
            current_hit = time.time()
            time_elapse = current_hit-self.last_hit_time
            if time_elapse > 0.1:
                #print ("Sensor height {0} cm vel {1} cm/s".format(self.height, self.vel))
                self.last_hit_time= current_hit
                self.vel = (e.value*1024.0/1000-self.height)/time_elapse
                self.vzfilter.add_raw_data(self.vel)
                self.vel = self.vzfilter.get_filter_data()
                self.height = e.value*1024.0/1000
            #    print ("Sensor %i: %i" % (e.index, height))
            #    f.write('Height at %.3f\n',height)
            #    f.close()
        return 0

    def LocalErrorCatcher(event):
        print("Phidget Exception: " + str(event.code) + " - " + str(event.details) + ", Exiting...")
        exit(1)

    def get_height(self):
        #with self.lock:
        return self.height

    def get_vel(self):
        #with self.lock:
        return self.vel

    def close_phidget(self):
        print("Closing...")
    #   f = open('sonar.txt','a')
    #   f.write('********************************\n')
    #   f.close()
        try:
            self.device.closePhidget()
        except PhidgetException as e:
            self.LocalErrorCatcher(e)
开发者ID:JXS2012,项目名称:CourseAppliedControl,代码行数:79,代码来源:sonar.py


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