Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class MemoryLink
Two links joined back to back in memory: what one writes the other reads. For tests and for a simulated device a driver can talk to without hardware.
MemoryLink[] pair = MemoryLink.pair();
ByteLink tillSide = pair[0];
ByteLink deviceSide = pair[1]; // answer from a test threadMethods
public static MemoryLink[] pair() | Two connected links. |
public void open() | Connects. |
public boolean isOpen() | Whether open() succeeded and close() has not been called. |
public void write(byte[] data, int offset, int length)
throws IOException | Writes bytes, returning once they are handed to the device. |
public int read(byte[] buffer, int offset, int length, int timeout)
throws IOException | Reads what has arrived, waiting up to timeout milliseconds for the first byte. |
public void close() | Disconnects. |
Inherited methods
Method details
pair
public static MemoryLink[] pair()Two connected links.
Returns
the two ends; either may be the device’s
open
public void open()Connects. Does nothing when already open.
Throws
IOException- when the device cannot be reached
isOpen
public boolean isOpen()Returns
true while open
write
public void write(byte[] data, int offset, int length)
throws IOExceptionWrites bytes, returning once they are handed to the device.
Parameters
databyte[]- the buffer
offsetint- where to start in it
lengthint- how many bytes
Throws
IOException- when the link is closed or broken
read
public int read(byte[] buffer, int offset, int length, int timeout)
throws IOExceptionReads what has arrived, waiting up to
timeout milliseconds for the
first byte.Parameters
bufferbyte[]- where to put the bytes
offsetint- where to start in it
lengthint- at most how many bytes
timeoutint- how long to wait, in milliseconds
Returns
the number of bytes read; 0 when nothing arrived in time
Throws
IOException- when the link is closed or broken, including when the other side closed it
close
public void close()Disconnects. Safe to call more than once, and from any thread; a read
blocked in another thread fails soon after.