lejos.nxt.comm
Class NXTCommand

java.lang.Object
  extended by lejos.nxt.comm.NXTCommand
All Implemented Interfaces:
NXTProtocol

public class NXTCommand
extends Object
implements NXTProtocol

Remote access to a NXT via Bluetooth using LCP.


Field Summary
 
Fields inherited from interface lejos.nxt.comm.NXTProtocol
ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, HIGH_SPEED_BUFFER, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, NO_OF_SENSOR_TYPES, NO_SENSOR, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TRANSITIONCNTMODE, WRITE
 
Constructor Summary
NXTCommand()
           
 
Method Summary
 void close()
          Call the close() command when your program ends, otherwise you will have to turn the NXT brick off/on before you run another program using iCommand.
 byte deleteUserFlash()
          Deletes user flash memory (not including system modules).
 int getBatteryLevel()
           
 DeviceInfo getDeviceInfo()
           
 FirmwareInfo getFirmwareVersion()
           
 InputValues getInputValues(int port)
           
 int getTachoCount(int port)
          Retrieves tacho count.
 void open(String name)
           
 byte playTone(int frequency, int duration)
          Plays a tone on NXT speaker.
 byte resetMotorPosition(int port, boolean relative)
          Resets the tachometer
 byte setInputMode(int port, int sensorType, int sensorMode)
          Tells the NXT what type of sensor you are using and the mode to operate in.
 byte setOutputState(int port, byte power, int mode, int regulationMode, int turnRatio, int runState, int tachoLimit)
           
 void setVerify(boolean verify)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

NXTCommand

public NXTCommand()
Method Detail

open

public void open(String name)
          throws IOException
Throws:
IOException

setOutputState

public byte setOutputState(int port,
                           byte power,
                           int mode,
                           int regulationMode,
                           int turnRatio,
                           int runState,
                           int tachoLimit)
                    throws IOException
Parameters:
port - - Output port (0 - 2 or 0xFF for all three)
power - - Setpoint for power. (-100 to 100)
mode - - Setting the modes MOTORON, BRAKE, and/or REGULATED. This parameter is a bitfield, so to put it in brake mode and regulated, use BRAKEMODE + REGULATED
regulationMode - - see NXTProtocol for enumerations
turnRatio - - Need two motors? (-100 to 100)
runState - - see NXTProtocol for enumerations
tachoLimit - - Number of degrees(?) to rotate before stopping.
Throws:
IOException

getTachoCount

public int getTachoCount(int port)
                  throws IOException
Retrieves tacho count.

Parameters:
port - - 0 to 3
Returns:
tacho count
Throws:
IOException

resetMotorPosition

public byte resetMotorPosition(int port,
                               boolean relative)
                        throws IOException
Resets the tachometer

Parameters:
port - Output port (0-2)
relative - TRUE: position relative to last movement, FALSE: absolute position
Throws:
IOException

setVerify

public void setVerify(boolean verify)

close

public void close()
           throws IOException
Call the close() command when your program ends, otherwise you will have to turn the NXT brick off/on before you run another program using iCommand.

Throws:
IOException

getBatteryLevel

public int getBatteryLevel()
                    throws IOException
Throws:
IOException

getInputValues

public InputValues getInputValues(int port)
                           throws IOException
Throws:
IOException

setInputMode

public byte setInputMode(int port,
                         int sensorType,
                         int sensorMode)
                  throws IOException
Tells the NXT what type of sensor you are using and the mode to operate in.

Parameters:
port - - 0 to 3
sensorType - - Enumeration for sensor type (see NXTProtocol)
sensorMode - - Enumeration for sensor mode (see NXTProtocol)
Throws:
IOException

playTone

public byte playTone(int frequency,
                     int duration)
              throws IOException
Plays a tone on NXT speaker. If a new tone is sent while the previous tone is playing, the new tone command will stop the old tone command.

Parameters:
frequency -
duration - - In milliseconds.
Returns:
- Returns true if command worked, false if it failed.
Throws:
IOException

getDeviceInfo

public DeviceInfo getDeviceInfo()
                         throws IOException
Throws:
IOException

getFirmwareVersion

public FirmwareInfo getFirmwareVersion()
                                throws IOException
Throws:
IOException

deleteUserFlash

public byte deleteUserFlash()
                     throws IOException
Deletes user flash memory (not including system modules).

Returns:
0 for success
Throws:
IOException