Beispiel #1
0
def main():
	createDB()

	try:
		manager = Manager()
	except RuntimeError as e:
		print("RuntimeException: %s" % e.details)
		print("Exiting...")
		exit(1)

	try:
		manager.setOnAttachHandler(managerDeviceAttached)
		manager.setOnDetachHandler(managerDeviceDetached)
		manager.setOnErrorHandler(managerErrorHandler)
		manager.setOnServerConnectHandler(managerServerConnect)
		manager.setOnServerDisconnectHandler(managerServerDisconnect)
		manager.openManager()

	except PhidgetException as e:
		print("Phidget Exception %i: %s" % (e.code, e.details))
		print("Exiting...")
		exit(1)
	try:
		manager.openManager()
	except PhidgetException as e:
		print("Phidget Exception %i: %s" % (e.code, e.details))
		print("Exiting...")
		exit(1)

	print("Press Enter to quit...")
	chr = sys.stdin.read(1)
	print("Closing...")

	try:
		manager.closeManager()
	except PhidgetException as e:
		print("Phidget Exception %i: %s" % (e.code, e.details))
		print("Exiting...")
		exit(1)
	print("Done.")
	exit(0)
Beispiel #2
0
    print("Phidget Exception: " + str(e.code) + " - " + str(e.details) + ", Exiting...")
    exit(1)


# ========= Main Code ==========

try:
    manager = Manager()
except RuntimeError as e:
    print("Runtime Error " + e.details + ", Exiting...\n")
    exit(1)

try:
    manager.setOnAttachHandler(AttachHandler)
    manager.setOnDetachHandler(DetachHandler)
    manager.setOnErrorHandler(LibraryErrorHandler)
except PhidgetException as e:
    LocalErrorCatcher(e)

print("Opening....")
try:
    # This would be openPhidget for a specific device object
    manager.openManager()
except PhidgetException as e:
    LocalErrorCatcher(e)

print("Phidget Simple Playground (plug and unplug devices)")
print("Press Enter to end anytime...")
character = str(raw_input())

print("Closing...")
Beispiel #3
0
    print("Manager Phidget Error %i: %s" % (e.eCode, e.description))


#Create an interfacekit object
try:
    mngr = Manager()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)

#Main Program Code
try:
    mngr.setOnAttachHandler(ManagerDeviceAttached)
    mngr.setOnDetachHandler(ManagerDeviceDetached)
    mngr.setOnErrorHandler(ManagerError)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Opening phidget manager....")

try:
    mngr.openManager()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

attachedDevices = mngr.getAttachedDevices()
Beispiel #4
0
def ManagerError(e):
    print("Manager Phidget Error %i: %s" % (e.eCode, e.description))

#Create an interfacekit object
try:
    mngr = Manager()
except RuntimeError as e:
    print("Runtime Exception: %s" % e.details)
    print("Exiting....")
    exit(1)

#Main Program Code
try:
    mngr.setOnAttachHandler(ManagerDeviceAttached)
    mngr.setOnDetachHandler(ManagerDeviceDetached)
    mngr.setOnErrorHandler(ManagerError)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Opening phidget manager....")

try:
    mngr.openManager()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

attachedDevices = mngr.getAttachedDevices()
Beispiel #5
0
def setup_phidgets():
    global interfaceKits
    interfaceKits = InterfaceKits()

    "Print Creating phidget manager"
    try:
        manager = Manager()
    except RuntimeError as e:
        output("Runtime Exception: %s" % e.details)
        output("Exiting....")
        exit(1)

    try:
        manager.setOnAttachHandler(ManagerDeviceAttached)
        manager.setOnDetachHandler(ManagerDeviceDetached)
        manager.setOnErrorHandler(ManagerError)
    except PhidgetException as e:
        output("Phidget Exception %i: %s" % (e.code, e.details))
        output("Exiting....")
        exit(1)

    output("Opening phidget manager....")
    logging.info("Opening phidget manager....")

    try:
        manager.openManager()
        #manager.openRemote("hydropi","hydropi")
    except PhidgetException as e:
        output("Phidget Exception %i: %s" % (e.code, e.details))
        logging.error("Phidget Exception %i: %s" % (e.code, e.details))
        output("Exiting....")
        logging.error("Exiting....")
        exit(1)

    # Wait a moment for devices to attache......
    output("\nWaiting one sec for devices to attach....\n\n")
    logging.info("Waiting one sec for devices to attach....")
    time.sleep(1)

    output("Phidget manager opened.")

    attachedDevices = manager.getAttachedDevices()
    for attachedDevice in attachedDevices:
     
        output("Found %30s - SN %10d" % (attachedDevice.getDeviceName(), attachedDevice.getSerialNum()))
        if attachedDevice.getDeviceClass() == PhidgetClass.INTERFACEKIT:
            output("  %s/%d is an InterfaceKit" % ( attachedDevice.getDeviceName(),attachedDevice.getSerialNum()))
            #Create an interfacekit object
            try:
                newInterfaceKit = InterfaceKit()
            except RuntimeError as e:
                output("Runtime Exception: %s" % e.details)
                output("Exiting....")
                exit(1)

            output("  Opening...")
            try:
                newInterfaceKit.openPhidget()
            except PhidgetException as e:
                output("Phidget Exception %i: %s" % (e.code, e.details))
                output("Exiting....")

            output("  Setting handlers...")
            try:
                newInterfaceKit.setOnAttachHandler(interfaceKitAttached)
                newInterfaceKit.setOnDetachHandler(interfaceKitDetached)
                newInterfaceKit.setOnErrorhandler(interfaceKitError)
            except PhidgetException as e:
                output("Phidget Exception %i: %s" % (e.code, e.details))
                output("Exiting....")
                exit(1)

            output("  Attaching...")
            try:
                newInterfaceKit.waitForAttach(5000)
            except PhidgetException as e:
                output("Phidget Exception %i: %s" % (e.code, e.details))
                try:
                    newInterfaceKit.closePhidget()
                except PhidgetException as e:
                    output("Phidget Exception %i: %s" % (e.code, e.details))
                    output("Exiting....")
                    exit(1)
                output("Exiting....")
                exit(1)

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

            interfaceKits.kitList.append(newInterfaceKit)
            
        
    display_device_info(manager)
    return manager 
Beispiel #6
0
# ========= Main Code ==========

try:
    manager = Manager()
except RuntimeError as e:
    print("Runtime Error " + e.details + ", Exiting...\n")
    exit(1)

try:
    #logging example, uncomment to generate a log file
    #manager.enableLogging(PhidgetLogLevel.PHIDGET_LOG_VERBOSE, "phidgetlog.log")

    manager.setOnAttachHandler(AttachHandler)
    manager.setOnDetachHandler(DetachHandler)
    manager.setOnErrorHandler(LibraryErrorHandler)
except PhidgetException as e:
    LocalErrorCatcher(e)

print("Opening....")
try:
    # This would be openPhidget for a specific device object
    manager.openManager()
except PhidgetException as e:
    LocalErrorCatcher(e)

print("Phidget Simple Playground (plug and unplug devices)")
print("Press Enter to end anytime...")
character = str(raw_input())

print("Closing...")