Class SerialPort

java.lang.Object
com.codename1.hardware.SerialPort

public final class SerialPort extends Object

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 Details

  • 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 HardwareException

      Reads 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
      Throws:
      HardwareException
    • write

      public void write(byte[] buf, int off, int len) throws HardwareException

      Writes all of buf[off..off+len).

      Throws
      • HardwareException: when the write fails or the port is closed
      Throws:
      HardwareException
    • 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.