Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class SerialPort
- Object
- SerialPort
A serial port in raw mode, opened through
Hardware.openSerial(String, int, int, int, int).
Reads block; call them off the event dispatch thread, or use [#read(byte[], int, int, int)] with a timeout.
Fields
public static final int PARITY_NONE = 0 | No parity bit. |
public static final int PARITY_ODD = 1 | Odd parity. |
public static final int PARITY_EVEN = 2 | Even parity. |
Methods
public String getDevice() | The device path this port was opened on. |
public int read(byte[] buf, int off, int len, int timeoutMs)
throws HardwareException | Reads up to len bytes, waiting at most timeoutMs for the first (negative waits indefinitely). |
public void write(byte[] buf, int off, int len)
throws HardwareException | Writes all of buf[off..off+len). |
public InputStream getInputStream() | A blocking stream over this port. |
public OutputStream getOutputStream() | A stream that writes to this port. |
public void close() | Closes the port. |
Inherited methods
Field details
PARITY_NONE
public static final int PARITY_NONE = 0No parity bit.
PARITY_ODD
public static final int PARITY_ODD = 1Odd parity.
PARITY_EVEN
public static final int PARITY_EVEN = 2Even parity.
Method details
getDevice
public String getDevice()The device path this port was opened on.
read
public int read(byte[] buf, int off, int len, int timeoutMs)
throws HardwareExceptionReads up to
len bytes, waiting at most timeoutMs for the first
(negative waits indefinitely). Returns the number read, 0 on timeout.Throws
HardwareException- when the read fails or the port is closed
write
public void write(byte[] buf, int off, int len)
throws HardwareExceptionWrites all of
buf[off..off+len).Throws
HardwareException- when the write fails or the port is closed
getInputStream
public InputStream getInputStream()A blocking stream over this port. Its
read waits until data arrives
and returns -1 only after close().getOutputStream
public OutputStream getOutputStream()A stream that writes to this port.
close
public void close()Closes the port. Closing twice is harmless.