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, writeData
public 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)
,
SerialPortParameters
public 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)
,
SerialPortParameters
public 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)
,
SerialPortParameters
public 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)
,
SerialPortParameters
public void close()
IConnectionInterface
close
in interface IConnectionInterface
IConnectionInterface.isOpen()
,
IConnectionInterface.open()
public InputStream getInputStream()
IConnectionInterface
getInputStream
in interface IConnectionInterface
IConnectionInterface.getOutputStream()
,
InputStream
public OutputStream getOutputStream()
IConnectionInterface
getOutputStream
in interface IConnectionInterface
IConnectionInterface.getInputStream()
,
OutputStream
public int getReadTimeout()
AbstractSerialPort
getReadTimeout
in class AbstractSerialPort
AbstractSerialPort.setReadTimeout(int)
public boolean isCD()
AbstractSerialPort
isCD
in class AbstractSerialPort
true
if the line is high, false
otherwise.AbstractSerialPort.isCTS()
,
AbstractSerialPort.isDSR()
,
AbstractSerialPort.setDTR(boolean)
,
AbstractSerialPort.setRTS(boolean)
public boolean isCTS()
AbstractSerialPort
isCTS
in class AbstractSerialPort
true
if the line is high, false
otherwise.AbstractSerialPort.isCD()
,
AbstractSerialPort.isDSR()
,
AbstractSerialPort.setDTR(boolean)
,
AbstractSerialPort.setRTS(boolean)
public boolean isDSR()
AbstractSerialPort
isDSR
in class AbstractSerialPort
true
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()
,
SerialPortInfo
public void open() throws InterfaceInUseException, InvalidInterfaceException, InvalidConfigurationException, PermissionDeniedException
IConnectionInterface
open
in interface IConnectionInterface
InterfaceInUseException
- 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.CommPortOwnershipListener
public void sendBreak(int duration)
AbstractSerialPort
sendBreak
in class AbstractSerialPort
duration
- Duration of the break signal in milliseconds.AbstractSerialPort.setBreak(boolean)
public void serialEvent(gnu.io.SerialPortEvent event)
serialEvent
in interface gnu.io.SerialPortEventListener
public void setBreak(boolean enabled)
AbstractSerialPort
setBreak
in class AbstractSerialPort
enabled
- true
to enable the Break line, false
to
disable it.AbstractSerialPort.sendBreak(int)
public void setDTR(boolean state)
AbstractSerialPort
setDTR
in class AbstractSerialPort
state
- 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
AbstractSerialPort
setPortParameters
in class AbstractSerialPort
baudRate
- 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)
AbstractSerialPort
setReadTimeout
in class AbstractSerialPort
timeout
- The new read timeout of the serial port in milliseconds.AbstractSerialPort.getReadTimeout()
public void setRTS(boolean state)
AbstractSerialPort
setRTS
in class AbstractSerialPort
state
- 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.