Class AbstractModbusElement<SELF extends AbstractModbusElement<?,?,?>,RAW,T>

java.lang.Object
io.openems.edge.bridge.modbus.api.element.ModbusElement
io.openems.edge.bridge.modbus.api.element.AbstractModbusElement<SELF,RAW,T>
Type Parameters:
SELF - the subclass of myself
RAW - the raw value type
T - the value type
Direct Known Subclasses:
CoilElement, ModbusRegisterElement

public abstract non-sealed class AbstractModbusElement<SELF extends AbstractModbusElement<?,?,?>,RAW,T> extends ModbusElement
A ModbusElement represents one row of a Modbus definition table.
  • Field Details

    • type

      public final OpenemsType type
      The type of the read and write value.
    • nextWriteValue

      protected T nextWriteValue
      The next Write-Value.
  • Constructor Details

    • AbstractModbusElement

      protected AbstractModbusElement(OpenemsType type, int startAddress, int length)
  • Method Details

    • valueToRaw

      protected abstract RAW valueToRaw(T value)
    • rawToValue

      protected abstract T rawToValue(RAW value)
      Converts the RAW value from j2mod to the expected type.
      Parameters:
      value - the raw value
      Returns:
      the typed/converted value
    • self

      protected abstract SELF self()
      Gets an instance of the correct subclass of myself.
      Returns:
      myself
    • fillElementsPriority

      public SELF fillElementsPriority(AbstractModbusElement.FillElementsPriority fillElementsPriority)
      Sets the AbstractModbusElement.FillElementsPriority.

      By default (AbstractModbusElement.FillElementsPriority.DEFAULT all Element-to-Channel mappings are handled in array order of the ReadTask. Elements marked AbstractModbusElement.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 - the AbstractModbusElement.FillElementsPriority
      Returns:
      myself
    • _getFillElementsPriority

      @Deprecated public AbstractModbusElement.FillElementsPriority _getFillElementsPriority()
      Deprecated.
      FillElementsPriority. Used internally.
      Returns:
      the AbstractModbusElement.FillElementsPriority
    • setInputValue

      public final void setInputValue(RAW raw)
      Set the input/read value.
      Parameters:
      raw - a value in raw format
    • setNextWriteValue

      public final void setNextWriteValue(T value)
      Sets a value that should be written to the Modbus device.
      Parameters:
      value - the value; possibly null
    • setNextWriteValueFromObject

      public final void setNextWriteValueFromObject(Object value)
      Sets a value that should be written to the Modbus device.
      Parameters:
      value - the value; possibly null
    • getNextWriteValueAndReset

      public final RAW 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

      public final SELF onUpdateCallback(Consumer<T> 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

      public final SELF onSetNextWrite(Consumer<Optional<T>> callback)
      Add an onSetNextWrite callback. It is called when a 'next write value' was set.
      Parameters:
      callback - the callback
      Returns:
      myself
    • invalidate

      public final void invalidate(AbstractModbusBridge bridge)
      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 class ModbusElement
      Parameters:
      bridge - the AbstractModbusBridge
    • debug

      public SELF debug()
      Activate Debug-Mode.
      Returns:
      myself
    • isDebug

      protected boolean isDebug()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 class ModbusElement