public abstract class ModbusSerialTransport extends Object implements ModbusTransport
| Modifier and Type | Field and Description |
|---|---|
protected CommPort |
m_CommPort
The M comm port.
|
protected boolean |
m_Echo
The M echo.
|
| Constructor and Description |
|---|
ModbusSerialTransport() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
close()
The
close method closes the serial input/output streams. |
boolean |
isEcho()
isEcho method returns the output echo state. |
abstract void |
prepareStreams(InputStream in,
OutputStream out)
prepareStreams prepares the input and output streams of this
ModbusSerialTransport instance. |
void |
readEcho(int len)
Reads the own message echo produced in RS485 Echo Mode
within the given time frame.
|
abstract ModbusRequest |
readRequest()
The
readRequest method listens continuously on the serial
input stream for master request messages and replies if the request slave
ID matches its own set in ModbusCoupler.getUnitID(). |
abstract ModbusResponse |
readResponse()
readResponse reads a response message from the slave
responding to a master writeMessage request. |
void |
setCommPort(CommPort cp)
setCommPort sets the comm port member and prepares the input
and output streams to be used for reading from and writing to. |
void |
setEcho(boolean b)
setEcho method sets the output echo state. |
void |
setReceiveThreshold(int th)
Describe
setReceiveThreshold method here. |
void |
setReceiveTimeout(int ms)
Describe
setReceiveTimeout method here. |
abstract void |
writeMessage(ModbusMessage msg)
The
writeMessage method writes a modbus serial message to
its serial output stream to a specified slave unit ID. |
protected CommPort m_CommPort
protected boolean m_Echo
public abstract void prepareStreams(InputStream in, OutputStream out) throws IOException
prepareStreams prepares the input and output streams of this
ModbusSerialTransport instance.in - the input stream to be read from.out - the output stream to write to.IOException - if an I\O error occurs.public abstract ModbusResponse readResponse() throws ModbusIOException
readResponse reads a response message from the slave
responding to a master writeMessage request.readResponse in interface ModbusTransportModbusResponse valueModbusIOException - if an error occurspublic abstract ModbusRequest readRequest() throws ModbusIOException
readRequest method listens continuously on the serial
input stream for master request messages and replies if the request slave
ID matches its own set in ModbusCoupler.getUnitID().readRequest in interface ModbusTransportModbusRequest valueModbusIOException - if an error occurspublic abstract void writeMessage(ModbusMessage msg) throws ModbusIOException
writeMessage method writes a modbus serial message to
its serial output stream to a specified slave unit ID.writeMessage in interface ModbusTransportmsg - a ModbusMessage valueModbusIOException - if an error occurspublic abstract void close()
throws IOException
close method closes the serial input/output streams.close in interface ModbusTransportIOException - if an error occurspublic void setCommPort(CommPort cp) throws IOException
setCommPort sets the comm port member and prepares the input
and output streams to be used for reading from and writing to.cp - the comm port to read from/write to.IOException - if an I/O related error occurs.public boolean isEcho()
isEcho method returns the output echo state.boolean valuepublic void setEcho(boolean b)
setEcho method sets the output echo state.b - a boolean valuepublic void setReceiveThreshold(int th)
setReceiveThreshold method here.th - an int valuepublic void setReceiveTimeout(int ms)
setReceiveTimeout method here.ms - an int valuepublic void readEcho(int len)
throws IOException
len - is the length of the echo to read. Timeout will occur if the echo is not received in the time specified in the SerialConnection.IOException - if a I/O error occurred.Copyright © 2017. All rights reserved.