com.phidgets
Class EncoderPhidget

java.lang.Object
  extended bycom.phidgets.Phidget
      extended bycom.phidgets.EncoderPhidget

public final class EncoderPhidget
extends Phidget

This class represents a Phidget Encoder. All methods to read encoder data from an encoder are implemented in this class.

Phidget Encoder boards generally support 1 or more encoders with 0 or more digital inputs. Both high speed optical and low speed mechanical encoders are supported with this API.

Author:
Phidgets Inc.

Field Summary
 
Fields inherited from class com.phidgets.Phidget
PHIDCLASS_ACCELEROMETER, PHIDCLASS_ADVANCEDSERVO, PHIDCLASS_ANALOG, PHIDCLASS_BRIDGE, PHIDCLASS_ENCODER, PHIDCLASS_FREQUENCYCOUNTER, PHIDCLASS_GPS, PHIDCLASS_INTERFACEKIT, PHIDCLASS_LED, PHIDCLASS_MOTORCONTROL, PHIDCLASS_NOTHING, PHIDCLASS_PHSENSOR, PHIDCLASS_RFID, PHIDCLASS_SERVO, PHIDCLASS_STEPPER, PHIDCLASS_TEMPERATURESENSOR, PHIDCLASS_TEXTLCD, PHIDCLASS_TEXTLED, PHIDCLASS_WEIGHTSENSOR, PHIDGET_LOG_CRITICAL, PHIDGET_LOG_DEBUG, PHIDGET_LOG_ERROR, PHIDGET_LOG_INFO, PHIDGET_LOG_VERBOSE, PHIDGET_LOG_WARNING, PHIDID_ACCELEROMETER_2AXIS, PHIDID_ACCELEROMETER_3AXIS, PHIDID_ADVANCEDSERVO_1MOTOR, PHIDID_ADVANCEDSERVO_8MOTOR, PHIDID_ANALOG_4OUTPUT, PHIDID_BIPOLAR_STEPPER_1MOTOR, PHIDID_BRIDGE_4INPUT, PHIDID_ENCODER_1ENCODER_1INPUT, PHIDID_ENCODER_HS_1ENCODER, PHIDID_ENCODER_HS_4ENCODER_4INPUT, PHIDID_FREQUENCYCOUNTER_2INPUT, PHIDID_GPS, PHIDID_INTERFACEKIT_0_0_4, PHIDID_INTERFACEKIT_0_0_8, PHIDID_INTERFACEKIT_0_16_16, PHIDID_INTERFACEKIT_0_8_8_w_LCD, PHIDID_INTERFACEKIT_2_2_2, PHIDID_INTERFACEKIT_4_8_8, PHIDID_INTERFACEKIT_8_8_8, PHIDID_INTERFACEKIT_8_8_8_w_LCD, PHIDID_IR, PHIDID_LED_64, PHIDID_LED_64_ADV, PHIDID_LINEAR_TOUCH, PHIDID_MOTORCONTROL_1MOTOR, PHIDID_MOTORCONTROL_HC_2MOTOR, PHIDID_MOTORCONTROL_LV_2MOTOR_4INPUT, PHIDID_NOTHING, PHIDID_PHSENSOR, PHIDID_RFID, PHIDID_RFID_2OUTPUT, PHIDID_RFID_2OUTPUT_READ_WRITE, PHIDID_ROTARY_TOUCH, PHIDID_SERVO_1MOTOR, PHIDID_SERVO_1MOTOR_OLD, PHIDID_SERVO_4MOTOR, PHIDID_SERVO_4MOTOR_OLD, PHIDID_SPATIAL_ACCEL_3AXIS, PHIDID_SPATIAL_ACCEL_GYRO_COMPASS, PHIDID_TEMPERATURESENSOR, PHIDID_TEMPERATURESENSOR_4, PHIDID_TEMPERATURESENSOR_IR, PHIDID_TEXTLCD_2x20, PHIDID_TEXTLCD_2x20_w_0_8_8, PHIDID_TEXTLCD_2x20_w_8_8_8, PHIDID_TEXTLCD_ADAPTER, PHIDID_TEXTLED_1x8, PHIDID_TEXTLED_4x8, PHIDID_UNIPOLAR_STEPPER_4MOTOR, PHIDID_WEIGHTSENSOR
 
Constructor Summary
EncoderPhidget()
           
 
Method Summary
 void addEncoderPositionChangeListener(EncoderPositionChangeListener l)
          Adds a position change listener.
 void addInputChangeListener(InputChangeListener l)
          Adds an input change listener.
 boolean getEnabled(int index)
          Returns the enabled state of an encoder.
 int getEncoderCount()
          Returns number of encoders.
 int getEncoderPosition(int index)
          Deprecated. Replaced by getPosition(int)
 int getIndexPosition(int index)
          Returns the last index position of an encoder.
 int getInputCount()
          Returns number of digital inputs.
 boolean getInputState(int index)
          Returns the state of a digital input.
 int getPosition(int index)
          Returns the position of an encoder.
 void removeEncoderPositionChangeListener(EncoderPositionChangeListener l)
           
 void removeInputChangeListener(InputChangeListener l)
           
 void setEnabled(int index, boolean state)
          Sets the enabled state of an encoder.
 void setEncoderPosition(int index, int position)
          Deprecated. Replaced by setPosition(int, int)
 void setPosition(int index, int position)
          Sets the position of a specific encoder.
 
Methods inherited from class com.phidgets.Phidget
addAttachListener, addDetachListener, addErrorListener, addServerConnectListener, addServerDisconnectListener, close, disableLogging, enableLogging, equals, getDeviceClass, getDeviceID, getDeviceLabel, getDeviceName, getDeviceType, getDeviceVersion, getLibraryVersion, getSerialNumber, getServerAddress, getServerID, getServerPort, isAttached, isAttachedToServer, log, open, open, open, open, open, openAny, openAny, openAny, openAny, openAny, openLabel, openLabel, openLabel, openLabel, openLabel, removeAttachListener, removeDetachListener, removeErrorListener, removeServerConnectListener, removeServerDisconnectListener, setDeviceLabel, toString, waitForAttachment, waitForAttachment
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EncoderPhidget

public EncoderPhidget()
               throws PhidgetException
Method Detail

getEncoderCount

public int getEncoderCount()
                    throws PhidgetException
Returns number of encoders. All current encoder boards support one encoder.

Returns:
number of encoders
Throws:
PhidgetException - If this Phidget is not opened and attached. See open for information on determining if a device is attached.

getInputCount

public int getInputCount()
                  throws PhidgetException
Returns number of digital inputs. On the mechanical encoder this refers to the pushbutton. The high speed encoder does not have any digital inputs.

Returns:
number of inputs
Throws:
PhidgetException - If this Phidget is not opened and attached. See open for information on determining if a device is attached.

getPosition

public int getPosition(int index)
                throws PhidgetException
Returns the position of an encoder. This is an absolute position as calcutated since the encoder was plugged in. This value can be reset to anything using setEncoderPosition.

Parameters:
index - index of the encoder
Returns:
position of the encoder
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

getIndexPosition

public int getIndexPosition(int index)
                     throws PhidgetException
Returns the last index position of an encoder. This is the position of the last index pulse. Not all encoders support index.

Parameters:
index - index of the encoder
Returns:
last index position of the encoder
Throws:
PhidgetException - If this Phidget is not opened and attached, if the index is out of range, of if index is not supported. See open for information on determining if a device is attached.

getEncoderPosition

public int getEncoderPosition(int index)
                       throws PhidgetException
Deprecated. Replaced by getPosition(int)

Throws:
PhidgetException

setPosition

public void setPosition(int index,
                        int position)
                 throws PhidgetException
Sets the position of a specific encoder. This resets the internal position count for an encoder. This call in no way actually sends information to the device, as an absolute position is maintained only in the library. After this call, position changes from the encoder will use the new value to calculate absolute position as reported by getEncoderPosition(int).

Parameters:
index - index of the encoder
position - new position for this encoder.
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

setEncoderPosition

public void setEncoderPosition(int index,
                               int position)
                        throws PhidgetException
Deprecated. Replaced by setPosition(int, int)

Throws:
PhidgetException

getInputState

public boolean getInputState(int index)
                      throws PhidgetException
Returns the state of a digital input. On the mechanical encoder this refers to the pushbutton. The high speed encoder does not have any digital inputs. A value of true means that the input is active(the button is pushed).

Parameters:
index - index of the input
Returns:
state of the input
Throws:
PhidgetException - If this Phidget is not opened and attached, or if the index is out of range. See open for information on determining if a device is attached.

getEnabled

public boolean getEnabled(int index)
                   throws PhidgetException
Returns the enabled state of an encoder. True indicated activated, False deactivated, which is the default.

Parameters:
index - index of the encoder
Returns:
state of the encoder
Throws:
PhidgetException - If this Phidget is not opened and attached, the index is out of range, or enable is not supported. See open for information on determining if a device is attached.

setEnabled

public void setEnabled(int index,
                       boolean state)
                throws PhidgetException
Sets the enabled state of an encoder. True indicated activated, False deactivated, which is the default.

Parameters:
index - index of the encoder
state - desired state
Throws:
PhidgetException - If this Phidget is not opened and attached, the index is out of range, or enable is not supported. See open for information on determining if a device is attached.

addEncoderPositionChangeListener

public final void addEncoderPositionChangeListener(EncoderPositionChangeListener l)
Adds a position change listener. The position change handler is a method that will be called when the position of an encoder changes. The position change event provides data about how many ticks have occured, and how much time has passed since the last position change event, but does not contain an absolute position. This can be obtained from getEncoderPosition(int).

There is no limit on the number of position change handlers that can be registered for a particular Phidget.

Parameters:
l - An implemetation of the EncoderPositionChangeListener interface

removeEncoderPositionChangeListener

public final void removeEncoderPositionChangeListener(EncoderPositionChangeListener l)

addInputChangeListener

public final void addInputChangeListener(InputChangeListener l)
Adds an input change listener. The input change handler is a method that will be called when an input on this Encoder board has changed.

There is no limit on the number of input change handlers that can be registered for a particular Phidget.

Parameters:
l - An implemetation of the InputChangeListener interface

removeInputChangeListener

public final void removeInputChangeListener(InputChangeListener l)