// phidgetIK -phidget interface kit object // phidgetEncoder // // Constructors // // phidgetEncoder() - open with first available phidget Encoder // // phidgetEncoder( int serial ) - open phidget with given serial number // // // Methods // // void close() - close the phidget Encoder // // boolean isAttached() - returns true if Encoder is attached // // void waitForAttachment( int timeout ) - wait for Encoder to attach with timeout in miliseconds // // void waitForAttachment( ) - wait indefinitely for Encoder to attach // // int serial() - return serial number of Encoder if attached, 0 otherwise // // int version() - return Encoder revision no if attached, 0 otherwise // // int getEncoderCount() - returns encoder count // // int getInputCount() - returns number of digital inputs // // int getPosition( int index ) - returns position of indexed encoder // // void setPosition( int index, int position ) - set position of indexed encoder // // boolean getInputState( int index ) - returns number of digital inputs // import com.phidgets.*; import com.phidgets.event.*; class phidgetEncoder { EncoderPhidget encoder; // constructors // open first available interface kit phidgetEncoder() { try { encoder = new EncoderPhidget(); encoder.openAny(); } catch(Exception e) {} } // open interface kit for given serial number phidgetEncoder( int serial ) { try { encoder = new EncoderPhidget(); encoder.open( serial ); } catch(Exception e) {} } // close the ik void close() { try { encoder.close(); } catch(Exception e) {} } // check if interface kit is attached boolean isAttached() { boolean result; try { result = encoder.isAttached(); } catch(Exception e) { result = false; } return result; } // wait for phidget to attach - with time out void waitForAttachment( int timeout ) { try { encoder.waitForAttachment(timeout); } catch( Exception e) { } } // sait for phidget to attach - indefinitely void waitForAttachment( ) { try { encoder.waitForAttachment(); } catch( Exception e) { } } // get serial number of attached phidget, return -1 if not attached int serial() { int s; try { s = encoder.getSerialNumber(); } catch( Exception e ) { s = -1; } return s; } // get device version int version() { int v; try { v = encoder.getDeviceVersion(); } catch( Exception e ) { v = -1; } return v; } // returns encoder count int getEncoderCount() { int n; try { n = encoder.getEncoderCount(); } catch( Exception e ) { n = 0; } return n; } // returns number of digital inputs int getInputCount() { int n; try { n = encoder.getInputCount(); } catch( Exception e ) { n = 0; } return n; } // returns position of indexed encoder int getPosition( int index ) { int pos; try { pos = encoder.getPosition( index ); } catch( Exception e ) { pos = 0; } return pos; } // set position of indexed encoder void setPosition( int index, int position ) { try { encoder.setPosition( index, position ); } catch( Exception e ) { } } // returns number of digital inputs boolean getInputState( int index ) { boolean state; try { state = encoder.getInputState( index ); } catch( Exception e ) { state = false; } return state; } }