Example #1
0
 def __init__(self):
     """The Constructor Method for the RFID Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
     """
     Phidget.__init__(self)
     
     self.__outputChange = None
     self.__tagGain = None
     self.__tagLoss = None
     
     self.__onTagHandler = None
     self.__onTagLostHandler = None
     self.__onOutputChange = None
     
     try:
         PhidgetLibrary.getDll().CPhidgetRFID_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if sys.platform == 'win32':
         self.__OUTPUTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__TAGHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_char_p, c_int)
         self.__TAGLOSTHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_char_p, c_int)
     elif sys.platform == 'darwin' or sys.platform == 'linux2':
         self.__OUTPUTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__TAGHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_char_p, c_int)
         self.__TAGLOSTHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_char_p, c_int)
Example #2
0
File: GPS.py Project: cyface/boxbot
    def __init__(self):
        """The Constructor Method for the GPS Class

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
        """
        Phidget.__init__(self)

        self.__positionChangeDelegate = None;
        self.__positionFixStatusChangeDelegate = None;

        self.__onPositionChangeHandler = None;
        self.__onPositionFixStatusChangeHandler = None;

        try:
            PhidgetLibrary.getDll().CPhidgetGPS_create(byref(self.handle))
        except RuntimeError:
            raise

        if sys.platform == 'win32':
            self.__POSITIONCHANGEHANDLER = ctypes.WINFUNCTYPE(c_int, c_void_p, c_void_p, c_double, c_double, c_double)
            self.__POSITIONFIXSTATUSCHANGEHANDLER = ctypes.WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int)
        elif sys.platform == 'darwin' or sys.platform == 'linux2':
            self.__POSITIONCHANGEHANDLER = ctypes.CFUNCTYPE(c_int, c_void_p, c_void_p, c_double, c_double, c_double)
            self.__POSITIONFIXSTATUSCHANGEHANDLER = ctypes.CFUNCTYPE(c_int, c_void_p, c_void_p, c_int)
Example #3
0
 def __init__(self):
     """The Constructor Method for the RFID Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
     """
     Phidget.__init__(self)
     
     hexArray = c_char*16
     self.__hexLookup = hexArray(b'0', b'1', b'2', b'3', b'4',
         b'5', b'6', b'7', b'8', b'9', b'A', b'B', b'C', b'D', b'E', b'F')
     
     self.__outputChange = None
     self.__tagGain = None
     self.__tagLoss = None
     
     self.__onTagHandler = None
     self.__onTagLostHandler = None
     self.__onOutputChange = None
     
     try:
         PhidgetLibrary.getDll().CPhidgetRFID_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if sys.platform == 'win32':
         self.__OUTPUTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__TAGHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte))
         self.__TAGLOSTHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte))
     elif sys.platform == 'darwin' or sys.platform == 'linux2':
         self.__OUTPUTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__TAGHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte))
         self.__TAGLOSTHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte))
Example #4
0
 def __init__(self):
     """The Constructor Method for the Accelerometer Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
     """
     Phidget.__init__(self)
     
     self.__IRCodeDelegate = None;
     self.__IRLearnDelegate = None;
     self.__IRRawDataDelegate = None;
     
     self.__onIRCodeHandler = None;
     self.__onIRLearnHandler = None;
     self.__onIRRawDataHandler = None;
     
     try:
         PhidgetLibrary.getDll().CPhidgetIR_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if sys.platform == 'win32':
         self.__IRCODEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte), c_int, c_int, c_int)
         self.__IRLEARNHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte), c_int, POINTER(CPhidgetIR_CodeInfo))
         self.__IRRAWDATAHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_int), c_int)
     elif sys.platform == 'darwin' or sys.platform.startswith('linux'):
         self.__IRCODEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte), c_int, c_int, c_int)
         self.__IRLEARNHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_ubyte), c_int, POINTER(CPhidgetIR_CodeInfo))
         self.__IRRAWDATAHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, POINTER(c_int), c_int)
Example #5
0
 def __init__(self):
     """The Constructor Method for the Encoder Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened.
     """
     Phidget.__init__(self)
     
     self.__inputChange = None
     self.__positionChange = None
     
     self.__onInputChange = None
     self.__onPositionChange = None
     
     try:
         PhidgetLibrary.getDll().CPhidgetEncoder_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if sys.platform == 'win32':
         self.__INPUTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__POSITIONCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int, c_int)
     elif sys.platform == 'darwin' or sys.platform.startswith('linux'):
         self.__INPUTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__POSITIONCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int, c_int)
Example #6
0
 def __init__(self):
     """The Constructor Method for the InterfaceKit Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened.
     """
     Phidget.__init__(self)
     
     self.__inputChange = None
     self.__outputChange = None
     self.__sensorChange = None
     
     self.__onInputChange = None
     self.__onSensorChange = None
     self.__onOutputChange = None
     
     try:
         PhidgetLibrary.getDll().CPhidgetInterfaceKit_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if sys.platform == 'win32':
         self.__INPUTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__OUTPUTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__SENSORCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
     elif sys.platform == 'darwin' or sys.platform == 'linux2':
         self.__INPUTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__OUTPUTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
         self.__SENSORCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
 def __init__(self):
     """The Constructor Method for the AdvancedServo Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
     """
     Phidget.__init__(self)
     
     self.__currentChange = None
     self.__positionChange = None
     self.__velocityChange = None
     
     self.__onCurrentChange = None
     self.__onPositionChange = None
     self.__onVelocityChange = None
     
     try:
         PhidgetLibrary.getDll().CPhidgetAdvancedServo_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if sys.platform == 'win32':
         self.__CURRENTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
         self.__POSITIONCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
         self.__VELOCITYCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
     elif sys.platform == 'darwin' or sys.platform == 'linux2':
         self.__CURRENTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
         self.__POSITIONCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
         self.__VELOCITYCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
Example #8
0
 def __init__(self):
     """The Constructor Method for the Accelerometer Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
     """
     Phidget.__init__(self)
     
     self.__numAccelAxes = 0;
     self.__numGyroAxes = 0;
     self.__numCompassAxes = 0;
     
     self.__attach = None
     self.__spatialData = None;
     
     self.__onAttach = None
     self.__onSpatialData = None;
     
     try:
         PhidgetLibrary.getDll().CPhidgetSpatial_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if sys.platform == 'win32':
         self.__ATTACHHANDLER = WINFUNCTYPE(c_long, c_void_p, c_void_p)
         self.__SPATIALDATAHANDLER = WINFUNCTYPE(c_long, c_void_p, c_void_p, POINTER(c_long), c_long)
     elif sys.platform == 'darwin' or sys.platform == 'linux2':
         self.__ATTACHHANDLER = CFUNCTYPE(c_long, c_void_p, c_void_p)
         self.__SPATIALDATAHANDLER = CFUNCTYPE(c_long, c_void_p, c_void_p, POINTER(c_long), c_long)
Example #9
0
 def closeDictionary(self):
     """Closes this Dictionary.
     
     This will shut down all threads dealing with this Dictionary and you won't recieve any more events.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Dictionary is not opened.
     """
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetDictionary_close(self.handle)
     except RuntimeError:
         raise
     
     if result > 0:
         description = Phidget.getErrorDescription(result)
         raise PhidgetException(result, description)
     else:
         try:
             result = PhidgetLibrary.getDll().CPhidgetDictionary_delete(self.handle)
         except RuntimeError:
             raise
         
         if result > 0:
             raise PhidgetException(result)
Example #10
0
 def __init__(self):
     """The Constructor Method for the TextLCD Class
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
     """
     Phidget.__init__(self)
     
     try:
         PhidgetLibrary.getDll().CPhidgetTextLCD_create(byref(self.handle))
     except RuntimeError:
         raise
Example #11
0
    def __init__(self):
        """The Constructor Method for the MotorControl Class
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
        """
        Phidget.__init__(self)

        self.__inputChange = None
        self.__velocityChange = None
        self.__currentChange = None
        self.__currentUpdate = None
        self.__positionChange = None
        self.__positionUpdate = None
        self.__sensorUpdate = None
        self.__backEMFUpdate = None

        self.__onInputChange = None
        self.__onVelocityChange = None
        self.__onCurrentChange = None
        self.__onCurrentUpdate = None
        self.__onPositionChange = None
        self.__onPositionUpdate = None
        self.__onSensorUpdate = None
        self.__onBackEMFUpdate = None

        try:
            PhidgetLibrary.getDll().CPhidgetMotorControl_create(byref(self.handle))
        except RuntimeError:
            raise

        if sys.platform == "win32":
            self.__INPUTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
            self.__VELOCITYCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
            self.__CURRENTCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
            self.__CURRENTUPDATEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
            self.__POSITIONCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int, c_int)
            self.__POSITIONUPDATEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
            self.__SENSORUPDATEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
            self.__BACKEMFUPDATEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
        elif sys.platform == "darwin" or sys.platform == "linux2":
            self.__INPUTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
            self.__VELOCITYCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
            self.__CURRENTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
            self.__CURRENTUPDATEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
            self.__POSITIONCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int, c_int)
            self.__POSITIONUPDATEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
            self.__SENSORUPDATEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_int)
            self.__BACKEMFUPDATEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
Example #12
0
File: GPS.py Project: cyface/boxbot
    def setOnPositionChangeHandler(self, positionChangeHandler):
        """Set the GPS Position Change Event Handler.

        An event that is issued whenever a change in position occurs. Event arguments are latitude, longitude, altitude.

        Parameters:
            positionChangeHandler: hook to the positionChangeHandler callback function.

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException
        """
        if positionChangeHandler is None:
            self.__positionChangeDelegate = None
            self.__onPositionChangeHandler = None
        else:
            self.__positionChangeDelegate = positionChangeHandler
            self.__onPositionChangeHandler = self.__POSITIONCHANGEHANDLER(self.__nativePositionChangeEvent)

        try:
            result = PhidgetLibrary.getDll().CPhidgetGPS_set_OnPositionChange_Handler(self.handle, self.__onPositionChangeHandler, None)
        except RuntimeError:
            self.__positionChangeDelegate = None
            self.__onPositionChangeHandler = None
            raise

        if result > 0:
            raise PhidgetException(result)
Example #13
0
 def getCursorBlink(self):
     """Returns the status of the cursor blink.
     
     True indicates that the cursor blink is on, False indicates that it is off.
     The cursor blink is an flashing box which appears directly to the right of
     the last entered character on the display, in the same spot as the cursor if it is enabled.
     The cursor blink is by default disabled.
     
     Returns:
         The current status of the cursor blink <boolean>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     cursorBlinkStatus = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_getCursorBlink(self.handle, byref(cursorBlinkStatus))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if cursorBlinkStatus.value == 1:
             return True
         else:
             return False
Example #14
0
 def setDisplayString(self, index, string):
     """Sets the display string of a certain row.
     
     If the string is longer then the row, it will be truncated.
     
     On linux, it has been found that encoding the string with iso-8859-15 encoding prevents a "UnicodeEncodeError" that would occur and ensure
     the character being displayed is correct between windows and linux.
     
     e.g. textLCD.setDisplayString(0, chr(223).encode("iso-8859-15"))
     
     Parameters:
         index<int>: the index of the row to write the string to.
         string<string>: the string to display.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the row index is invalid.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_setDisplayString(self.handle, c_int(index), c_char_p(string))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #15
0
 def setCursorBlink(self, state):
     """Sets the state of the cursor blink.
     
     True turns the cursor blink on, False turns it off.
     The cursor blink is an flashing box which appears directly to the right
     of the last entered character on the display, in the same spot as the cursor if it is enabled.
     The cursor blink is by default disabled.
     
     Parameters:
         state - the desired state of the cursor blink <boolean>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     if state == True:
         value = 1
     else:
         value = 0
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_setCursorBlink(self.handle, c_int(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #16
0
 def getBacklight(self):
     """Returns the status of the backlight.
     
     True indicated that the backlight is on, False indicated that it is off.
     The backlight is by default turned on.
     
     Returns:
         The status of the backlight <boolean>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     backlightStatus = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_getBacklight(self.handle, byref(backlightStatus))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if backlightStatus.value == 1:
             return True
         else:
             return False
Example #17
0
 def setBacklight(self, state):
     """Sets the status of the backlight.
     
     True turns the backlight on, False turns it off.
     The backlight is by default turned on.
     
     Parameters:
         state<boolean>: the desired backlight state.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     if state == True:
         value = 1
     else:
         value = 0
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_setBacklight(self.handle, c_int(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #18
0
 def isAttachedToServer(self):
     """Returns the network attached status for remotely opened Phidgets.
     
     This method returns True or False, depending on whether a connection to the Phidget WebService is open - or not.
     If this is false for a remote Phidget then the connection is not active - either because a connection has not yet been established,
     or because the connection was terminated.
     
     Returns:
         The attached status <boolean>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: if the Manager was not opened or opened remotely.
     """
     serverStatus = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_getServerStatus(self.handle, byref(serverStatus))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if serverStatus.value == 1:
             return True
         else:
             return False
Example #19
0
 def setOnAttachHandler(self, attachHandler):
     """Set the Attach event handler.
     
     The attach handler is a method that will be called when a Phidget is phisically attached to the system,
     and has gone through its initalization, and so is ready to be used.
     
     Parameters:
         attachHandler: hook to the attachHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     if attachHandler == None:
         self.__attach = None
         self.__onAttach = None
     else:
         self.__attach = attachHandler
         self.__onAttach = self.__ATTACHHANDLER(self.__nativeAttachEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_set_OnAttach_Handler(self.handle, self.__onAttach, None)
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #20
0
 def setOnServerDisconnectHandler(self, serverDisconnectHandler):
     """Sets the ServerDisconnect event handler.
     
     The serverDisconnect handler is a method that will be called when a connection to a server is terminated.
     
     Parameters:
         serverDisconnectHandler: hook to the serverDisconnectHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     if serverDisconnectHandler == None:
         self.__serverDisconnect = None
         self.__onServerDisconnect = None
     else:
         self.__serverDisconnect = serverDisconnectHandler
         self.__onServerDisconnect = self.__SERVERDETACHHANDLER(self.__nativeServerDisconnectEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_set_OnServerDisconnect_Handler(self.handle, self.__onServerDisconnect, None)
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #21
0
 def getAttachedDevices(self):
     """Returns a list of Phidgets attached to the host computer.
     
     This list is updated right before the attach and detach events, and so will be up to date within these events.
     
     Returns:
         The list of attached phidgets <array of Phidget objects>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     devices = []
     count = c_int()
     listptr = pointer(c_void_p())
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_getAttachedDevices(self.handle, byref(listptr), byref(count))
     except RuntimeError:
         raise
     
     if result > 0:
             raise PhidgetException(result)
     
     for i in range(count.value):
         phid = Phidget()
         devicePtr = c_void_p(listptr[i])
         phid.handle = devicePtr
         devices.append(phid)
     
     return devices
Example #22
0
 def setOnDetachHandler(self, detachHandler):
     """Set the Detach event handler.
     
     The detach handler is a method that will be called when a Phidget is phisically detached from the system, and is no longer available.
     
     Parameters:
         detachHandler: hook to the detachHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     if detachHandler == None:
         self.__detach = None
         self.__onDetach = None
     else:
         self.__detach = detachHandler
         self.__onDetach = self.__DETACHHANDLER(self.__nativeDetachEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_set_OnDetach_Handler(self.handle, self.__onDetach, None)
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #23
0
 def setOnErrorHandler(self, errorHandler):
     """Sets the error event handler.
     
     The error handler is a method that will be called when an asynchronous error occurs.
     Error events are not currently used, but will be in the future to report any problems that happen out of context from a direct function call.
     
     Parameters:
         errorHandler: hook to the errorHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     if errorHandler == None:
         self.__error = None
         self.__onError = None
     else:
         self.__error = errorHandler
         self.__onError = self.__ERRORHANDLER(self.__nativeErrorEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_set_OnError_Handler(self.handle, self.__onError, None)
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
 def getStopped(self, index):
     """Gets the stopped state of a motor.
     
     This is true when the motor is not moving and there are no outstanding commands.
     
     Parameters:
         index<int>: index of the motor.
     
     Returns:
         The current state of the stopped flag for this motor<boolean>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is invalid.
     """
     stoppedState = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetAdvancedServo_getStopped(self.handle, c_int(index), byref(stoppedState))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if stoppedState.value == 1:
             return True
         else:
             return False
 def getAcceleration(self, index):
     """Returns a motor's acceleration.
     
     The valid range is between getAccelerationMin and getAccelerationMax,
     and refers to how fast the AdvancedServo Controller will change the speed of a motor.
     
     Parameters:
         index<int>: index of motor.
     
     Returns:
         The acceleration of the motor <double>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is invalid.
     """
     accel = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetAdvancedServo_getAcceleration(self.handle, c_int(index), byref(accel))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return accel.value
 def getSpeedRampingOn(self, index):
     """Gets the speed ramping state for a motor.
     
     This is whether or not velocity and acceleration are used.
     
     Parameters:
         index<int>: index of the motor.
     
     Returns:
         The current state of the speedRamping flag for this motor<boolean>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is invalid.
     """
     rampingState = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetAdvancedServo_getSpeedRampingOn(self.handle, c_int(index), byref(rampingState))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if rampingState.value == 1:
             return True
         else:
             return False
 def setOnPositionChangeHandler(self, positionChangeHandler):
     """Sets the Position Change Event Handler.
     
     The servo position change handler is a method that will be called when the servo position has changed.
     The event will get fired after every call to setPosition.
     
     Parameters:
         positionChangeHandler: hook to the positionChangeHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     if positionChangeHandler == None:
         self.__positionChange = None
         self.__onPositionChange = None
     else:
         self.__positionChange = positionChangeHandler
         self.__onPositionChange = self.__POSITIONCHANGEHANDLER(self.__nativePositionChangeEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetAdvancedServo_set_OnPositionChange_Handler(self.handle, self.__onPositionChange, None)
     except RuntimeError:
         self.__positionChange = None
         self.__onPositionChange = None
         raise
     
     if result > 0:
         raise PhidgetException(result)
 def setOnCurrentChangeHandler(self, currentChangeHandler):
     """Sets the CurrentCHange Event Handler.
     
     The current change handler is a method that will be called when the current consumed by a motor changes.
     
     Parameters:
         currentChangeHandler: hook to the currentChangeHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     if currentChangeHandler == None:
         self.__currentChange = None
         self.__onCurrentChange = None
     else:
         self.__currentChange = currentChangeHandler
         self.__onCurrentChange = self.__CURRENTCHANGEHANDLER(self.__nativeCurrentChangeEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetAdvancedServo_set_OnCurrentChange_Handler(self.handle, self.__onCurrentChange, None)
     except RuntimeError:
         self.__currentChange = None
         self.__onCurrentChange = None
         raise
     
     if result > 0:
         raise PhidgetException(result)
 def setEngaged(self, index, state):
     """Sets the engaged state of a motor.
     
     This is whether the motor is powered or not.
     
     Parameters:
         index<int>: Index of the motor.
         state<boolean>: State to set the engaged flag for this motor to.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is out of range.
     """
     if state == True:
         value = 1
     else:
         value = 0
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetAdvancedServo_setEngaged(self.handle, c_int(index), c_int(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #30
0
File: GPS.py Project: cyface/boxbot
    def setOnPositionFixStatusChangeHandler(self, positionFixStatusChangeHandler):
        """Set the GPS Position Fix Status Change Event Handler.

        An event that is issued when a position fix is obtained or lost. The event argument can be used to inform you whether or not you are getting a signal.

        Parameters:
            positionFixStatusChangeHandler: hook to the positionFixStatusChangeHandler callback function.

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException
        """
        if positionFixStatusChangeHandler == None:
            self.__positionFixStatusChangeDelegate = None
            self.__onPositionFixStatusChangeHandler = None
        else:
            self.__positionFixStatusChangeDelegate = positionFixStatusChangeHandler
            self.__onPositionFixStatusChangeHandler = self.__POSITIONFIXSTATUSCHANGEHANDLER(self.__nativePositionFixStatusChangeEvent)

        try:
            result = PhidgetLibrary.getDll().CPhidgetGPS_set_OnPositionFixStatusChange_Handler(self.handle, self.__onPositionFixStatusChangeHandler, None)
        except RuntimeError:
            self.__positionFixStatusChangeDelegate = None
            self.__onPositionFixStatusChangeHandler = None
            raise

        if result > 0:
            raise PhidgetException(result)
Example #31
0
    def getEncoderCount(self):
        """Returns number of encoders.
        
        All current encoder boards support one encoder.
        
        Returns:
            The number of encoders <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        encoderCount = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetEncoder_getEncoderCount(
                self.handle, byref(encoderCount))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return encoderCount.value
Example #32
0
    def getBrightness(self):
        """Returns the brightness of the display.
        
        This is the brightness of the entire display. For devices that support a range of backlight brightnesses.
        
        Returns:
            The current brightness setting <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        brightness = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetTextLCD_getBrightness(
                self.handle, byref(brightness))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return brightness.value
Example #33
0
    def getColumnCount(self):
        """Returns the number of columns (characters per row) available on the display.
        
        This value is the same for every row.
        
        Returns:
            The number of rows <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        columnCount = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetTextLCD_getColumnCount(
                self.handle, byref(columnCount))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return columnCount.value
Example #34
0
    def getOutputCount(self):
        """Returns the number of outputs.
        
        These are the outputs provided by the terminal block. Older RFID readers do not have these outputs, and this method will return 0.
        
        Returns:
            The number of outputs available <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        outputCount = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetRFID_getOutputCount(
                self.handle, byref(outputCount))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return outputCount.value
Example #35
0
    def getOutputCount(self):
        """Returns the number of analog outputs.

        Currently all Phidget Analogs provide two analog outputs.

        Returns:
            The number of Available analog outputs <int>.

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this phidget is not opened or attached.
        """
        outputCount = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetAnalog_getOutputCount(
                self.handle, byref(outputCount))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return outputCount.value
Example #36
0
    def getDeviceClass(self):
        """Gets the class of this Phidget.
        
        Classes represent a group of Phidgets that use the same API type.
        
        Returns:
            The Device Class number<int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If there is no Phidget attached.
        """
        classNum = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidget_getDeviceClass(
                self.handle, byref(classNum))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return classNum.value
Example #37
0
 def getServerAddress(self):
     """Returns the Address of a Phidget Webservice when this Manager was opened as remote.
     
     This may be an IP Address or a hostname.
     
     Returns:
         The server address for the webservice <string>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: if the Manager was not opened or opened remotely.
     """
     serverAddr = c_char_p()
     port = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_getServerAddress(self.handle, byref(serverAddr), byref(port))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return serverAddr.value
Example #38
0
 def getMagneticField(self, index):
     """Gets the current magnetic field stregth of an axis, in Gauss.
     
     Parameters:
         index<int>: index of the axis.
     
     Returns:
         The Magnetic Field strength for this compass axis, in Gauss. <double>
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is out of range.
     """
     value = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetSpatial_getMagneticField(self.handle, c_int(index), byref(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return value.value
Example #39
0
 def getRatiometric(self):
     """Gets the ratiometric state for the analog sensors
     
     Returns:
         State of the Ratiometric setting.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if this phidget does not support ratiometric.
     """
     ratiometricState = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetInterfaceKit_getRatiometric(self.handle, byref(ratiometricState))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if ratiometricState.value == 1:
             return True
         else:
             return False
Example #40
0
 def setOnOutputChangeHandler(self, outputChangeHandler):
     """Sets the OutputChange Event Handler.
     
     The output change handler is a method that will be called when an output on this Interface Kit has changed.
     
     Parameters:
         outputChangeHandler: hook to the outputChangeHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     self.__outputChange = outputChangeHandler
     self.__onOutputChange = self.__OUTPUTCHANGEHANDLER(self.__nativeOutputChangeEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetInterfaceKit_set_OnOutputChange_Handler(self.handle, self.__onOutputChange, None)
     except RuntimeError:
         self.__outputChange = None
         self.__onOutputChange = None
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #41
0
    def getSerialNum(self):
        """Returns the unique serial number of this Phidget.
        
        This number is set during manufacturing, and is unique across all Phidgets. This number can be used in calls to open to specify this specific Phidget to be opened.
        
        Returns:
            The Serial Number <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        serialNo = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidget_getSerialNumber(
                self.handle, byref(serialNo))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return serialNo.value
Example #42
0
    def getDeviceID(self):
        """Gets the ID of this Phidget.
        
        This ID specifies a specific Phidget device, within the phidget class.
        
        Returns:
            The Device ID <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If there is no Phidget attached.
        """
        deviceID = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidget_getDeviceID(
                self.handle, byref(deviceID))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return deviceID.value
Example #43
0
    def getServerID(self):
        """Returns the Server ID of a Phidget Webservice when this Dictionary was opened as remote.
        
        This is an arbitrary server identifier, independant of IP address and Port.
        
        Returns:
            The ServerID for the webservice <string>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: if this Dictionary was not opened.
        """
        serverID = c_char_p()

        try:
            result = PhidgetLibrary.getDll().CPhidgetDictionary_getServerID(
                self.handle, byref(serverID))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return serverID.value
    def setPosition(self, index, value):
        """Sets the position of a servo motor.
        
        The range here is between getPositionMin and getPositionMax, and corresponds aproximately to an angle in degrees.
        Note that most servos will not be able to operate accross this entire range.
        Typically, the range might be 25 - 180 degrees, but this depends on the servo.
        
        Parameters:
            index<int>: index of the motor.
            position<double>: desired position for the motor.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached, or if the index or position is out of range,
            or if the desired position is out of range, or if the motor is not engaged.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetAdvancedServo_setPosition(
                self.handle, c_int(index), c_double(value))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #45
0
    def __init__(self):
        """The Constructor Method for the Dictionary Class
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened.
        """
        self.handle = c_void_p()

        self.__error = None
        self.__serverConnect = None
        self.__serverDisconnect = None

        self.__onError = None
        self.__onServerConnect = None
        self.__onServerDisconnect = None

        if sys.platform == 'win32':
            self.__ERRORHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int,
                                              c_char_p)
            self.__SERVERATTACHHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p)
            self.__SERVERDETACHHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p)
        elif sys.platform == 'darwin' or sys.platform == 'linux2':
            self.__ERRORHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int,
                                            c_char_p)
            self.__SERVERATTACHHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p)
            self.__SERVERDETACHHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p)

        try:
            result = PhidgetLibrary.getDll().CPhidgetDictionary_create(
                byref(self.handle))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #46
0
    def start(self):
        """Start this key listener.
        
        This method should not be called until the coresponding dictionary is connected.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Dictionary is not opened.
        """
        self.__onKeyChange = self.__KEYCHANGEHANDLER(self.__nativeKeyEvent)
        listener = c_int()

        try:
            result = PhidgetLibrary.getDll(
            ).CPhidgetDictionary_set_OnKeyChange_Handler(
                self.__dict.handle, byref(listener),
                c_char_p(self.__keyPattern), self.__onKeyChange, None)
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)

        self.__listenerHandle = listener
Example #47
0
File: IR.py Project: Jak23/modular
 def getLastLearnedCode(self):
     """Gets the last code the was learned.
     
     Returns:
         The last IR Code Learned. <IRLearnedCode>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     codePtr = (c_ubyte * IR_MAX_CODE_DATA_LENGTH)()
     dataLength = c_int(IR_MAX_CODE_DATA_LENGTH)
     codeInfo = CPhidgetIR_CodeInfo()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetIR_getLastLearnedCode(self.handle, codePtr, byref(dataLength), byref(codeInfo))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         learnedCode = IRLearnedCode(IRCode(codePtr, codeInfo.bitCount), IRCodeInfo(codeInfo))
         return learnedCode
Example #48
0
    def setErrorHandler(self, errorhandler):
        """Sets the Error Event Handler.
        
        Parameters:
            errorhandler: hook to the errorhandler callback function.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException
        """
        self.__error = errorhandler
        self.__onError = self.__ERRORHANDLER(self.__nativeErrorEvent)

        try:
            result = PhidgetLibrary.getDll(
            ).CPhidgetDictionary_set_OnError_Handler(self.handle,
                                                     self.__onError, None)
        except RuntimeError:
            self.__error = None
            self.__onError = None
            raise

        if result > 0:
            raise PhidgetException(result)
Example #49
0
File: IR.py Project: Jak23/modular
 def transmit(self, code, codeInfo):
     """Transmits a code
     
     Parameters:
         code<IRCode>: The code to transmit.
         codeInfo<IRCodeInfo>: Code encoding information.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     codeInfoPtr = codeInfo.toCPhidgetIR_CodeInfo()
     codePtr = (c_ubyte * len(code.Data))()
     
     for posn in range(len(code.Data)):
         codePtr[posn] = c_ubyte(code.Data[posn])
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetIR_Transmit(self.handle, codePtr, byref(codeInfoPtr))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #50
0
    def getLEDCount(self):
        """Returns the number of LEDs that this board can drive.
        
        This may not correspond to the actual number of LEDs attached.
        
        Returns:
            The number of available LEDs <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        LEDCount = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetLED_getLEDCount(
                self.handle, byref(LEDCount))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return LEDCount.value
Example #51
0
    def getContrast(self):
        """Returns the contrastof the display.
        
        This is the contrast of the entire display.
        
        Returns:
            The current contrast setting <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        contrast = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetTextLCD_getContrast(
                self.handle, byref(contrast))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return contrast.value
Example #52
0
File: IR.py Project: Jak23/modular
 def getLastCode(self):
     """Gets the last code that was recieved.
     
     Returns:
         The last IR Code received. <IRCode>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     codePtr = (c_ubyte * IR_MAX_CODE_DATA_LENGTH)(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
     dataLength = c_int(IR_MAX_CODE_DATA_LENGTH)
     bitCount = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetIR_getLastCode(self.handle, codePtr, byref(dataLength), byref(bitCount))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         code = IRCode(codePtr, bitCount.value)
         return code
Example #53
0
 def openRemote(self, serverID, password=""):
     """Open this Manager remotely using a Server ID, and securely using a Password.
     
     ServerID can be NULL to get a listing of all Phidgets on all Servers
     
     This password can be set as a parameter when starting the Phidget Webservice.
     The use of a password is optional and calling the function without providing a password will
     connect normally.
     
     Parameters:
         serverID<string>: ServerID of the Phidget Webservice.
         password<string>: The secure password for the Phidget Webservice.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: if the Phidget Webservice cannot be contacted
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetManager_openRemote(self.handle, c_char_p(serverID), c_char_p(password))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #54
0
    def getMotorCount(self):
        """Returns the number of motors this Phidget can support.
        
        Note that there is no way of programatically determining how many motors are actually attached to the board.
        
        Returns:
            The number of motors <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        motorCount = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetServo_getMotorCount(
                self.handle, byref(motorCount))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return motorCount.value
    def setBackEMFSensingState(self, index, state):
        """

        Parameters:
            state<boolean>:

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached, the supplied index is out of range, or if this Motor Controller does not support braking.
        """
        if state == True:
            value = 1
        else:
            value = 0

        try:
            result = PhidgetLibrary.getDll(
            ).CPhidgetMotorControl_setBackEMFSensingState(
                self.handle, c_int(index), c_int(value))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #56
0
 def setCustomCharacter(self, index, part1, part2):
     """Sets a custom character.
     
     You can set up to 8 (0-7) custom characters, each one is completely defined by two integers,
     and gets stored in the character display until power is removed, whence they must be re-programmed.
     
     See TextLCD-simple.py for an example of how this works.
     
     Parameters:
         index<int>: custom character list index.
         part1<int>: first half of the character code.
         part2<int>: second half of the character code.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is invalid.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_setCustomCharacter(self.handle, c_int(index + 8), c_int(part1), c_int(part2))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #57
0
 def getAccelerationMin(self, index):
     """Returns the minimum acceleration value that this axis will report.
     
     This will be set to just lower then the minimum acceleration that this axis can measure.
     If the acceleration is equal to this minimum, assume that that axis is saturated beyond what it can measure.
     
     Returns:
         The Minimum Acceleration <double>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is out of range.
     """
     value = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetSpatial_getAccelerationMin(self.handle, c_int(index), byref(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return value.value
Example #58
0
    def setOnServerDisconnectHandler(self, serverDisconnectHandler):
        """Set the Server Disconnect event handler.
        
        The serverDisconnect handler is a method that will be called when a connection to a server is terminated. This is only usefull for Phidgets opened remotely.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened
        """
        self.__serverDisconnect = serverDisconnectHandler
        self.__onServerDisconnect = self.__SERVERDETACHHANDLER(
            self.__nativeServerDisconnectEvent)

        try:
            result = PhidgetLibrary.getDll(
            ).CPhidget_set_OnServerDisconnect_Handler(
                self.handle, self.__onServerDisconnect, None)
        except RuntimeError:
            self.__serverDisconnect = None
            self.__onServerDisconnect = None
            raise

        if result > 0:
            raise PhidgetException(result)
    def setDisplayCharacter(self, row, column, character):
        """Sets a single character on the display.

        On linux, it has been found that encoding the string with iso-8859-15 encoding prevents a "UnicodeEncodeError" that would occur and ensure
        the character being displayed is correct between windows and linux.

        e.g. textLCD.setDisplayCharacter(0, 0, chr(223).encode("iso-8859-15"))

        Parameters:
            row<int>: the index of the row to write the character to.
            column<int>: the index of the column to write the character to.
            character<char>: the character to display.

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached, or if the row index is invalid.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetTextLCD_setDisplayCharacter(self.handle, c_int(row), c_int(column), c_ubyte(character))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #60
0
 def getAngularRate(self, index):
     """Gets the angular rate of rotation for this Gyro axis, in degrees per second.
     
     Parameters:
         index<int>: index of the axis.
     
     Returns:
         Angular rate of rotation for the selected gyro axis, in degrees per second. <double>
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or if the index is out of range.
     """
     value = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetSpatial_getAngularRate(self.handle, c_int(index), byref(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return value.value