Interface ModbusCommunicationInterface
- All Superinterfaces:
AutoCloseable
Interface for interacting with a particular modbus slave.
When no further communication is expected with the slave, close the interface so that any underlying resources can be
freed.
Close unregisters all the regular polls registered with registerRegularPoll. When endpoint's last
communication interface is closed, the connection is closed as well, no matter the what EndpointPoolConfiguration
says.
- Author:
- Sami Salonen - Initial contribution
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this communication interface and try to free all resources associated with it Upon close, all polling tasks registered by this instance are unregistered.Get endpoint associated with this communication interfaceregisterRegularPoll
(ModbusReadRequestBlueprint request, long pollPeriodMillis, long initialDelayMillis, ModbusReadCallback resultCallback, ModbusFailureCallback<ModbusReadRequestBlueprint> failureCallback) Register regularly polled task.Future<?>
submitOneTimePoll
(ModbusReadRequestBlueprint request, ModbusReadCallback resultCallback, ModbusFailureCallback<ModbusReadRequestBlueprint> failureCallback) Submit one-time poll task.Future<?>
submitOneTimeWrite
(ModbusWriteRequestBlueprint request, ModbusWriteCallback resultCallback, ModbusFailureCallback<ModbusWriteRequestBlueprint> failureCallback) Submit one-time write task.boolean
Unregister regularly polled task If this communication interface is closed already, the method returns immediately with false return value
-
Method Details
-
getEndpoint
ModbusSlaveEndpoint getEndpoint()Get endpoint associated with this communication interface- Returns:
- modbus slave endpoint
-
submitOneTimePoll
Future<?> submitOneTimePoll(ModbusReadRequestBlueprint request, ModbusReadCallback resultCallback, ModbusFailureCallback<ModbusReadRequestBlueprint> failureCallback) Submit one-time poll task. The method returns immediately, and the execution of the poll task will happen in background.- Parameters:
request
- request to sendresultCallback
- callback to call with datafailureCallback
- callback to call in case of failure- Returns:
- future representing the polled task
- Throws:
IllegalStateException
- when this communication has been closed already
-
registerRegularPoll
PollTask registerRegularPoll(ModbusReadRequestBlueprint request, long pollPeriodMillis, long initialDelayMillis, ModbusReadCallback resultCallback, ModbusFailureCallback<ModbusReadRequestBlueprint> failureCallback) Register regularly polled task. The method returns immediately, and the execution of the poll task will happen in the background. One can register only one regular poll task for triplet of (endpoint, request, callback).- Parameters:
request
- request to sendpollPeriodMillis
- poll interval, in millisecondsinitialDelayMillis
- initial delay before starting polling, in millisecondsresultCallback
- callback to call with datafailureCallback
- callback to call in case of failure- Returns:
- poll task representing the regular poll
- Throws:
IllegalStateException
- when this communication has been closed already
-
unregisterRegularPoll
Unregister regularly polled task If this communication interface is closed already, the method returns immediately with false return value- Parameters:
task
- poll task to unregister- Returns:
- whether poll task was unregistered. Poll task is not unregistered in case of unexpected errors or in the case where the poll task is not registered in the first place
-
submitOneTimeWrite
Future<?> submitOneTimeWrite(ModbusWriteRequestBlueprint request, ModbusWriteCallback resultCallback, ModbusFailureCallback<ModbusWriteRequestBlueprint> failureCallback) Submit one-time write task. The method returns immediately, and the execution of the task will happen in background.- Parameters:
request
- request to sendresultCallback
- callback to call with responsefailureCallback
- callback to call in case of failure- Returns:
- future representing the task
- Throws:
IllegalStateException
- when this communication has been closed already
-
close
Close this communication interface and try to free all resources associated with it Upon close, all polling tasks registered by this instance are unregistered. In addition, connections are closed eagerly if this was the last connection interface pointing to the endpoint. After close, the communication interface cannot be used to communicate with the device.- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-