Class AbstractModbusElement<SELF extends AbstractModbusElement<?,?,?>,RAW,T>
- Type Parameters:
SELF
- the subclass of myselfRAW
- the raw value typeT
- the value type
- Direct Known Subclasses:
CoilElement
,ModbusRegisterElement
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected T
The next Write-Value.final OpenemsType
The type of the read and write value.Fields inherited from class io.openems.edge.bridge.modbus.api.element.ModbusElement
length, startAddress
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractModbusElement
(OpenemsType type, int startAddress, int length) -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.void
This is called on deactivate of the Modbus-Bridge.debug()
Activate Debug-Mode.fillElementsPriority
(AbstractModbusElement.FillElementsPriority fillElementsPriority) final RAW
Gets the next write value and resets it.final void
invalidate
(AbstractModbusBridge bridge) Invalidates the Channel in case it could not be read from the Modbus device, i.e.protected boolean
isDebug()
protected void
final SELF
onSetNextWrite
(Consumer<Optional<T>> callback) Add an onSetNextWrite callback.final SELF
onUpdateCallback
(Consumer<T> onUpdateCallback) The onUpdateCallback is called on reception of a new value.protected abstract T
rawToValue
(RAW value) Converts the RAW value from j2mod to the expected type.protected abstract SELF
self()
Gets an instance of the correct subclass of myself.final void
setInputValue
(RAW raw) Set the input/read value.final void
setNextWriteValue
(T value) Sets a value that should be written to the Modbus device.final void
Sets a value that should be written to the Modbus device.toString()
protected abstract RAW
valueToRaw
(T value) Methods inherited from class io.openems.edge.bridge.modbus.api.element.ModbusElement
getModbusTask, setModbusTask
-
Field Details
-
type
The type of the read and write value. -
nextWriteValue
The next Write-Value.
-
-
Constructor Details
-
AbstractModbusElement
-
-
Method Details
-
valueToRaw
-
rawToValue
Converts the RAW value from j2mod to the expected type.- Parameters:
value
- the raw value- Returns:
- the typed/converted value
-
self
Gets an instance of the correct subclass of myself.- Returns:
- myself
-
fillElementsPriority
Sets theAbstractModbusElement.FillElementsPriority
.By default (
AbstractModbusElement.FillElementsPriority.DEFAULT
all Element-to-Channel mappings are handled in array order of theReadTask
. Elements markedAbstractModbusElement.FillElementsPriority.HIGH
are handled first.This feature is useful for SunSpec devices, where the dynamic ScaleFactor for a Element is only at the end of the SunSpec block. Without HIGH priority, the ScaleFactor would always get applied too late.
- Parameters:
fillElementsPriority
- theAbstractModbusElement.FillElementsPriority
- Returns:
- myself
-
_getFillElementsPriority
Deprecated.FillElementsPriority. Used internally.- Returns:
- the
AbstractModbusElement.FillElementsPriority
-
setInputValue
Set the input/read value.- Parameters:
raw
- a value in raw format
-
setNextWriteValue
Sets a value that should be written to the Modbus device.- Parameters:
value
- the value; possibly null
-
setNextWriteValueFromObject
Sets a value that should be written to the Modbus device.- Parameters:
value
- the value; possibly null
-
getNextWriteValueAndReset
Gets the next write value and resets it.This method should be called once in every cycle on the TOPIC_CYCLE_EXECUTE_WRITE event. It makes sure, that the nextWriteValue gets initialized in every Cycle. If registers need to be written again in every cycle, next setNextWriteValue()-method needs to be called on every Cycle.
- Returns:
- the next write value
-
onNextWriteValueReset
protected void onNextWriteValueReset() -
onUpdateCallback
The onUpdateCallback is called on reception of a new value.Be aware, that this is the original, untouched value. ChannelToElementConverters are not applied here yet!
- Parameters:
onUpdateCallback
- the Callback- Returns:
- myself
-
onSetNextWrite
Add an onSetNextWrite callback. It is called when a 'next write value' was set.- Parameters:
callback
- the callback- Returns:
- myself
-
invalidate
Description copied from class:ModbusElement
Invalidates the Channel in case it could not be read from the Modbus device, i.e. sets the value to 'UNDEFINED'/null. Applies the 'invalidateElementsAfterReadErrors' config setting of the bridge.- Specified by:
invalidate
in classModbusElement
- Parameters:
bridge
- theAbstractModbusBridge
-
debug
Activate Debug-Mode.- Returns:
- myself
-
isDebug
protected boolean isDebug() -
toString
-
deactivate
public void deactivate()Description copied from class:ModbusElement
This is called on deactivate of the Modbus-Bridge. It can be used to clear any references like listeners.- Specified by:
deactivate
in classModbusElement
-