Class SerialPort
java.lang.Object
com.codename1.hardware.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intEven parity.static final intNo parity bit.static final intOdd parity. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the port.The device path this port was opened on.A blocking stream over this port.A stream that writes to this port.intread(byte[] buf, int off, int len, int timeoutMs) Reads up tolenbytes, waiting at mosttimeoutMsfor the first (negative waits indefinitely).voidwrite(byte[] buf, int off, int len) Writes all ofbuf[off..off+len).
-
Field Details
-
PARITY_NONE
public static final int PARITY_NONENo parity bit.- See Also:
-
PARITY_ODD
public static final int PARITY_ODDOdd parity.- See Also:
-
PARITY_EVEN
public static final int PARITY_EVENEven parity.- See Also:
-
-
Method Details
-
getDevice
The device path this port was opened on. -
read
Reads up to
lenbytes, waiting at mosttimeoutMsfor the first (negative waits indefinitely). Returns the number read,0on timeout.Throws
HardwareException: when the read fails or the port is closed
- Throws:
HardwareException
-
write
Writes all of
buf[off..off+len).Throws
HardwareException: when the write fails or the port is closed
- Throws:
HardwareException
-
getInputStream
A blocking stream over this port. Itsreadwaits until data arrives and returns-1only afterclose(). -
getOutputStream
A stream that writes to this port. -
close
public void close()Closes the port. Closing twice is harmless.
-