public class SerialPortRxTx extends AbstractSerialPort implements gnu.io.SerialPortEventListener, gnu.io.CommPortOwnershipListener
DEFAULT_DATA_BITS, DEFAULT_FLOW_CONTROL, DEFAULT_PARITY, DEFAULT_PORT_TIMEOUT, DEFAULT_STOP_BITS| Constructor and Description |
|---|
SerialPortRxTx(String port,
int baudRate)
Class constructor.
|
SerialPortRxTx(String port,
int baudRate,
int receiveTimeout)
Class constructor.
|
SerialPortRxTx(String port,
SerialPortParameters parameters)
Class constructor.
|
SerialPortRxTx(String port,
SerialPortParameters parameters,
int receiveTimeout)
Class constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Attempts to close the connection interface.
|
InputStream |
getInputStream()
Returns the connection interface input stream to read data from.
|
OutputStream |
getOutputStream()
Returns the connection interface output stream to write data to.
|
int |
getReadTimeout()
Returns the read timeout of the serial port (in milliseconds).
|
boolean |
isCD()
Returns the state of the CD line.
|
boolean |
isCTS()
Returns the state of the CTS line.
|
boolean |
isDSR()
Returns the state of the DSR line.
|
static String[] |
listSerialPorts()
Retrieves the list of available serial ports in the system.
|
static ArrayList<SerialPortInfo> |
listSerialPortsInfo()
Retrieves the list of available serial ports with their information.
|
void |
open()
Attempts to open the connection interface.
|
void |
ownershipChange(int nType) |
void |
sendBreak(int duration)
Sends a break signal to the serial port with the given duration
(in milliseconds).
|
void |
serialEvent(gnu.io.SerialPortEvent event) |
void |
setBreak(boolean enabled)
Enables or disables the break line.
|
void |
setDTR(boolean state)
Sets the state of the DTR.
|
void |
setPortParameters(int baudRate,
int dataBits,
int stopBits,
int parity,
int flowControl)
Sets the new parameters of the serial port.
|
void |
setReadTimeout(int timeout)
Sets the read timeout of the serial port (in milliseconds).
|
void |
setRTS(boolean state)
Sets the state of the RTS line.
|
String |
toString() |
flush, getPort, getPortParameters, getReceiveTimeout, isHardwareFlowControl, isOpen, purge, readData, readData, setPortParameters, writeData, writeDatapublic SerialPortRxTx(String port, int baudRate)
SerialPortRxTx object using
the given parameters.port - Serial port name to use.baudRate - Serial port baud rate, the rest of parameters will be
set by default.NullPointerException - if port == null.AbstractSerialPort.DEFAULT_DATA_BITS,
AbstractSerialPort.DEFAULT_FLOW_CONTROL,
AbstractSerialPort.DEFAULT_PARITY,
AbstractSerialPort.DEFAULT_STOP_BITS,
AbstractSerialPort.DEFAULT_PORT_TIMEOUT,
SerialPortRxTx(String, int, int),
SerialPortRxTx(String, SerialPortParameters),
SerialPortRxTx(String, SerialPortParameters, int),
SerialPortParameterspublic SerialPortRxTx(String port, int baudRate, int receiveTimeout)
SerialPortRxTx object using
the given parameters.port - Serial port name to use.baudRate - Serial port baud rate, the rest of parameters will be
set by default.receiveTimeout - Serial port receive timeout in milliseconds.IllegalArgumentException - if receiveTimeout < 0.NullPointerException - if port == null.AbstractSerialPort.DEFAULT_DATA_BITS,
AbstractSerialPort.DEFAULT_FLOW_CONTROL,
AbstractSerialPort.DEFAULT_PARITY,
AbstractSerialPort.DEFAULT_STOP_BITS,
SerialPortRxTx(String, int),
SerialPortRxTx(String, SerialPortParameters),
SerialPortRxTx(String, SerialPortParameters, int),
SerialPortParameterspublic SerialPortRxTx(String port, SerialPortParameters parameters)
SerialPortRxTx object using
the given parameters.port - Serial port name to use.parameters - Serial port parameters.NullPointerException - if port == null or
if parameters == null.SerialPortRxTx(String, int),
SerialPortRxTx(String, int, int),
SerialPortRxTx(String, SerialPortParameters, int),
SerialPortParameterspublic SerialPortRxTx(String port, SerialPortParameters parameters, int receiveTimeout)
SerialPortRxTx object using
the given parameters.port - Serial port name to use.parameters - Serial port parameters.receiveTimeout - Serial port receive timeout in milliseconds.IllegalArgumentException - if receiveTimeout < 0.NullPointerException - if port == null or
if parameters == null.SerialPortRxTx(String, int),
SerialPortRxTx(String, int, int),
SerialPortRxTx(String, SerialPortParameters),
SerialPortParameterspublic void close()
IConnectionInterfaceclose in interface IConnectionInterfaceIConnectionInterface.isOpen(),
IConnectionInterface.open()public InputStream getInputStream()
IConnectionInterfacegetInputStream in interface IConnectionInterfaceIConnectionInterface.getOutputStream(),
InputStreampublic OutputStream getOutputStream()
IConnectionInterfacegetOutputStream in interface IConnectionInterfaceIConnectionInterface.getInputStream(),
OutputStreampublic int getReadTimeout()
AbstractSerialPortgetReadTimeout in class AbstractSerialPortAbstractSerialPort.setReadTimeout(int)public boolean isCD()
AbstractSerialPortisCD in class AbstractSerialPorttrue if the line is high, false otherwise.AbstractSerialPort.isCTS(),
AbstractSerialPort.isDSR(),
AbstractSerialPort.setDTR(boolean),
AbstractSerialPort.setRTS(boolean)public boolean isCTS()
AbstractSerialPortisCTS in class AbstractSerialPorttrue if the line is high, false otherwise.AbstractSerialPort.isCD(),
AbstractSerialPort.isDSR(),
AbstractSerialPort.setDTR(boolean),
AbstractSerialPort.setRTS(boolean)public boolean isDSR()
AbstractSerialPortisDSR in class AbstractSerialPorttrue if the line is high, false otherwise.AbstractSerialPort.isCD(),
AbstractSerialPort.isCTS(),
AbstractSerialPort.setDTR(boolean),
AbstractSerialPort.setRTS(boolean)public static String[] listSerialPorts()
listSerialPortsInfo()public static ArrayList<SerialPortInfo> listSerialPortsInfo()
listSerialPorts(),
SerialPortInfopublic void open() throws InterfaceInUseException, InvalidInterfaceException, InvalidConfigurationException, PermissionDeniedException
IConnectionInterfaceopen in interface IConnectionInterfaceInterfaceInUseException - if the interface is in use by other
application(s).InvalidInterfaceException - if the interface is invalid or does
not exist.InvalidConfigurationException - if the configuration used to open
the interface is invalid.PermissionDeniedException - if you do not have permissions to
access the interface.IConnectionInterface.close(),
IConnectionInterface.isOpen()public void ownershipChange(int nType)
ownershipChange in interface gnu.io.CommPortOwnershipListenerpublic void sendBreak(int duration)
AbstractSerialPortsendBreak in class AbstractSerialPortduration - Duration of the break signal in milliseconds.AbstractSerialPort.setBreak(boolean)public void serialEvent(gnu.io.SerialPortEvent event)
serialEvent in interface gnu.io.SerialPortEventListenerpublic void setBreak(boolean enabled)
AbstractSerialPortsetBreak in class AbstractSerialPortenabled - true to enable the Break line, false to
disable it.AbstractSerialPort.sendBreak(int)public void setDTR(boolean state)
AbstractSerialPortsetDTR in class AbstractSerialPortstate - true to set the line status high, false to
set it low.AbstractSerialPort.isCD(),
AbstractSerialPort.isCTS(),
AbstractSerialPort.isDSR(),
AbstractSerialPort.setRTS(boolean)public void setPortParameters(int baudRate, int dataBits, int stopBits, int parity, int flowControl) throws InvalidConfigurationException, ConnectionException
AbstractSerialPortsetPortParameters in class AbstractSerialPortbaudRate - The new value of baud rate.dataBits - The new value of data bits.stopBits - The new value of stop bits.parity - The new value of parity.flowControl - The new value of flow control.InvalidConfigurationException - if the configuration is invalid.ConnectionException - if any error occurs when setting the serial
port parametersAbstractSerialPort.getPortParameters(),
AbstractSerialPort.setPortParameters(SerialPortParameters)public void setReadTimeout(int timeout)
AbstractSerialPortsetReadTimeout in class AbstractSerialPorttimeout - The new read timeout of the serial port in milliseconds.AbstractSerialPort.getReadTimeout()public void setRTS(boolean state)
AbstractSerialPortsetRTS in class AbstractSerialPortstate - true to set the line status high, false to
set it low.AbstractSerialPort.isCD(),
AbstractSerialPort.isCTS(),
AbstractSerialPort.isDSR(),
AbstractSerialPort.setDTR(boolean)public String toString()
toString in class AbstractSerialPort© Copyright 2014–2014 Digi International Inc. All rights reserved.