public abstract class AbstractSerialPort extends Object implements IConnectionInterface
| Modifier and Type | Field and Description | 
|---|---|
static int | 
DEFAULT_DATA_BITS
Default number of data bits: 8. 
 | 
static int | 
DEFAULT_FLOW_CONTROL
Default flow control: 0 (None). 
 | 
static int | 
DEFAULT_PARITY
Default parity: 0 (None). 
 | 
static int | 
DEFAULT_PORT_TIMEOUT
Default receive timeout: 10 seconds. 
 | 
static int | 
DEFAULT_STOP_BITS
Default number of stop bits: 1. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
flush()
Flushes the available data of the output stream. 
 | 
String | 
getPort()
Returns the name of the serial port. 
 | 
SerialPortParameters | 
getPortParameters()
Returns the XBee serial port parameters. 
 | 
abstract int | 
getReadTimeout()
Returns the read timeout of the serial port (in milliseconds). 
 | 
int | 
getReceiveTimeout()
Returns the serial port receive timeout (in milliseconds). 
 | 
abstract boolean | 
isCD()
Returns the state of the CD line. 
 | 
abstract boolean | 
isCTS()
Returns the state of the CTS line. 
 | 
abstract boolean | 
isDSR()
Returns the state of the DSR line. 
 | 
boolean | 
isHardwareFlowControl()
Returns whether or not the port's flow control is configured in 
 hardware mode. 
 | 
boolean | 
isOpen()
Returns whether the connection interface is open or not. 
 | 
void | 
purge()
Purges the serial port removing all the data from the input stream. 
 | 
int | 
readData(byte[] data)
Reads data from the connection interface and stores it in the provided 
 byte array returning the number of read bytes. 
 | 
int | 
readData(byte[] data,
        int offset,
        int length)
Reads the given number of bytes at the given offset from the connection
 interface and stores it in the provided byte array returning the number
 of read bytes. 
 | 
abstract void | 
sendBreak(int duration)
Sends a break signal to the serial port with the given duration
 (in milliseconds). 
 | 
abstract void | 
setBreak(boolean enabled)
Enables or disables the break line. 
 | 
abstract 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 | 
setPortParameters(SerialPortParameters parameters)
Sets the new parameters of the serial port as 
  
SerialPortParameters. | 
abstract void | 
setReadTimeout(int timeout)
Sets the read timeout of the serial port (in milliseconds). 
 | 
abstract void | 
setRTS(boolean state)
Sets the state of the RTS line. 
 | 
String | 
toString()  | 
void | 
writeData(byte[] data)
Writes the given data in the connection interface. 
 | 
void | 
writeData(byte[] data,
         int offset,
         int length)
Writes the given data in the connection interface. 
 | 
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitclose, getInputStream, getOutputStream, openpublic static final int DEFAULT_DATA_BITS
public static final int DEFAULT_FLOW_CONTROL
public static final int DEFAULT_PARITY
public static final int DEFAULT_PORT_TIMEOUT
When the specified number of milliseconds have elapsed, read will return immediately.
public static final int DEFAULT_STOP_BITS
public SerialPortParameters getPortParameters()
setPortParameters(SerialPortParameters), 
setPortParameters(int, int, int, int, int), 
SerialPortParameterspublic abstract int getReadTimeout()
setReadTimeout(int)public int getReceiveTimeout()
getReadTimeout(), 
setReadTimeout(int)public abstract boolean isCD()
true if the line is high, false otherwise.isCTS(), 
isDSR(), 
setDTR(boolean), 
setRTS(boolean)public abstract boolean isCTS()
true if the line is high, false otherwise.isCD(), 
isDSR(), 
setDTR(boolean), 
setRTS(boolean)public abstract boolean isDSR()
true if the line is high, false otherwise.isCD(), 
isCTS(), 
setDTR(boolean), 
setRTS(boolean)public boolean isHardwareFlowControl()
true if the flow control is hardware, false 
         otherwise.getPortParameters(), 
setPortParameters(SerialPortParameters), 
setPortParameters(int, int, int, int, int)public boolean isOpen()
IConnectionInterfaceisOpen in interface IConnectionInterfacetrue if the connection interface is open, false 
         otherwise.IConnectionInterface.close(), 
IConnectionInterface.open()public void purge()
flush()public int readData(byte[] data) throws IOException
IConnectionInterfacereadData in interface IConnectionInterfacedata - The byte array to store the read data.IOException - if there is any problem reading from the input stream.IConnectionInterface.readData(byte[], int, int)public int readData(byte[] data, int offset, int length) throws IOException
IConnectionInterfacereadData in interface IConnectionInterfacedata - The byte array to store the read data.offset - The start offset in data array at which the data is written.length - Maximum number of bytes to read.IOException - if there is any problem reading from the input stream.IConnectionInterface.readData(byte[])public abstract void sendBreak(int duration)
duration - Duration of the break signal in milliseconds.setBreak(boolean)public abstract void setBreak(boolean enabled)
enabled - true to enable the Break line, false to 
                disable it.sendBreak(int)public abstract void setDTR(boolean state)
state - true to set the line status high, false to 
              set it low.isCD(), 
isCTS(), 
isDSR(), 
setRTS(boolean)public void setPortParameters(int baudRate, int dataBits, int stopBits, int parity, int flowControl) throws InvalidConfigurationException, ConnectionException
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.ConnectionException - if any error occurs when setting the serial 
                             port parametersIllegalArgumentException - if baudRate < 0 or
                                  if dataBits < 0 or
                                  if stopBits < 0 or
                                  if parity < 0 or
                                  if flowControl < 0.InvalidConfigurationException - if the configuration is invalid.getPortParameters(), 
setPortParameters(SerialPortParameters)public void setPortParameters(SerialPortParameters parameters) throws InvalidConfigurationException, ConnectionException
SerialPortParameters.parameters - The new serial port parameters.ConnectionException - if any error occurs when setting the serial 
                             port parameters.InvalidConfigurationException - if the configuration is invalid.NullPointerException - if parameters == null.getPortParameters(), 
setPortParameters(int, int, int, int, int), 
SerialPortParameterspublic abstract void setReadTimeout(int timeout)
timeout - The new read timeout of the serial port in milliseconds.getReadTimeout()public abstract void setRTS(boolean state)
state - true to set the line status high, false to 
              set it low.isCD(), 
isCTS(), 
isDSR(), 
setDTR(boolean)public void writeData(byte[] data) throws IOException
IConnectionInterfacewriteData in interface IConnectionInterfacedata - The data to be written in the connection interface.IOException - if there is any problem writing to the output stream.IConnectionInterface.writeData(byte[], int, int)public void writeData(byte[] data, int offset, int length) throws IOException
IConnectionInterfacewriteData in interface IConnectionInterfacedata - The data to be written in the connection interface.offset - The start offset in the data to write.length - The number of bytes to write.IOException - if there is any problem writing to the output stream.IConnectionInterface.writeData(byte[])© Copyright 2014–2014 Digi International Inc. All rights reserved.