Package lejos.hardware.port
Interface UARTPort
-
- All Superinterfaces:
java.lang.AutoCloseable,BasicSensorPort,java.io.Closeable,IOPort,SensorConstants
- All Known Implementing Classes:
RemoteRequestUARTPort,RemoteUARTPort
public interface UARTPort extends IOPort, BasicSensorPort
-
-
Field Summary
Fields Modifier and Type Field Description static intUART_RAW_MODE-
Fields inherited from interface lejos.hardware.sensor.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, BROWN, GREEN, GREEN_INDEX, MAX_TYPE, MIN_TYPE, MODE_RAW, NXT_ADC_RES, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HIGHSPEED, TYPE_HIGHSPEED_9V, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description bytegetByte()read a single byte from the devicevoidgetBytes(byte[] vals, int offset, int len)read a number of bytes from the devicejava.lang.StringgetModeName(int mode)Get the string name of the specified mode.intgetShort()read a single short from the device.voidgetShorts(short[] vals, int offset, int len)read a number of shorts from the devicebooleaninitialiseSensor(int mode)Initialise the attached sensor and set it to the required operating mode.
Note: This method is not normally needed as the sensor will be initialised when it is opened.intrawRead(byte[] buffer, int offset, int len)Read bytes from the uart port.intrawWrite(byte[] buffer, int offset, int len)Attempt to write a series of bytes to the uart port.voidresetSensor()Reset the attached sensor.voidsetBitRate(int bitRate)Set the bit rate of the port when operating in RAW mode.java.lang.StringtoString()Return the current sensor reading to a string.intwrite(byte[] buffer, int offset, int len)Write bytes to the sensor-
Methods inherited from interface lejos.hardware.port.BasicSensorPort
getMode, getType, setMode, setType, setTypeAndMode
-
Methods inherited from interface lejos.hardware.port.IOPort
close, getName, setPinMode
-
-
-
-
Field Detail
-
UART_RAW_MODE
static final int UART_RAW_MODE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getByte
byte getByte()
read a single byte from the device- Returns:
- the byte value
-
getBytes
void getBytes(byte[] vals, int offset, int len)read a number of bytes from the device- Parameters:
vals- byte array to accept the dataoffset- offset at which to store the datalen- number of bytes to read
-
getShort
int getShort()
read a single short from the device.- Returns:
- the short value
-
getShorts
void getShorts(short[] vals, int offset, int len)read a number of shorts from the device- Parameters:
vals- short array to accept the dataoffset- offset at which to store the datalen- number of shorts to read
-
getModeName
java.lang.String getModeName(int mode)
Get the string name of the specified mode.TODO: Make other mode data available.
- Parameters:
mode- mode to lookup- Returns:
- String version of the mode name
-
toString
java.lang.String toString()
Return the current sensor reading to a string.- Overrides:
toStringin classjava.lang.Object
-
initialiseSensor
boolean initialiseSensor(int mode)
Initialise the attached sensor and set it to the required operating mode.
Note: This method is not normally needed as the sensor will be initialised when it is opened. However it may be of use if the sensor needs to be reset or in other cases.- Parameters:
mode- target mode- Returns:
- true if ok false if error
-
resetSensor
void resetSensor()
Reset the attached sensor. Following this the sensor must be initialised before it can be used.
-
write
int write(byte[] buffer, int offset, int len)Write bytes to the sensor- Parameters:
buffer- bytes to be writtenoffset- offset to the start of the writelen- length of the write- Returns:
- number of bytes written
-
rawRead
int rawRead(byte[] buffer, int offset, int len)Read bytes from the uart port. If no bytes are available return 0.Note: The port must have been set into RAW mode to use this method.
- Parameters:
buffer- The buffer to store the read bytesoffset- The offset at which to start storing the byteslen- The maximum number of bytes to read- Returns:
- The actual number of bytes read
-
rawWrite
int rawWrite(byte[] buffer, int offset, int len)Attempt to write a series of bytes to the uart port. This call is non-blocking if there is no space in the write buffer a count of 0 is returned.Note: The port must have been set into RAW mode before attempting to use the method.
- Parameters:
buffer- The buffer containing the bytes to writeoffset- The offset of the first bytelen- The number of bytes to attempt to write- Returns:
- The actual number of bytes written
-
setBitRate
void setBitRate(int bitRate)
Set the bit rate of the port when operating in RAW mode.- Parameters:
bitRate- The new bit rate
-
-