Package gnu.io
Class NRSerialPort
- java.lang.Object
-
- gnu.io.NRSerialPort
-
public class NRSerialPort extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description NRSerialPort(java.lang.String port)
Class Constructor for a NRSerialPort with a given port and baudrate.NRSerialPort(java.lang.String port, int baud)
NRSerialPort(java.lang.String port, int baud, int parity)
NRSerialPort(java.lang.String port, int baud, int parity, int dataBits)
NRSerialPort(java.lang.String port, int baud, int parity, int dataBits, int stopBits)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEventListener(SerialPortEventListener lsnr)
boolean
connect()
void
disconnect()
int
enableRs485(boolean busEnableActiveLow, int delayBusEnableBeforeSendMs, int delayBusEnableAfterSendMs)
Enables RS485 half-duplex bus communication for Linux.static java.util.Set<java.lang.String>
getAvailableSerialPorts()
int
getBaud()
int
getDataBits()
java.io.InputStream
getInputStream()
java.io.OutputStream
getOutputStream()
int
getParity()
RXTXPort
getSerialPortInstance()
Gets theSerialPort
instance.int
getStopBits()
TelnetSerialPort
getTelnetSerialPortInstance()
Gets theSerialPort
instance.boolean
isConnected()
void
notifyOnDataAvailable(boolean b)
void
removeEventListener()
void
setBaud(int baud)
void
setConnected(boolean connected)
void
setDataBits(int dataBits)
void
setParity(int parity)
void
setStopBits(int stopBits)
-
-
-
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 transmissiondelayBusEnableBeforeSendMs
- 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 theSerialPort
instance. This will return null untilconnect()
is successfully called.- Returns:
- The
SerialPort
instance or null.
-
getTelnetSerialPortInstance
public TelnetSerialPort getTelnetSerialPortInstance()
Gets theSerialPort
instance. This will return null untilconnect()
is successfully called.- Returns:
- The
SerialPort
instance or null.
-
-