Interface ModbusCommunicationInterface

  • All Superinterfaces:

    public interface ModbusCommunicationInterface
    extends 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.
    Sami Salonen - Initial contribution
    • Method Detail

      • getEndpoint

        ModbusSlaveEndpoint getEndpoint()
        Get endpoint associated with this communication interface
        modbus slave endpoint
      • 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).
        request - request to send
        pollPeriodMillis - poll interval, in milliseconds
        initialDelayMillis - initial delay before starting polling, in milliseconds
        callback - callback to call with data
        callback - callback to call in case of failure
        poll task representing the regular poll
        IllegalStateException - when this communication has been closed already
      • unregisterRegularPoll

        boolean unregisterRegularPoll​(PollTask task)
        Unregister regularly polled task If this communication interface is closed already, the method returns immediately with false return value
        task - poll task to unregister
        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
      • close

        void close()
            throws Exception
        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 interface AutoCloseable