Class SerialLink
A serial port: an RS-232 cable, or a USB serial adapter the operating
system presents as one (COM3, /dev/ttyUSB0, /dev/ttyACM0).
Needs Hardware.FEATURE_SERIAL: the Windows and Linux desktop ports and
the simulator. On Android, reach a USB serial device through
UsbLink instead.
-
Constructor Summary
ConstructorsConstructorDescriptionSerialLink(String device, int baud) 8 data bits, no parity, one stop bit.SerialLink(String device, int baud, int dataBits, int parity, int stopBits) Parameters
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disconnects.booleanisOpen()WhetherByteLink.open()succeeded andByteLink.close()has not been called.voidopen()Connects.intread(byte[] buffer, int offset, int length, int timeout) Reads what has arrived, waiting up totimeoutmilliseconds for the first byte.voidwrite(byte[] data, int offset, int length) Writes bytes, returning once they are handed to the device.
-
Constructor Details
-
SerialLink
8 data bits, no parity, one stop bit.
Parameters
-
device: the port's device path or name -
baud: the speed
-
-
SerialLink
Parameters
-
device: the port's device path or name -
baud: the speed -
dataBits: 5 to 8 -
parity: one of theSerialPort.PARITY_constants -
stopBits: 1 or 2
-
-
-
Method Details
-
open
Description copied from class:ByteLinkConnects. Does nothing when already open.
Throws
IOException: when the device cannot be reached
- Specified by:
openin classByteLink- Throws:
IOException
-
isOpen
public boolean isOpen()Description copied from class:ByteLink -
write
Description copied from class:ByteLinkWrites bytes, returning once they are handed to the device.
Parameters
-
data: the buffer -
offset: where to start in it -
length: how many bytes
Throws
IOException: when the link is closed or broken
- Specified by:
writein classByteLink- Throws:
IOException
-
-
read
Description copied from class:ByteLinkReads what has arrived, waiting up to
timeoutmilliseconds for the first byte.Parameters
-
buffer: where to put the bytes -
offset: where to start in it -
length: at most how many bytes -
timeout: 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
- Specified by:
readin classByteLink- Throws:
IOException
-
-
close
-