Example #1
0
 def getServoType(self, index):
     """Returns the servo type of the specified motor.
     
     Parameters:
         index<int>: index of a servo motor.
     
     Returns:
         Servo type for the motor<int>.
     
     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.
     """
     servoType = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetServo_getServoType(self.handle, c_int(index), byref(servoType))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return servoType.value
    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)
    def setDataRate(self, dataRate):
        """Sets the maximum rate at which events will be fired, in ms.

        Data rate applies to all 4 bridges simultaneously. Setting a slower data rate will reduce noise at the cost of sample time.
        Also note that each bridge is being sampled only 1/4 of the time - this is probably ok for very stable signals, but for changing signals,
        it's probably best to set a higher sampling rate and do averaging in software.

        Data rate must be a multiple of 8ms. Trying to set something between multiples of 8 will cause an EPHIDGET_INVALIDARG exception to be thrown.

        Parameters:
            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, or the supplied data rate value is out of range.
        """
        try:
            result = PhidgetLibrary.getDll().CPhidgetBridge_setDataRate(
                self.handle, c_int(dataRate))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
    def getDataRateMax(self):
        """Returns the maximum supported data rate value that can be set, in ms.

        This is currently 8.

        Returns:
            The maximum supported data rate <int>

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

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return dataRateMax.value
Example #5
0
    def getCompassAxisCount(self):
        """Returns the number of compass axes.
        
        Currently all compass provide two or three axes of Magnetic field - x, y, and z.
        
        Returns:
            The number of Available Axes <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this phidget is not opened or attached.
        """
        axisCount = c_int()
        try:
            result = PhidgetLibrary.getDll(
            ).CPhidgetSpatial_getCompassAxisCount(self.handle,
                                                  byref(axisCount))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return axisCount.value
    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 #7
0
 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)
    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
    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 #10
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
    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 __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)
 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 #14
0
 def getInputState(self, index):
     """Returns the state of a digital input.
     
     True means that the input is activated, and False indicated the default state.
     
     Parameters:
         index<int>: The index of the input.
     
     Returns:
         The state of the input <boolean>.
     
     Exceptions:
         PhidgetException: If this Phidget is not opened and attached, or if the index is invalid.
     """
     inputState = c_int()
     result = self.dll.CPhidgetStepper_getInputState(
         self.handle, c_int(index), byref(inputState))
     if result > 0:
         raise PhidgetException(result)
     else:
         if inputState.value == 1:
             return True
         else:
             return False
Example #15
0
 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
    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 #17
0
 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
    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
    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 #20
0
    def getDataRate(self):
        """Gets the event data rate in ms.
        
        Data rate needs to be between DataRateMin and DataRateMax.
        
        Returns:
            The current event data rate, in ms. <int>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened and attached.
        """
        dataRate = c_int()

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return dataRate.value
Example #21
0
 def getSensorValue(self, index):
     """Returns the value of a analog input.
     
     The analog inputs are where analog sensors are attached on the InterfaceKit 8/8/8.
     On the Linear and Circular touch sensor Phidgets, analog input 0 represents position on the slider.
     
     The valid range is 0-1000. In the case of a sensor, this value can be converted to an actual sensor
     value using the formulas provided here: http://www.phidgets.com/documentation/Sensors.pdf
     
     Parameters:
         index<int>: Index of the sensor.
     
     Returns:
         The Sensor value <int>
     
     Exceptions:
         PhidgetException: If this Phidget is not opened and attached, or if the index is out of range.
     """
     sensorValue = c_int()
     result = self.dll.CPhidgetInterfaceKit_getSensorValue(self.handle, c_int(index), byref(sensorValue))
     if result > 0:
         raise PhidgetException(result)
     else:
         return sensorValue.value
Example #22
0
 def setTargetPosition(self, index, value):
     """Sets a motor's target position.
     
     Use this is set the target position for the stepper. If the stepper is engaged (getEngaged) it will start moving towards this target position.
     The valid range is between getPositionMin and getPositionMax.
     
     This value is in (micro)steps. The step unit will depend on the Stepper Controller.
     For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.
     
     Parameters:
         index<int>: The index of the motor.
         value<longlong>: The 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 are invalid.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_setTargetPosition(self.handle, c_int(index), c_longlong(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #23
0
 def getInputState(self, index):
     """Returns the state of a digital input.
     
     Digital inputs read True where they are activated and False when they are in their default state.
     Be sure to check getInputCount first if you are unsure as to the number of inputs, so as not to set an Index that is out of range.
     
     Parameters:
         index<int>: Index of the input.
     
     Returns:
         State of the input <boolean>.
     
     Exceptions:
         PhidgetException: If this Phidget is not opened and attached, or if the index is out of range.
     """
     inputState = c_int()
     result = self.dll.CPhidgetInterfaceKit_getInputState(self.handle, c_int(index), byref(inputState))
     if result > 0:
         raise PhidgetException(result)
     else:
         if inputState.value == 1:
             return True
         else:
             return False
    def getInputCount(self):
        """Returns the number of Bridge inputs.

        Current version of the Phidget Bridge has 4 Bridge inputs, future versions could have more or less.

        Returns:
            The number of available Bridge inputs <int>.

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

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return inputCount.value
Example #25
0
 def getVelocity(self, index):
     """Returns a motor's current velocity.
     
     The valid range is between getVelocityMin and getVelocityMax, with 0 being stopped.
     This value is in (micro)steps per second. The step unit will depend on the Stepper Controller.
     For example, the Bipolar Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second.
     
     Parameters:
         index<int>: The index of the motor.
     
     Returns:
         The current velocity of the motor <double>.
     
     Exceptions:
         PhidgetException: If this Phidget is not opened and attached, or if the index is invalid, or if the velocity in unknown.
     """
     velocity = c_double()
     result = self.dll.CPhidgetStepper_getVelocity(self.handle,
                                                   c_int(index),
                                                   byref(velocity))
     if result > 0:
         raise PhidgetException(result)
     else:
         return velocity.value
Example #26
0
 def getEngaged(self, index):
     """Returns the engaged state of a servo
     
     Returns:
         Motor Engaged 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, or if the index is out of range.
     """
     engagedStatus = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetServo_getEngaged(self.handle, c_int(index), byref(engagedStatus))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if engagedStatus.value == 1:
             return True
         else:
             return False
Example #27
0
 def getCurrent(self, index):
     """Returns a motor's current usage.
     
     The valid range is between getCurrentMin and getCurrentMax.
     This value is in Amps.
     
     Note that this is not supported on all stepper controllers.
     
     Parameters:
         index<int>: Index of the motor.
     
     Returns:
         The Current usage for the motor <double>.
     
     Exceptions:
         PhidgetException: If this Phidget is not opened and attached, if the index is invalid, if the value is unknown, or if this is not supported.
     """
     current = c_double()
     result = self.dll.CPhidgetStepper_getCurrent(self.handle, c_int(index),
                                                  byref(current))
     if result > 0:
         raise PhidgetException(result)
     else:
         return current.value
    def getTotalCount(self, index):
        """Gets the total number of pulses detected on the specified channel since the Phidget was opened, or since the last reset.

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

        Returns:
            The current number of pulses detected <long long>.

        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.
        """
        count = c_longlong()

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return count.value
    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