Example #1
0
 def __init__(self):
     """The Constructor Method for the Stepper 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.__positionChange = None
     self.__currentChange = None
     
     self.__onInputChange = None
     self.__onVelocityChange = None
     self.__onPositionChange = None
     self.__onCurrentChange = None
     
     try:
         PhidgetLibrary.getDll().CPhidgetStepper_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.__POSITIONCHANGEHANDLER = WINFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_longlong)
         self.__CURRENTCHANGEHANDLER = 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.__POSITIONCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_longlong)
         self.__CURRENTCHANGEHANDLER = CFUNCTYPE(c_int, c_void_p, c_void_p, c_int, c_double)
Example #2
0
    def enableLogging(level, file):
        """Turns on logging in the native C Library.
        
        This is mostly usefull for debugging purposes - when an issue needs to be resolved by Phidgets Inc.
        The output is mostly low-level library information, that won't be usefull for most users.
        
        Logging may be usefull for users trying to debug their own problems, as logs can be inserted by the user using log.
        The level can be one of:
        PhidgetLogLevel.PHIDGET_LOG_VERBOSE ,
        PhidgetLogLevel.PHIDGET_LOG_INFO ,
        PhidgetLogLevel.PHIDGET_LOG_DEBUG ,
        PhidgetLogLevel.PHIDGET_LOG_WARNING ,
        PhidgetLogLevel.PHIDGET_LOG_ERROR or
        PhidgetLogLevel.PHIDGET_LOG_CRITICAL 
        
        Parameters:
            level<int>: highest level of logging that will be output, the PhidgetLogLevel object has been provided for a readable way to set this.
            file<string>: path and name of file to output to.  specify NULL to output to the console.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException
        """
        try:
            result = PhidgetLibrary.getDll().CPhidget_enableLogging(c_int(level), c_char_p(file))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #3
0
    def getServerAddress(self):
        """Returns the Address of a Phidget Webservice.
        
        Returns the Address of a Phidget Webservice when this Phidget was opened as remote.
        This may be an IP Address or a hostname.
        
        Returns:
            The Address of the Webservice <string>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: if this Phidget was open opened as a remote Phidget.
        """
        serverAddr = c_char_p()
        port = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidget_getServerAddress(self.handle, byref(serverAddr), byref(port))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
        else:
            return prepOutput(serverAddr)
Example #4
0
    def waitForAttach(self, timeout):
        """Waits for this Phidget to become available.
        
        This method can be called after open has been called to wait for thid Phidget to become available.
        This is usefull because open is asynchronous (and thus returns immediately), and most methods will throw a PhidgetException is they are called before a device is actually ready.
        This method is synonymous with polling the isAttached method until it returns True, or using the Attach event.
        
        This method blocks for up to the timeout, at which point it will throw a PhidgetException. Otherwise, it returns when the phidget is attached and initialized.
        
        A timeout of 0 is infinite.
        
        Parameters:
            timeout<long>: Timeout in milliseconds
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened.
        """

        try:
            result = PhidgetLibrary.getDll().CPhidget_waitForAttachment(self.handle, c_long(timeout))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #5
0
    def setOnDetachHandler(self, detachHandler):
        """Sets the Detach Event Handler.
        
        The detach handler is a method that will be called when this Phidget is phisically detached from the system, and is no longer available.
        This is particularly usefull for applications when a phisical detach would be expected.
        
        Remember that many of the methods, if called on an unattached device, will throw a PhidgetException.
        This Exception can be checked to see if it was caused by a device being unattached, but a better method would be to regiter the detach handler,
        which could notify the main program logic that the device is no longer available, disable GUI controls, etc.
        
        Parameters:
            detachHandler: hook to the detachHandler callback function
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened.
        """
        if detachHandler == None:
            self.__detach = None
            self.__onDetach = None
        else:
            self.__detach = detachHandler
            self.__onDetach = self.__DETACHHANDLER(self.__nativeDetachEvent)

        try:
            result = PhidgetLibrary.getDll().CPhidget_set_OnDetach_Handler(self.handle, self.__onDetach, None)
        except RuntimeError:
            self.__detach = None
            self.__onDetach = None
            raise

        if result > 0:
            raise PhidgetException(result)
Example #6
0
    def isAttached(self):
        """Returns the attached status of this Phidget.
        
        This method returns True or False, depending on whether the Phidget is phisically plugged into the computer, initialized, and ready to use - or not.
        If a Phidget is not attached, many functions calls will fail with a PhidgetException, so either checking this function, or using the Attach and Detach events, is recommended, if a device is likely to be attached or detached during use.
        
        Returns:
            Attached Status of the Phidget <boolean>
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened.
        """
        status = c_int()

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

        if result > 0:
            raise PhidgetException(result)
        else:
            if status.value == 1:
                return True
            else:
                return False
Example #7
0
    def openRemoteIP(self, IPAddress, port, serial=-1, password=""):
        """Open this Phidget remotely using an IP Address, securely providing a password,and whether or not to connect to a specific serial number.
        
        Providing a password will open the connection securely depending on if a password is set on the host machine's webservice.
        
        If no serial number is provided, the first available Phidget will be opened. If there are two Phidgets of the same type attached to the system,
        you should specify a serial number, as there is no guarantee which Phidget will be selected by the call to open().
        
        Parameters:
            IPAddress<string>: IP Address or hostname of the Phidget Webservice
            port<int>: Port of the Phidget Webservice
            serial<int>: The serial number of the device
            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
        """
        if not isinstance(serial, int):
            if password == "":
                password = serial
                serial = -1
            else:
                raise TypeError("inappropriate arguement type: serial %s" % (type(serial)))

        try:
            result = PhidgetLibrary.getDll().CPhidget_openRemoteIP(
                self.handle, c_int(serial), c_char_p(IPAddress), c_int(port), c_char_p(password)
            )
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #8
0
    def getAccelerationMax(self, index):
        """Returns the maximum acceleration that a motor will accept, or return.
        
        This value uses the same units as setAcceleration/getAcceleration.
        
        Parameters:
            index<int>: Index of the motor.
        
        Returns:
            The maximum allowable 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 the index is invalid.
        """
        accelMax = c_double()

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return accelMax.value
Example #9
0
 def setOnPositionChangeHandler(self, positionChangeHandler):
     """Sets the PositionChange event handler
     
     The position change handler is a method that will be called when the stepper position has changed.
     
     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().CPhidgetStepper_set_OnPositionChange_Handler(self.handle, self.__onPositionChange, None)
     except RuntimeError:
         self.__positionChange = None
         self.__onPositionChange = None
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #10
0
 def getPositionMin(self, index):
     """Returns the minimum position that a stepper motor will accept, or return.
     
     This value uses the same usits as setTargetPosition/getTargetPosition and setCurrentPosition/getCurrentPosition.
     
     Parameters:
         index<int>: Index of the motor.
     
     Returns:
         The minimum allowable position <longlong>.
     
     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.
     """
     positionMin = c_longlong()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getPositionMin(self.handle, c_int(index), byref(positionMin))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return positionMin.value
Example #11
0
 def setCurrentPosition(self, index, value):
     """Sets a motor's current position.
     
     Use this is (re)set the current physical position of the motor to a specific position value.
     This does not move the motor, and if the motor is moving, calling this will cause it to stop moving.
     Use setTargetPosition to move the motor to a 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>: Index of the motor.
         value<longlong>: The current position of 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_setCurrentPosition(self.handle, c_int(index), c_longlong(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #12
0
 def getCurrentPosition(self, index):
     """Returns a motor's current position.
     
     This is the actual step position that the motor is at right now.
     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>: Index of the motor.
     
     Returns:
         The current position of the motor <longlong>.
     
     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.
     """
     currentPosition = c_longlong()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getCurrentPosition(self.handle, c_int(index), byref(currentPosition))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return currentPosition.value
Example #13
0
 def setOnVelocityChangeHandler(self, velocityChangeHandler):
     """Sets the VelocityChange event handler.
     
     The velocity change handler is a method that will be called when the stepper velocity has changed.
     
     Parameters:
         velocityChangeHandler: hook to the velocityChangeHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException
     """
     if velocityChangeHandler == None:
         self.__velocityChange = None
         self.__onVelocityChange = None
     else:
         self.__velocityChange = velocityChangeHandler
         self.__onVelocityChange = self.__VELOCITYCHANGEHANDLER(self.__nativeVelocityChangeEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_set_OnVelocityChange_Handler(self.handle, self.__onVelocityChange, None)
     except RuntimeError:
         self.__velocityChange = None
         self.__onVelocityChange = None
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #14
0
 def getVelocityMin(self, index):
     """Returns the minimum velocity that a stepper motor will accept, or return.
     
     This value uses the same units as setVelocityLimit/getVelocityLimit and getVelocity.
     
     Parameters:
         index<int>: The index of the motor.
     
     Returns:
         The minimum allowable velocity 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.
     """
     velocityMin = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getVelocityMin(self.handle, c_int(index), byref(velocityMin))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return velocityMin.value
Example #15
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:
         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, or if the velocity in unknown.
     """
     velocity = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getVelocity(self.handle, c_int(index), byref(velocity))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return velocity.value
Example #16
0
 def setCurrentLimit(self, index, value):
     """Sets a motor's current usage limit.
     
     The valid range is between getCurrentMin and getCurrentMax.
     This sets the maximum current that a motor will be allowed to draw.
     
     Use this with the Bipolar stepper controller to get smooth micro stepping - see the product manual for more details. This value is in Amps.
     
     Note that this is not supported on all stepper controllers.
     
     Parameters:
         index<int>: Index of the motor.
         value<double>: The desired Current 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, if the index or value are invalid, or if this is not supported.
     """
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_setCurrentLimit(self.handle, c_int(index), c_double(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #17
0
    def getAcceleration(self, index):
        """Returns a motor's acceleration.
        
        The valid range is between getAccelerationMin and getAccelerationMax, and refers to how fast the Stepper Controller will change the speed of a motor.
        This value is in (micro)steps per second squared. 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 squared.
        
        Parameters:
            index<int>: INdex of a 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, or if the acceleration is unknown.
        """
        accel = c_double()

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return accel.value
Example #18
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:
         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 invalid, if the value is unknown, or if this is not supported.
     """
     current = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getCurrent(self.handle, c_int(index), byref(current))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return current.value
Example #19
0
    def openPhidget(self, serial=-1):
        """Open a Phidget with or without a serial number.
        
        Open is pervasive. What this means is that you can call open on a device before it is plugged in, and keep the device opened across device dis- and re-connections.
        
        Open is Asynchronous.  What this means is that open will return immediately -- before the device being opened is actually available,
        so you need to use either the attach event or the waitForAttachment method to determine if a device is available before using it.
        
        If no arguement is provided, the first available Phidget will be opened. If there are two Phidgets of the same type attached to the system,
        you should specify a serial number, as there is no guarantee which Phidget will be selected by the call to open().
        
        The serial number is a unique number assigned to each Phidget during production and can be used to uniquely identify specific phidgets.
        
        Parameters:
            serial<int>: The serial number of the device
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException
        """
        try:
            result = PhidgetLibrary.getDll().CPhidget_open(self.handle, c_int(serial))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #20
0
 def getCurrentMin(self, index):
     """Returns the minimum current that a stepper motor will accept, or return.
     
     This value is in Amps.
     
     Parameters:
         index<int>: Index of the motor.
     
     Returns:
         The Minimum allowable Current usage for 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, if the index is invalid, or if this is not supported.
     """
     currentMin = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getCurrentMin(self.handle, c_int(index), byref(currentMin))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return currentMin.value
Example #21
0
    def getDeviceName(self):
        """Return the name of this Phidget.
        
        This is a string that describes the device. For example, a PhidgetInterfaceKit 
        could be described as "Phidget InterfaceKit 8/8/8", or "Phidget InterfaceKit 0/0/4", among others, depending on the specific device.
        
        This lets you determine the specific type of a Phidget, within the broader classes of Phidgets, such as PhidgetInterfaceKit, or PhidgetServo.
        
        Returns:
            The name of the device <string>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this phidget is not opened or attached.
        """
        ptr = c_char_p()

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

        if result > 0:
            raise PhidgetException(result)
        else:
            return prepOutput(ptr)
Example #22
0
 def setOnCurrentChangeHandler(self, currentChangeHandler):
     """Sets the CurrentChange event handler
     
     The current change handler is a method that will be called when the stepper current has changed.
     
     Note that not all stepper controllers support current sensing.
     
     Parameters:
         currentChangeHandler: hook to the currentChangeHandler callback function.
     
     Exceptions:
         RuntimeError - If current platform is not supported/phidget c dll cannot be found
         PhidgetException: If this is not supported.
     """
     if currentChangeHandler == None:
         self.__currentChange = None
         self.__onCurrentChange = None
     else:
         self.__currentChange = currentChangeHandler
         self.__onCurrentChange = self.__CURRENTCHANGEHANDLER(self.__nativeCurrentChangeEvent)
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_set_OnCurrentChange_Handler(self.handle, self.__onCurrentChange, None)
     except RuntimeError:
         self.__currentChange = None
         self.__onCurrentChange = None
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #23
0
    def setOnAttachHandler(self, attachHandler):
        """Sets the Attach Event Handler.
        
        The attach handler is a method that will be called when this Phidget is physically 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 this Phidget is not opened.
        """
        if attachHandler == None:
            self.__attach = None
            self.__onAttach = None
        else:
            self.__attach = attachHandler
            self.__onAttach = self.__ATTACHHANDLER(self.__nativeAttachEvent)

        try:
            result = PhidgetLibrary.getDll().CPhidget_set_OnAttach_Handler(self.handle, self.__onAttach, None)
        except RuntimeError:
            self.__attach = None
            self.__onAttach = None
            raise

        if result > 0:
            raise PhidgetException(result)
Example #24
0
 def getEngaged(self, index):
     """Returns the engaged state of a motor.
     
     Parameters:
         index<int>: Index of the motor.
     
     Returns:
         The engaged state for the 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 out of range.
     """
     engagedState = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getEngaged(self.handle, c_int(index), byref(engagedState))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if engagedState.value == 1:
             return True
         else:
             return False
Example #25
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 this Phidget is not opened.
        """
        if errorHandler == None:
            self.__error = None
            self.__onError = None
        else:
            self.__error = errorHandler
            self.__onError = self.__ERRORHANDLER(self.__nativeErrorEvent)

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

        if result > 0:
            raise PhidgetException(result)
Example #26
0
 def setEngaged(self, index, state):
     """Engage or disengage a motor.
     
     This engages or disengages the stepper motor. The motors are by default disengaged when the stepper controller is plugged in.
     When the stepper is disengaged, position, velocity, etc. can all be set, but the motor will not start moving until it is engaged.
     If position is read when a motor is disengaged, it will throw an exception.
     
     Parameters:
         index<int>: Index of the motor.
         state<boolean>: The desired engaged state 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.
     """
     if state == True:
         value = 1
     else:
         value = 0
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_setEngaged(self.handle, c_int(index), c_int(value))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
Example #27
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
        """
        if serverDisconnectHandler == None:
            self.__serverDisconnect = None
            self.__onServerDisconnect = None
        else:
            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)
Example #28
0
 def getStopped(self, index):
     """Returns the stopped state of a motor.
     
     Use this to determine if the motor is moving and/or up to date with the latest commands you have sent.
     If this is true, the motor is guaranteed to be stopped and to have processed every command issued.
     Generally, this would be polled after a target position is set to wait until that position is reached.
     
     Parameters:
         index<int>: Index of the motor.
     
     Returns:
         The stopped state of the 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 out of range.
     """
     stoppedState = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_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
Example #29
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:
            Phidget Network Attached Status <boolean>.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException: If this Phidget is not opened remotely.
        """
        serverStatus = c_int()

        try:
            result = PhidgetLibrary.getDll().CPhidget_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 #30
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:
         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.
     """
     inputState = c_int()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getInputState(self.handle, c_int(index), byref(inputState))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         if inputState.value == 1:
             return True
         else:
             return False
Example #31
0
    def log(level, id, log):
        """Adds a log entry into the phidget log.
        
        This log is enabled by calling enableLogging and this allows the entry of user logs in amongst the phidget library logs.
        
        The level can be one of:
        PhidgetLogLevel.PHIDGET_LOG_VERBOSE,
        PhidgetLogLevel.PHIDGET_LOG_INFO,
        PhidgetLogLevel.PHIDGET_LOG_DEBUG,
        PhidgetLogLevel.PHIDGET_LOG_WARNING,
        PhidgetLogLevel.PHIDGET_LOG_ERROR or
        PhidgetLogLevel.PHIDGET_LOG_CRITICAL
        
        Note: PhidgetLogLevel.PHIDGET_LOG_DEBUG should not be used, as these logs are only printed when using the debug library,
        which is not generally available.
        
        Parameters:
            level<int>: level to enter the log at.
            id<string>: an arbitrary identifier for this log.  This can be NULL. The C library uses this field for source filename and line number.
            log<string>: the message to log.
        
        Exceptions:
            RuntimeError - If current platform is not supported/phidget c dll cannot be found
            PhidgetException
        """
        try:
            result = PhidgetLibrary.getDll().CPhidget_log(c_int(level), c_char_p(id), c_char_p(log))
        except RuntimeError:
            raise

        if result > 0:
            raise PhidgetException(result)
Example #32
0
 def getAccelerationMax(self, index):
     """Returns the maximum acceleration that a motor will accept, or return.
     
     This value uses the same units as setAcceleration/getAcceleration.
     
     Parameters:
         index<int>: Index of the motor.
     
     Returns:
         The maximum allowable 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 the index is invalid.
     """
     accelMax = c_double()
     
     try:
         result = PhidgetLibrary.getDll().CPhidgetStepper_getAccelerationMax(self.handle, c_int(index), byref(accelMax))
     except RuntimeError:
         raise
     
     if result > 0:
         raise PhidgetException(result)
     else:
         return accelMax.value