#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Uisng multiple phidget interfacekit in single python program


    im trying to use multiple interfacekit pidget in a single python program here my coding but der the single phidget oly getting attache. and working.

    #Basic imports
    from ctypes import *
    import sys
    import random
    #Phidget specific imports
    from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
    from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, InputChangeEventArgs, OutputChangeEventArgs, SensorChangeEventArgs
    from Phidgets.Devices.InterfaceKit import InterfaceKit
    from time import sleep
    #Create an interfacekit object
    try:
    interfaceKit = InterfaceKit()
    except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)
    def inferfaceKitAttached(e):
    attached = e.device
    print("InterfaceKit %i Attached!" % (attached.getSerialNum()))

    def interfaceKitDetached(e):
    detached = e.device
    print("InterfaceKit %i Detached!" % (detached.getSerialNum()))

    def interfaceKitError(e):
    try:
    source = e.device
    print("InterfaceKit %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
    except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))

    #def interfaceKitInputChanged(e):
    # source = e.device
    # print("InterfaceKit %i: Input %i: %s" % (source.getSerialNum(), e.index, e.state))

    #def interfaceKitOutputChanged(e):
    # source = e.device
    # print("InterfaceKit %i: Output %i: %s" % (source.getSerialNum(), e.index, e.state))

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

    try:
    #interfaceKit.openPhidget(277983)
    interfaceKit.openPhidget()
    #interfaceKit.openPhidget(273506)
    except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

    print("Waiting for attach....")

    try:
    interfaceKit.waitForAttach(10000)
    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)
    else:
    interfaceKit.setOutputState(0,1);
    interfaceKit.setOutputState(1,1);
    interfaceKit.closePhidget()
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,702
    Rep Power
    480

    Lesson learned!


    phidgets are some sort of usb hardware.

    You're more likely to get a reasonable answer if you ask your question at the phidgets web site, if they support customers.

    Also, You've made me realize a new great reason to avoid

    from module import *

    It's about impossible to read your program because I need to know the entire name spaces of these modules. I certainly hope to remember this lesson and never ever again even consider import * .

    You might have intended this python program?
    Code:
    #http://www.phidgets.com/
    
    
    #Basic imports
    from ctypes import *
    import sys
    import random
    #Phidget specific imports
    from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException
    from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, InputChangeEventArgs, OutputChangeEventArgs, SensorChangeEventArgs
    from Phidgets.Devices.InterfaceKit import InterfaceKit
    from time import sleep
    #Create an interfacekit object
    try:
        interfaceKit = InterfaceKit()
    except RuntimeError as e:
        print("Runtime Exception: %s" % e.details)
        print("Exiting....")
        exit(1)
    
    def inferfaceKitAttached(e):
        attached = e.device
        print("InterfaceKit %i Attached!" % (attached.getSerialNum()))
    
    def interfaceKitDetached(e):
        detached = e.device
        print("InterfaceKit %i Detached!" % (detached.getSerialNum()))
    
    def interfaceKitError(e):
        try:
            source = e.device
            print("InterfaceKit %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description))
        except PhidgetException as e:
            print("Phidget Exception %i: %s" % (e.code, e.details))
    
    #def interfaceKitInputChanged(e):
    # source = e.device
    # print("InterfaceKit %i: Input %i: %s" % (source.getSerialNum(), e.index, e.state))
    
    #def interfaceKitOutputChanged(e):
    # source = e.device
    # print("InterfaceKit %i: Output %i: %s" % (source.getSerialNum(), e.index, e.state))
    
    #Main Program Code
    try:
        interfaceKit.setOnAttachHandler(inferfaceKitAttached)
        interfaceKit.setOnDetachHandler(interfaceKitDetached)
        interfaceKit.setOnErrorhandler(interfaceKitError)
        # interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
        #interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
        # interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    
    print("Opening phidget object....")
    
    try:
        #interfaceKit.openPhidget(277983) 
        interfaceKit.openPhidget() 
        #interfaceKit.openPhidget(273506)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)
    
    print("Waiting for attach....")
    
    try:
        interfaceKit.waitForAttach(10000)
    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)
    else:
        interfaceKit.setOutputState(0,1); 
        interfaceKit.setOutputState(1,1);
        interfaceKit.closePhidget()
    Last edited by b49P23TIvg; October 18th, 2012 at 08:56 AM. Reason: reorganized for clarity
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo