Package lejos.hardware.device
Class UART
- java.lang.Object
-
- lejos.hardware.device.UART
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class UART extends java.lang.Object implements java.io.CloseableThis class provides low level access to a UART device.- Author:
- andy
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classUART.UARTInputStreaminternal class that provides an InputStream interface to a UARTprotected classUART.UARTOutputStreaminternal class that provides an OutputStream interface to a UART
-
Field Summary
Fields Modifier and Type Field Description protected java.io.InputStreaminputStreamprotected java.io.OutputStreamoutputStreamprotected UARTPortport
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()java.io.InputStreamgetInputStream()Return the InputStream associated with this device.java.io.OutputStreamgetOutputStream()Return the OutputStream associated with this device.intread(byte[] buffer, int offset, int len)Read bytes from the device.voidsetBitRate(int rate)Set the bit rate to be used by the UARTintwrite(byte[] buffer, int offset, int len)Write bytes to the device.
-
-
-
Field Detail
-
port
protected UARTPort port
-
inputStream
protected java.io.InputStream inputStream
-
outputStream
protected java.io.OutputStream outputStream
-
-
Constructor Detail
-
UART
public UART(Port port)
Create a UART device attached to the specified port.- Parameters:
port-
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
setBitRate
public void setBitRate(int rate)
Set the bit rate to be used by the UART- Parameters:
rate-
-
read
public int read(byte[] buffer, int offset, int len)Read bytes from the device. The read is non blocking and will return a count of 0 if no bytes are available to read.- Parameters:
buffer- buffer to read the bytes intooffset- first position that bytes will be read intolen- maximum number of bytes to read- Returns:
- actual number of bytes read
-
write
public int write(byte[] buffer, int offset, int len)Write bytes to the device. The write is non blocking and will return 0 if it is not possible to write to the device.- Parameters:
buffer- buffer to write fromoffset- offset of first byte to be writtenlen- number of bytes to try and write- Returns:
- number of bytes actually written
-
getInputStream
public java.io.InputStream getInputStream()
Return the InputStream associated with this device.- Returns:
- the InputStream that can be used to read from the UART
-
getOutputStream
public java.io.OutputStream getOutputStream()
Return the OutputStream associated with this device.- Returns:
- the OutputStream that can be used to write to the UART
-
-