public class SerialConnection extends AbstractSerialConnection
| Modifier and Type | Field and Description |
|---|---|
static int |
CONNECT_RETRIES |
static int |
CONNECT_RETRY_DELAY |
EVEN_PARITY, FLOW_CONTROL_CTS_ENABLED, FLOW_CONTROL_DISABLED, FLOW_CONTROL_DSR_ENABLED, FLOW_CONTROL_DTR_ENABLED, FLOW_CONTROL_RTS_ENABLED, FLOW_CONTROL_XONXOFF_IN_ENABLED, FLOW_CONTROL_XONXOFF_OUT_ENABLED, MARK_PARITY, NO_PARITY, ODD_PARITY, ONE_POINT_FIVE_STOP_BITS, ONE_STOP_BIT, OPEN_DELAY, SPACE_PARITY, TIMEOUT_NONBLOCKING, TIMEOUT_READ_BLOCKING, TIMEOUT_READ_SEMI_BLOCKING, TIMEOUT_SCANNER, TIMEOUT_WRITE_BLOCKING, TWO_STOP_BITS| Constructor and Description |
|---|
SerialConnection()
Default constructor
|
SerialConnection(SerialParameters parameters)
Creates a SerialConnection object and initializes variables passed in as
params.
|
| Modifier and Type | Method and Description |
|---|---|
int |
bytesAvailable()
Bytes available to read
|
void |
close()
Close the port and clean up associated elements
|
int |
getBaudRate()
Returns current baud rate
|
static AbstractSerialConnection |
getCommPort(String commPort)
Returns a JSerialComm implementation for the given comms port
|
Set<String> |
getCommPorts()
Returns a set of all the available comm port names
|
String |
getDescriptivePortName()
Returns a descriptive name of the port
|
AbstractModbusTransport |
getModbusTransport()
Returns the ModbusTransport instance to be used for receiving
and sending messages.
|
int |
getNumDataBits()
Returns current data bits value
|
int |
getNumStopBits()
Returns current stop bits
|
int |
getParity()
Returns current parity
|
String |
getPortName()
Returns a name of the port
|
int |
getTimeout()
Returns the timeout for this connection
|
boolean |
isOpen()
Reports the open status of the port
|
void |
open()
Opens the port and throws an error if it cannot for some reason
|
int |
readBytes(byte[] buffer,
int bytesToRead)
Read a specified number of bytes from the serial port
|
void |
setComPortTimeouts(int newTimeoutMode,
int newReadTimeout,
int newWriteTimeout)
Set port timeouts
|
void |
setTimeout(int timeout)
Sets the timeout for this connection.
|
int |
writeBytes(byte[] buffer,
int bytesToWrite)
Write a specified number of bytes to the serial port
|
public static final int CONNECT_RETRY_DELAY
public static final int CONNECT_RETRIES
public SerialConnection()
public SerialConnection(SerialParameters parameters)
parameters - A SerialParameters object.public static AbstractSerialConnection getCommPort(String commPort)
commPort - Comms port e.g. /dev/ttyAMA0public AbstractModbusTransport getModbusTransport()
AbstractSerialConnectiongetModbusTransport in class AbstractSerialConnectionpublic void open()
throws IOException
AbstractSerialConnectionopen in class AbstractSerialConnectionIOException - If the port is not available or cannot be openedpublic void close()
AbstractSerialConnectionclose in class AbstractSerialConnectionpublic boolean isOpen()
AbstractSerialConnectionisOpen in class AbstractSerialConnectionpublic int getTimeout()
AbstractSerialConnectiongetTimeout in class AbstractSerialConnectionpublic void setTimeout(int timeout)
AbstractSerialConnectionsetTimeout in class AbstractSerialConnectiontimeout - the timeout as int millisecondspublic int readBytes(byte[] buffer,
int bytesToRead)
AbstractSerialConnectionreadBytes in class AbstractSerialConnectionbuffer - Buffer to recieve bytes from the portbytesToRead - Number of bytes to readpublic int writeBytes(byte[] buffer,
int bytesToWrite)
AbstractSerialConnectionwriteBytes in class AbstractSerialConnectionbuffer - Bytes to send to the portbytesToWrite - How many bytes to sendpublic int bytesAvailable()
AbstractSerialConnectionbytesAvailable in class AbstractSerialConnectionpublic int getBaudRate()
AbstractSerialConnectiongetBaudRate in class AbstractSerialConnectionpublic int getNumDataBits()
AbstractSerialConnectiongetNumDataBits in class AbstractSerialConnectionpublic int getNumStopBits()
AbstractSerialConnectiongetNumStopBits in class AbstractSerialConnectionpublic int getParity()
AbstractSerialConnectiongetParity in class AbstractSerialConnectionpublic String getPortName()
AbstractSerialConnectiongetPortName in class AbstractSerialConnectionpublic String getDescriptivePortName()
AbstractSerialConnectiongetDescriptivePortName in class AbstractSerialConnectionpublic void setComPortTimeouts(int newTimeoutMode,
int newReadTimeout,
int newWriteTimeout)
AbstractSerialConnectionsetComPortTimeouts in class AbstractSerialConnectionnewTimeoutMode - Timeout modenewReadTimeout - Read timeout (milliseconds)newWriteTimeout - Write timeout (milliseconds)public Set<String> getCommPorts()
AbstractSerialConnectiongetCommPorts in class AbstractSerialConnectionCopyright © 2025. All Rights Reserved.