def run(self):
        try:
            manager = Manager()
        except RuntimeError as e:
            print("Runtime Error " + e.details)
            return False

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

        try:
            manager.open()
        except PhidgetException as e:
            return LocalErrorCatcher(e)
        """ Method that runs forever """
        while True:
            # Do something
            print('Doing something imporant in the background (phiget)')

            time.sleep(self.interval)

        try:
            manager.close()
        except PhidgetException as e:
            return LocalErrorCatcher(e)
Exemplo n.º 2
0
class PhidgetHelloWorld():
    '''
    PhidgetHelloWorld.

    Example Usage:

    dev = PhidgetHelloWorld()
    '''
    def __init__(self, *args, **kwargs):

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

        try:
            #logging example, uncomment to generate a log file
            #manager.enableLogging(PhidgetLogLevel.PHIDGET_LOG_VERBOSE, "phidgetlog.log")
            self._manager.setOnAttachHandler(self._phidget_attached)
            self._manager.setOnDetachHandler(self._phidget_detached)
        except PhidgetException as e:
            self._local_error_catcher(e)

    def _local_error_catcher(e):
        print("Phidget Exception: " + str(e.code) + " - " + str(e.details) +
              ", Exiting...")
        raise RuntimeError

    def _phidget_attached(self, phidget, channel):
        serial_number = channel.getDeviceSerialNumber()
        device_name = channel.getDeviceName()
        print("Hello to Device " + str(device_name) + ", Serial Number: " +
              str(serial_number))

    def _phidget_detached(self, phidget, channel):
        serial_number = channel.getDeviceSerialNumber()
        device_name = channel.getDeviceName()
        print("Goodbye Device " + str(device_name) + ", Serial Number: " +
              str(serial_number))

    def open(self):
        print("Opening....")
        try:
            self._manager.open()
        except PhidgetException as e:
            self._local_error_catcher(e)

    def close(self):
        print("Closing...")
        try:
            self._manager.close()
        except PhidgetException as e:
            self._local_error_catcher(e)
Exemplo n.º 3
0
def demo_source_level():
    try:
        #Setting up a manager to be used to demonstrate logging
        #Not required, but serves as a convenient source of log entries
        manager = Manager()

        print("\nDemonstrating Source Level\n")    

        Log.enable(LogLevel.PHIDGET_LOG_INFO, "source_level_log.txt")    

        print("\nSetting source _phidget22channel to LogLevel.PHIDGET_LOG_VERBOSE\n")    

        #Knowing the list of sources, you can set a specific source to a different
        #log level than the others, to allow more or less detail for that source
        Log.setSourceLevel("_phidget22channel", LogLevel.PHIDGET_LOG_VERBOSE)    

        print("\nOpening Manager: Plug and unplug Phidgets, then check source_level_log.txt to\nsee what happened.\n")    

        manager.open()   

        time.sleep(5)    

        print("\nClosing Manager\n")    

        manager.close()  

        time.sleep(1)    

        Log.disable()    

        time.sleep(10)
        
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Press Enter to Exit...\n")
        readin = sys.stdin.read(1)
        exit(1)   
Exemplo n.º 4
0
    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)
except PhidgetException as e:
    LocalErrorCatcher(e)

print("Opening....")
try:
    manager.open()
except PhidgetException as e:
    LocalErrorCatcher(e)

print("Phidget Simple Playground (plug and unplug devices)")
print("Press Enter to end anytime...")
character = sys.stdin.read(1)

print("Closing...")
try:
    manager.close()
except PhidgetException as e:
    LocalErrorCatcher(e)

exit(0)