Ejemplo n.º 1
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 = PhidgetException.getErrorDescription(result)
         raise PhidgetException(result, description)
     else:
         try:
             result = PhidgetLibrary.getDll().CPhidgetDictionary_delete(self.handle)
         except RuntimeError:
             raise
         
         if result > 0:
             raise PhidgetException(result)
Ejemplo n.º 2
0
    def removeKey(self, pattern):
        """Removes a key, or set of keys, from the Dictionary.
        
        The key name is a regular expressions pattern, and so care must be taken to only have it match the specific keys you want to remove.
        
        Parameters:
            pattern<string>: The regular expression pattern to match to the keys you want to remove from the Dictionary.
        
        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().CPhidgetDictionary_removeKey(
                self.handle, c_char_p(pattern))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 3
0
 def setContrast(self, value):
     """Sets the contrast of the display.
     
     The valid range is 0-255.
     Changing the contrast can increase the readability of the display in certain viewing situation, such as at an odd angle.
     
     Parameters:
         value<int>: the desired contrast value.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_setContrast(self.handle, c_int(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Ejemplo n.º 4
0
    def getSupplyVoltage(self):
        """

        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 this feature.
        """
        supplyVoltage = c_double()

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return supplyVoltage.value
Ejemplo n.º 5
0
    def setServoType(self, index, servoType):
        """Sets the desired servo type for a specified motor.
        
        Parameters:
            index<int>: index of a servo motor.
            servoType<int>: The desired servo type 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 is out of range.
        """
        try:
            result = PhidgetLibrary.getDll(
            ).CPhidgetAdvancedServo_setServoType(self.handle, c_int(index),
                                                 c_int(servoType))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 6
0
    def setScreenSize(self, screenSize):
        """Sets the active screen size.

        Only supported on the TextLCD Adapter.

        Parameters:
            screenIndex<int/TextLCD_ScreenSize>: The desired active screen index.

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetTextLCD_setScreenSize(
                self.handle, c_int(screenSize))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 7
0
    def setScreenIndex(self, screenIndex):
        """Sets the active screen.

        This is the screen that all subsequent API calls will apply to.

        Parameters:
            screenIndex<int>: The desired active screen index.

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetTextLCD_setScreen(
                self.handle, c_int(screenIndex))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 8
0
    def setPHChangeTrigger(self, value):
        """Sets the pH change trigger.
        
        This is how much the pH much change between successive PHChangeEvents. By default this value is set to 0.05.
        
        Parameters:
            value<double>: The requested pH change trigger value.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached, or the trigger value is out of range.
        """
        try:
            result = PhidgetLibrary.getDll(
            ).CPhidgetPHSensor_setPHChangeTrigger(self.handle, c_double(value))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 9
0
    def reset(self, index):
        """Resets the TotalCount and TotalTime counters to 0 for the specified channel.

        For best performance, this should be called when the channel is disabled.

        Parameters:
            index<int>: index of the frequency input channel

        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.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetFrequencyCounter_reset(
                self.handle, c_int(index))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 10
0
 def __init__(self):
     """The Constructor Method for the Manager 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.__attach = None
     self.__detach = None
     self.__error = None
     self.__serverConnect = None
     self.__serverDisconnect = None
     
     self.__onAttach = None
     self.__onDetach = None
     self.__onError = None
     self.__onServerConnect = None
     self.__onServerDisconnect = None
     
     if sys.platform == 'win32':
         self.__ATTACHHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p)
         self.__DETACHHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p)
         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.__ATTACHHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p)
         self.__DETACHHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p)
         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().CPhidgetManager_create(byref(self.handle))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Ejemplo n.º 11
0
    def setGain(self, index, gain):
        """Sets the gain for a selected bridge.
        Supported gains are 8, 16, 32, 64, 128, or no gain.
        Note that increasing the gains will reduce the measurable voltage difference by the gain factor, with +-1000mV/V being the maximum, with no gain.

        Parameters:
            index<int>: index of the Bridge input
            gain<int/BridgeGain>: desired gain to set the input to

        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached, if the index is out of range, or if the gain specified is out of range.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetBridge_setGain(
                self.handle, c_int(index), c_int(gain))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
 def setDataRate(self, index, value):
     """
     Sets the maximum rate at which events will be fired, in ms.
     
     This value needs to be a multiple of 8, between DataRateMin and DataRateMax.  I.E. 1,2,4,8,16,24,32,....
     
     Parameters:
         index<int>: Index of the sensor.
         value<int>: The desired Data Rate Value.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, if the index is out of range, or the supplied data rate value is out of range.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetInterfaceKit_setDataRate(self.handle, c_int(index), c_int(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Ejemplo n.º 14
0
 def getTemperatureInputCount(self):
     """Returns the number of thermocouples.
     
     Returns:
         Number of thermocouple temperature inputs <int>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     inputCount = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetTemperatureSensor_getTemperatureInputCount(self.handle, byref(inputCount))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return inputCount.value
Ejemplo n.º 15
0
    def getScreenSize(self):
        """Gets the screen size.

        Returns:
            The screen size <int/TextLCD_ScreenSize>.

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

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return screenSize.value
Ejemplo n.º 16
0
    def getBackEMFSensingState(self, index):
        """

        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.
        """
        state = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidgetMotorControl_getBackEMFSensingState(self.handle, c_int(index), byref(state))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            if state.value == 1:
                return True
            else:
                return False
Ejemplo n.º 17
0
 def setVelocity(self, index, value):
     """Sets a motor's velocity.
     
     The valid range is from -100 to 100, with 0 being stopped. -100 and 100 both corespond to full voltage,
     with the value in between corresponding to different widths of PWM.
     
     Parameters:
         index<int>: index of the motor.
         value<double>: requested velocity 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 velocity value are invalid.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetMotorControl_setVelocity(self.handle, c_int(index), c_double(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Ejemplo n.º 18
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.
        
        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)
Ejemplo n.º 19
0
    def setBrightness(self, value):
        """Sets the brightness of the display.
        
        For devices that support a range of backlight brightnesses.
        The valid range is 0-255.
        
        Parameters:
            value<int>: the desired brightness value.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetTextLCD_setBrightness(
                self.handle, c_int(value))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 20
0
 def setSensorChangeTrigger(self, index, value):
     """Sets the change trigger for an analog input.
     
     This is the amount that an inputs must change between successive SensorChangeEvents.
     This is based on the 0-1000 range provided by getSensorValue. This value is by default set to 10 for most Interface Kits with analog inputs.
     
     Parameters:
         index<int>: Index of the sensor.
         value<int>: The Trigger Value.
     
     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.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetInterfaceKit_setSensorChangeTrigger(self.handle, c_int(index), c_int(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Ejemplo n.º 21
0
 def getPotentialMin(self):
     """Returns the minimum potential that will be returned by the ph sensor input.
     
     Returns:
         The Minimum potential in millivolts <double>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     potentialMin = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetPHSensor_getPotentialMin(self.handle, byref(potentialMin))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return potentialMin.value
Ejemplo n.º 22
0
    def setBrightness(self, index, value):
        """Sets the brightness of an LED.
        
        Valid values are 0-100, with 0 being off and 100 being the brightest.
        
        Parameters:
            index<int>: index of the Discrete LED.
            value<double>: brightness value of the Discrete LED.
        
        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 brightness value are out of range.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetLED_setBrightness(
                self.handle, c_int(index), c_double(value))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 23
0
 def getPHMax(self):
     """Returns the maximum ph that will be returned by the ph sensor input.
     
     Returns:
         The Maximum pH readable <double>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     phMax = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetPHSensor_getPHMax(self.handle, byref(phMax))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return phMax.value
Ejemplo n.º 24
0
    def setPositionMin(self, index, value):
        """Sets the minimum position of a servo motor.
        
        Parameters:
            index<int>: index of the motor.
            position<double>: desired minimum position limit 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 minimum position limit is out of range, or if the motor is not engaged.
        """
        try:
            result = PhidgetLibrary.getDll(
            ).CPhidgetAdvancedServo_setPositionMin(self.handle, c_int(index),
                                                   c_double(value))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Ejemplo n.º 25
0
 def getAngularRateMin(self, index):
     """Gets the minimum supported angular rate for this gyro axis.
     
     Returns:
         The Minimum supported Angular Rate for this gyro axis. <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_getAngularRateMin(self.handle, c_int(index), byref(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return value.value
Ejemplo n.º 26
0
 def setAcceleration(self, index, value):
     """Sets a motor's acceleration.
     
     The valid range is between getAccelerationMin and getAccelerationMax.
     This controls how fast the motor changes speed.
     
     Parameters:
         index<int>: index of the motor.
         value<double>: requested acceleration for that 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 acceleration value are invalid.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetMotorControl_setAcceleration(self.handle, c_int(index), c_double(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Ejemplo n.º 27
0
 def getMagneticFieldMin(self, index):
     """Gets the minimum magnetic field strength measurable by this compass axis.
     
     Returns:
         The Minimum measurable Magnetic Field strength for this compass axis. <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_getMagneticFieldMin(self.handle, c_int(index), byref(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return value.value
Ejemplo n.º 28
0
    def getScreenCount(self):
        """Gets the number of Display supported by this TextLCD

        Returns:
            The number of supported screens <int>.

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

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return screenCount.value
Ejemplo n.º 29
0
 def setTemperatureChangeTrigger(self, index, value):
     """Sets the change trigger for an input.
     
     This is the amount by which the sensed temperature must change between TemperatureChangeEvents.
     By default this is set to 0.5.
     
     Parameters:
         index<int>: index of the thermocouple input.
         value<double>: temperature change trigger value.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached, or index or value are out of range.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetTemperatureSensor_setTemperatureChangeTrigger(self.handle, c_int(index), c_double(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Ejemplo n.º 30
0
 def getRowCount(self):
     """Returns the number of rows available on the display.
     
     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.
     """
     rowCount = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetTextLCD_getRowCount(self.handle, byref(rowCount))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return rowCount.value
Ejemplo n.º 31
0
 def getAmbientTemperatureMin(self):
     """Returns the minimum temperature that will be returned by the ambient sensor.
     
     Returns:
         Minimum Ambient Temperature in derees celcius <double>.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this Phidget is not opened and attached.
     """
     ambientMin = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetTemperatureSensor_getAmbientTemperatureMin(self.handle, byref(ambientMin))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return ambientMin.value