public class ModbusTCPTransaction extends Object implements ModbusTransaction
| Constructor and Description |
|---|
ModbusTCPTransaction()
Constructs a new ModbusTCPTransaction
instance.
|
ModbusTCPTransaction(ModbusRequest request)
Constructs a new ModbusTCPTransaction
instance with a given ModbusRequest to
be send when the transaction is executed.
|
ModbusTCPTransaction(TCPMasterConnection con)
Constructs a new ModbusTCPTransaction
instance with a given TCPMasterConnection to
be used for transactions.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkValidity()
Checks the validity of the transaction, by
checking if the values of the response correspond
to the values of the request.
|
void |
execute()
Executes this ModbusTransaction.
|
ModbusRequest |
getRequest()
Returns the ModbusRequest instance
associated with this ModbusTransaction.
|
ModbusResponse |
getResponse()
Returns the ModbusResponse instance
associated with this ModbusTransaction.
|
int |
getRetries()
Returns the amount of retries for opening
the connection for executing the transaction.
|
int |
getTransactionID()
Returns the actual transaction identifier of
this ModbusTransaction.
|
boolean |
isCheckingValidity()
Tests whether the validity of a transaction
will be checked.
|
boolean |
isReconnecting()
Tests if the connection will be openend
and closed for each execution.
|
void |
setCheckingValidity(boolean b)
Sets the flag that controls whether the
validity of a transaction will be checked.
|
void |
setConnection(TCPMasterConnection con)
Sets the connection on which this ModbusTransaction
should be executed.
|
void |
setReconnecting(boolean b)
Sets the flag that controls whether a
connection is openend and closed for
each execution or not.
|
void |
setRequest(ModbusRequest req)
Sets the ModbusRequest for this
ModbusTransaction.
|
void |
setRetries(int num)
Set the amount of retries for opening
the connection for executing the transaction.
|
public ModbusTCPTransaction()
public ModbusTCPTransaction(ModbusRequest request)
request - a ModbusRequest instance.public ModbusTCPTransaction(TCPMasterConnection con)
con - a TCPMasterConnection instance.public void setConnection(TCPMasterConnection con)
An implementation should be able to
handle open and closed connections.
con - a TCPMasterConnection.public void setRequest(ModbusRequest req)
ModbusTransaction
The related ModbusResponse is acquired
from the passed in ModbusRequest instance.
setRequest in interface ModbusTransactionreq - a ModbusRequest.public ModbusRequest getRequest()
ModbusTransactiongetRequest in interface ModbusTransactionpublic ModbusResponse getResponse()
ModbusTransactiongetResponse in interface ModbusTransactionpublic int getTransactionID()
ModbusTransactiongetTransactionID in interface ModbusTransactionpublic void setCheckingValidity(boolean b)
ModbusTransactionsetCheckingValidity in interface ModbusTransactionb - true if checking validity, false otherwise.public boolean isCheckingValidity()
ModbusTransactionisCheckingValidity in interface ModbusTransactionpublic void setReconnecting(boolean b)
b - true if reconnecting, false otherwise.public boolean isReconnecting()
public int getRetries()
ModbusTransactiongetRetries in interface ModbusTransactionpublic void setRetries(int num)
ModbusTransactionsetRetries in interface ModbusTransactionnum - the amount of retries as int.public void execute()
throws ModbusIOException,
ModbusSlaveException,
ModbusException
ModbusTransactionexecute in interface ModbusTransactionModbusException - if an I/O error occurs, or the response is a modbus protocol exception.ModbusIOExceptionModbusSlaveExceptionprotected void checkValidity()
throws ModbusException
ModbusException - if this transaction has not been valid.Copyright © 2017. All rights reserved.