Class AbstractReadTask<REQUEST extends com.ghgande.j2mod.modbus.msg.ModbusRequest,RESPONSE extends com.ghgande.j2mod.modbus.msg.ModbusResponse,ELEMENT extends AbstractModbusElement,T>

java.lang.Object
io.openems.edge.bridge.modbus.api.task.AbstractTask<REQUEST,RESPONSE>
io.openems.edge.bridge.modbus.api.task.AbstractReadTask<REQUEST,RESPONSE,ELEMENT,T>
All Implemented Interfaces:
ReadTask, Task, ManagedTask
Direct Known Subclasses:
AbstractReadDigitalInputsTask, AbstractReadRegistersTask

public abstract class AbstractReadTask<REQUEST extends com.ghgande.j2mod.modbus.msg.ModbusRequest,RESPONSE extends com.ghgande.j2mod.modbus.msg.ModbusResponse,ELEMENT extends AbstractModbusElement,T> extends AbstractTask<REQUEST,RESPONSE> implements ReadTask
An abstract Modbus 'AbstractTask' is holding references to one or more Modbus ModbusElements which have register addresses in the same range.
  • Constructor Details

  • Method Details

    • execute

      public Task.ExecuteState execute(AbstractModbusBridge bridge)
      Description copied from class: AbstractTask
      Executes the tasks - i.e. sends the query of a ReadTask or writes a WriteTask.
      Specified by:
      execute in interface Task
      Specified by:
      execute in class AbstractTask<REQUEST extends com.ghgande.j2mod.modbus.msg.ModbusRequest,RESPONSE extends com.ghgande.j2mod.modbus.msg.ModbusResponse>
      Parameters:
      bridge - the Modbus-Bridge
      Returns:
      the number of executed Sub-Tasks
    • getPriority

      public Priority getPriority()
      Description copied from interface: ManagedTask
      Gets the Priority of this ManagedTask.
      Specified by:
      getPriority in interface ManagedTask
      Returns:
      the Priority
    • handleResponse

      protected abstract void handleResponse(ELEMENT element, int position, T[] response) throws OpenemsException
      Handle a Response, e.g. set the internal value.
      Parameters:
      element - the ModbusElement
      position - the current position
      response - the converted ModbusResponse values
      Throws:
      OpenemsException - on error
    • calculateNextPosition

      protected abstract int calculateNextPosition(ModbusElement modbusElement, int position)
      Calculate the position of the next Element.
      Parameters:
      modbusElement - current Element
      position - current position
      Returns:
      next position
    • createModbusRequest

      protected abstract REQUEST createModbusRequest()
      Factory for a ModbusRequest.
      Returns:
      a new ModbusRequest
    • parseResponse

      protected abstract T[] parseResponse(RESPONSE response) throws OpenemsException
      Parses a ModbusResponse to an array of values.
      Parameters:
      response - the ModbusResponse
      Returns:
      array of results
      Throws:
      OpenemsException - on error
    • payloadToString

      protected final String payloadToString(REQUEST request)
      Description copied from class: AbstractTask
      Converts the actual payload of the REQUEST to a human readable format suitable for logs; without header data (like Unit-ID, function code, checksum, etc).
      Specified by:
      payloadToString in class AbstractTask<REQUEST extends com.ghgande.j2mod.modbus.msg.ModbusRequest,RESPONSE extends com.ghgande.j2mod.modbus.msg.ModbusResponse>
      Parameters:
      request - the request
      Returns:
      a string