Interface ModbusCommunicationInterface

  • All Superinterfaces:
    AutoCloseable

    @NonNullByDefault
    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.
    Author:
    Sami Salonen - Initial contribution
    • Method Detail

      • getEndpoint

        ModbusSlaveEndpoint getEndpoint()
        Get endpoint associated with this communication interface
        Returns:
        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).
        Parameters:
        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
        Returns:
        poll task representing the regular poll
        Throws:
        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
        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
      • 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
        Throws:
        Exception