public class NXTCommand extends java.lang.Object implements NXTProtocol
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_FILENAMELENGTH |
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, NXJ_DEFRAG, NXJ_DISCONNECT, NXJ_GET_AUTO_RUN, NXJ_GET_DEFAULT_PROGRAM, NXJ_GET_KEY_CLICK_VOLUME, NXJ_GET_SLEEP_TIME, NXJ_GET_VERSION, NXJ_GET_VOLUME, NXJ_PACKET_MODE, NXJ_SET_AUTO_RUN, NXJ_SET_DEFAULT_PROGRAM, NXJ_SET_KEY_CLICK_VOLUME, NXJ_SET_SLEEP_TIME, NXJ_SET_VOLUME, 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 and Description |
|---|
NXTCommand(NXTCommRequest nxtComm)
Create a NXTCommand object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
boot()
Put the NXT into SAMBA mode, ready to update the firmware.
|
void |
close()
Deprecated.
call disconnect, then close the underlying NXTComm
|
byte |
closeFile(byte handle)
Closes an open file.
|
byte |
defrag()
A NXJ extension to defrag the file system
|
byte |
delete(java.lang.String fileName)
Delete a file on the NXT
|
byte |
deleteUserFlash()
Deletes user flash memory.
|
void |
disconnect()
Tell the NXT that the connection is aborted.
|
FileInfo |
findFirst(java.lang.String wildCard)
Find the first file on the NXT.
|
FileInfo |
findNext(byte handle)
Find the next file on the NXT
|
boolean |
getAutoRun()
leJOS-specific command to get the auto run setring
|
int |
getBatteryLevel()
Get the battery reading
|
java.lang.String |
getCurrentProgramName()
Name of current running program.
|
java.lang.String |
getDefaultProgram()
leJOS-specific command to get the default program name
|
DeviceInfo |
getDeviceInfo()
Gets device information
|
FirmwareInfo |
getFirmwareVersion()
Get the fimrware version.
|
java.lang.String |
getFriendlyName()
Get the friendly name of the NXT
|
InputValues |
getInputValues(int port)
Get input values for a specific NXT sensor port
|
int |
getKeyClickVolume()
leJOS-specific command to get the master volume level
|
java.lang.String |
getLocalAddress()
Get the local address of the NXT.
|
NXJFirmwareInfo |
getNXJFirmwareInfo()
leJOS-specific command to get the NXJ firmware and menu information
|
java.lang.String |
getNXJFirmwareVersion()
leJOS-specific command to get the NXJ firmware version
|
java.lang.String |
getNXJMenuVersion()
leJOS-specific command to get the NXJ start-up menu version
|
OutputState |
getOutputState(int port)
Retrieves the current output state for a port.
|
int |
getSleepTime()
leJOS-specific method to get the menu sleep time
|
int |
getTachoCount(int port)
Retrieves tacho count.
|
int |
getVolume()
leJOS-specific command to get the master volume level
|
boolean |
isOpen()
Test is connection is open
|
byte[] |
LSGetStatus(byte port)
Returns the status for an Inter-Integrated Circuit (I2C) sensor (the
ultrasound sensor) via the Low Speed (LS) data port.
|
byte[] |
LSRead(byte port)
Reads data from an Inter-Integrated Circuit (I2C) sensor (the
ultrasound sensor) via the Low Speed (LS) data port.
|
byte |
LSWrite(byte port,
byte[] txData,
byte rxDataLength)
Used to request data from an Inter-Integrated Circuit (I2C) sensor (the
ultrasound sensor) via the Low Speed (LS) data port.
|
byte[] |
messageRead(byte remoteInbox,
byte localInbox,
boolean remove)
Read message.
|
byte |
messageWrite(byte[] message,
byte inbox)
Sends a message to an inbox on the NXT for storage(?)
For future reference, message size must be capped at 59 for USB.
|
FileInfo |
openRead(java.lang.String fileName)
Opens a file on the NXT for reading.
|
byte |
openWrite(java.lang.String fileName,
int size)
Opens a file on the NXT for writing.
|
byte |
playSoundFile(java.lang.String fileName,
boolean repeat) |
byte |
playTone(int frequency,
int duration)
Plays a tone on NXT speaker.
|
int |
readFile(byte handle,
byte[] data,
int offset,
int length)
Returns requested number of bytes from a file.
|
byte |
resetMotorPosition(int port,
boolean relative)
Resets either RotationCount or BlockTacho
|
byte |
setAutoRun(boolean on)
leJOS-specific command to set auto-run on or off
|
byte |
setDefaultProgram(java.lang.String name)
leJOS-specific command to set the default program
|
byte |
setFriendlyName(java.lang.String name)
Set the friendly name of the NXT
|
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 |
setKeyClickVolume(byte volume)
leJOS-specific command to set the key click volume level
|
byte |
setOutputState(int port,
byte power,
int mode,
int regulationMode,
int turnRatio,
int runState,
int tachoLimit) |
byte |
setSleepTime(byte seconds)
leJOS-specific command to the the sleep time for the menu
|
void |
setVerify(boolean verify)
Toggle the verify flag.
|
byte |
setVolume(byte volume)
leJOS-specific command to set the master volume level
|
byte |
startProgram(java.lang.String fileName)
Starts a program already on the NXT.
|
byte |
stopProgram()
Forces the currently executing program to stop.
|
byte |
stopSoundPlayback()
Stops sound file playing.
|
java.lang.String |
uploadFile(java.io.File file,
java.lang.String nxtFileName)
Upload a file to the NXT
|
byte |
writeFile(byte handle,
byte[] data,
int offset,
int length)
Write data to the file
|
public static final int MAX_FILENAMELENGTH
public NXTCommand(NXTCommRequest nxtComm)
public void setVerify(boolean verify)
verify - true causes all commands to return a response.public byte startProgram(java.lang.String fileName)
throws java.io.IOException
fileName - the file namejava.io.IOExceptionpublic byte stopProgram()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getCurrentProgramName()
throws java.io.IOException
java.io.IOExceptionpublic FileInfo openRead(java.lang.String fileName) throws java.io.IOException
fileName - e.g. "Woops.wav"java.io.IOExceptionpublic byte openWrite(java.lang.String fileName,
int size)
throws java.io.IOException
fileName - e.g. "Woops.wav"java.io.IOExceptionpublic byte closeFile(byte handle)
throws java.io.IOException
handle - File handle number.java.io.IOExceptionpublic byte delete(java.lang.String fileName)
throws java.io.IOException
fileName - the name of the filejava.io.IOExceptionpublic FileInfo findFirst(java.lang.String wildCard) throws java.io.IOException
wildCard - [filename].[extension], *.[extension], [filename].*, *.*java.io.IOExceptionpublic FileInfo findNext(byte handle) throws java.io.IOException
handle - Handle number from the previous found file or from the Find
First command.java.io.IOExceptionpublic int getBatteryLevel()
throws java.io.IOException
java.io.IOException@Deprecated
public void close()
throws java.io.IOException
java.io.IOExceptionpublic void disconnect()
throws java.io.IOException
java.io.IOExceptionpublic void boot()
throws java.io.IOException
java.io.IOExceptionpublic byte writeFile(byte handle,
byte[] data,
int offset,
int length)
throws java.io.IOException
handle - the file handledata - the data to writejava.io.IOExceptionpublic java.lang.String uploadFile(java.io.File file,
java.lang.String nxtFileName)
throws java.io.IOException
file - the file to uploadnxtFileName - the name of the file on the NXTjava.io.IOExceptionpublic int readFile(byte handle,
byte[] data,
int offset,
int length)
throws java.io.IOException
handle - File handle number (from openRead method)data - Buffer to which data is writtenoffset - Index of first byte to be overwrittenlength - Number of bytes to readjava.io.IOExceptionpublic byte defrag()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getFriendlyName()
throws java.io.IOException
java.io.IOExceptionpublic byte setFriendlyName(java.lang.String name)
throws java.io.IOException
name - the friendly namejava.io.IOExceptionpublic java.lang.String getLocalAddress()
throws java.io.IOException
java.io.IOExceptionpublic InputValues getInputValues(int port) throws java.io.IOException
port - the port numberjava.io.IOExceptionpublic OutputState getOutputState(int port) throws java.io.IOException
port - - 0 to 3java.io.IOExceptionpublic int getTachoCount(int port)
throws java.io.IOException
port - - 0 to 3java.io.IOExceptionpublic byte setInputMode(int port,
int sensorType,
int sensorMode)
throws java.io.IOException
port - - 0 to 3sensorType - - Enumeration for sensor type (see NXTProtocol)sensorMode - - Enumeration for sensor mode (see NXTProtocol)java.io.IOExceptionpublic byte[] LSGetStatus(byte port)
throws java.io.IOException
port - 0-3java.io.IOExceptionpublic byte[] LSRead(byte port)
throws java.io.IOException
port - java.io.IOExceptionpublic byte LSWrite(byte port,
byte[] txData,
byte rxDataLength)
throws java.io.IOException
txData - Transmitted data.rxDataLength - Receive data length.port - 0-3java.io.IOExceptionpublic byte[] messageRead(byte remoteInbox,
byte localInbox,
boolean remove)
throws java.io.IOException
remoteInbox - 0-9localInbox - 0-9remove - True clears the message from the remote inbox.java.io.IOExceptionpublic byte messageWrite(byte[] message,
byte inbox)
throws java.io.IOException
message - String to send.inbox - Inbox Number 0 - 9java.io.IOExceptionpublic byte playTone(int frequency,
int duration)
throws java.io.IOException
frequency - - 100 to 2000?duration - - In milliseconds.java.io.IOExceptionpublic byte playSoundFile(java.lang.String fileName,
boolean repeat)
throws java.io.IOException
java.io.IOExceptionpublic byte stopSoundPlayback()
throws java.io.IOException
java.io.IOExceptionpublic byte resetMotorPosition(int port,
boolean relative)
throws java.io.IOException
port - Output port (0-2)relative - TRUE: BlockTacho, FALSE: RotationCountjava.io.IOExceptionpublic byte setOutputState(int port,
byte power,
int mode,
int regulationMode,
int turnRatio,
int runState,
int tachoLimit)
throws java.io.IOException
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 + REGULATEDregulationMode - - see NXTProtocol for enumerationsturnRatio - - Need two motors? (-100 to 100)runState - - see NXTProtocol for enumerationstachoLimit - - Number of degrees(?) to rotate before stopping.java.io.IOExceptionpublic DeviceInfo getDeviceInfo() throws java.io.IOException
java.io.IOExceptionpublic FirmwareInfo getFirmwareVersion() throws java.io.IOException
java.io.IOExceptionpublic byte deleteUserFlash()
throws java.io.IOException
java.io.IOExceptionpublic byte setDefaultProgram(java.lang.String name)
throws java.io.IOException
name - the default program namejava.io.IOExceptionpublic byte setVolume(byte volume)
throws java.io.IOException
volume - the master volume leveljava.io.IOExceptionpublic byte setKeyClickVolume(byte volume)
throws java.io.IOException
volume - the key click volume leveljava.io.IOExceptionpublic byte setAutoRun(boolean on)
throws java.io.IOException
on - true = on, false = offjava.io.IOExceptionpublic int getVolume()
throws java.io.IOException
java.io.IOExceptionpublic int getKeyClickVolume()
throws java.io.IOException
java.io.IOExceptionpublic boolean getAutoRun()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getNXJFirmwareVersion()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getNXJMenuVersion()
throws java.io.IOException
java.io.IOExceptionpublic NXJFirmwareInfo getNXJFirmwareInfo() throws java.io.IOException
java.io.IOExceptionpublic int getSleepTime()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getDefaultProgram()
throws java.io.IOException
java.io.IOExceptionpublic byte setSleepTime(byte seconds)
throws java.io.IOException
seconds - the number of seconds before shutdownjava.io.IOExceptionpublic boolean isOpen()