Class SerialPort

  • All Implemented Interfaces:
    AutoCloseable

    public class SerialPort
    extends Object
    implements AutoCloseable
    A SerialPort represents a serial port on the system. To open a serial port, use the appropriate constructor to open it, providing the entire path to the serial port, and optionally settings. You can define:
    • The speed of the serial port
    • The number of data bits
    • The number of stop bits.
    • The parity
    • The flow control
    • The control lines to monitor
    The special parameter controlLineFlags to the constructor defines what control lines you want to listen for. By default, you will get notifications for ALL_CONTROL_LINES if you install a SerialChangeListener. Note that any control line changes you want to listen for require a new thread per serial port. Often you don't need to listen to any serial line changes, and in that case you can pass NO_CONTROL_LINE_CHANGE to the constructor.

    Example:

     
     //Open up a serial port on Mac/Linux
     SerialPort s = new SerialPort( "/dev/ttyS0" );
     //Open up a serial port on Windows
     SerialPort s = new SerialPort( "COM1" );
     
     
    Once the port has been opened, you can change any setting that you want to(baud, parity, etc).

    The native code is automatically extracted from the jar file. If you need to use a special version, there are two Java properties to set.

    com.rm5248.javaserial.lib.path - give the directory name that the JNI code is located in
    com.rm5248.javaserial.lib.name - explicitly give the name of the library(the default is 'javaserial')

    Author:
    rm5248