Package gnu.io

Class NRSerialPort


  • public class NRSerialPort
    extends java.lang.Object
    • Constructor Detail

      • NRSerialPort

        public NRSerialPort​(java.lang.String port)
        Class Constructor for a NRSerialPort with a given port and baudrate.
        Parameters:
        port - the port to connect to (i.e. COM6 or /dev/ttyUSB0)
      • NRSerialPort

        public NRSerialPort​(java.lang.String port,
                            int baud)
      • NRSerialPort

        public NRSerialPort​(java.lang.String port,
                            int baud,
                            int parity)
      • NRSerialPort

        public NRSerialPort​(java.lang.String port,
                            int baud,
                            int parity,
                            int dataBits)
      • NRSerialPort

        public NRSerialPort​(java.lang.String port,
                            int baud,
                            int parity,
                            int dataBits,
                            int stopBits)
    • Method Detail

      • connect

        public boolean connect()
      • getInputStream

        public java.io.InputStream getInputStream()
      • getOutputStream

        public java.io.OutputStream getOutputStream()
      • disconnect

        public void disconnect()
      • getAvailableSerialPorts

        public static java.util.Set<java.lang.String> getAvailableSerialPorts()
      • isConnected

        public boolean isConnected()
      • setConnected

        public void setConnected​(boolean connected)
      • setBaud

        public void setBaud​(int baud)
      • getBaud

        public int getBaud()
      • setParity

        public void setParity​(int parity)
      • getParity

        public int getParity()
      • setStopBits

        public void setStopBits​(int stopBits)
      • getStopBits

        public int getStopBits()
      • setDataBits

        public void setDataBits​(int dataBits)
      • getDataBits

        public int getDataBits()
      • enableRs485

        public int enableRs485​(boolean busEnableActiveLow,
                               int delayBusEnableBeforeSendMs,
                               int delayBusEnableAfterSendMs)
        Enables RS485 half-duplex bus communication for Linux. The Linux kernel uses the RTS pin as bus enable. If you use a device that is configured via the Linux device tree, take care to add "uart-has-rtscts" and to configure the RTS GPIO correctly. Before enabling RS485, the serial port must be connected/opened. See also:
        • https://www.kernel.org/doc/Documentation/serial/serial-rs485.txt
        • https://www.kernel.org/doc/Documentation/devicetree/bindings/serial/serial.txt
        Parameters:
        busEnableActiveLow - true, if the bus enable signal (RTS) shall be low during transmission
        delayBusEnableBeforeSendMs - delay of bus enable signal (RTS) edge to first data edge in ms (not supported by all serial drivers)
        delayBusEnableAfterSendMs - delay of bus enable signal (RTS) edge after end of transmission in ms (not supported by all serial drivers)
        Returns:
        the ioctl() return value
      • notifyOnDataAvailable

        public void notifyOnDataAvailable​(boolean b)
      • addEventListener

        public void addEventListener​(SerialPortEventListener lsnr)
                              throws java.util.TooManyListenersException
        Throws:
        java.util.TooManyListenersException
      • removeEventListener

        public void removeEventListener()
      • getSerialPortInstance

        public RXTXPort getSerialPortInstance()
        Gets the SerialPort instance. This will return null until connect() is successfully called.
        Returns:
        The SerialPort instance or null.