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
ModbusElement
s which have register addresses in the same range.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.openems.edge.bridge.modbus.api.task.Task
Task.ExecuteState
-
Field Summary
Fields inherited from class io.openems.edge.bridge.modbus.api.task.AbstractTask
elements, length, name, responseClazz, startAddress
-
Constructor Summary
ConstructorDescriptionAbstractReadTask
(String name, Class<RESPONSE> responseClazz, Class<ELEMENT> elementClazz, int startAddress, Priority priority, ModbusElement... elements) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
calculateNextPosition
(ModbusElement modbusElement, int position) Calculate the position of the next Element.protected abstract REQUEST
Factory for aModbusRequest
.execute
(AbstractModbusBridge bridge) Executes the tasks - i.e.Gets thePriority
of thisManagedTask
.protected abstract void
handleResponse
(ELEMENT element, int position, T[] response) Handle a Response, e.g.protected abstract T[]
parseResponse
(RESPONSE response) Parses aModbusResponse
to an array of values.protected final String
payloadToString
(REQUEST request) 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).Methods inherited from class io.openems.edge.bridge.modbus.api.task.AbstractTask
deactivate, debug, executeRequest, getElements, getLength, getLogVerbosity, getParent, getStartAddress, logError, logInfo, logRequest, payloadToString, setParent, toLogMessage, toLogMessage, toLogMessage, toLogMessage
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.openems.edge.bridge.modbus.api.task.Task
deactivate, getElements, getLength, getParent, getStartAddress, setParent
-
Constructor Details
-
AbstractReadTask
-
-
Method Details
-
execute
Description copied from class:AbstractTask
Executes the tasks - i.e. sends the query of a ReadTask or writes a WriteTask. -
getPriority
Description copied from interface:ManagedTask
Gets thePriority
of thisManagedTask
.- Specified by:
getPriority
in interfaceManagedTask
- 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
- theModbusElement
position
- the current positionresponse
- the convertedModbusResponse
values- Throws:
OpenemsException
- on error
-
calculateNextPosition
Calculate the position of the next Element.- Parameters:
modbusElement
- current Elementposition
- current position- Returns:
- next position
-
createModbusRequest
Factory for aModbusRequest
.- Returns:
- a new
ModbusRequest
-
parseResponse
Parses aModbusResponse
to an array of values.- Parameters:
response
- theModbusResponse
- Returns:
- array of results
- Throws:
OpenemsException
- on error
-
payloadToString
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 classAbstractTask<REQUEST extends com.ghgande.j2mod.modbus.msg.ModbusRequest,
RESPONSE extends com.ghgande.j2mod.modbus.msg.ModbusResponse> - Parameters:
request
- the request- Returns:
- a string
-