Interface Channel<T>

Type Parameters:
T - the type of the Channel. One out of OpenemsType.
All Known Subinterfaces:
All Known Implementing Classes:
AbstractReadChannel, BooleanReadChannel, BooleanWriteChannel, DoubleReadChannel, DoubleWriteChannel, EnumReadChannel, EnumWriteChannel, FloatReadChannel, FloatWriteChannel, IntegerReadChannel, IntegerWriteChannel, LongReadChannel, LongWriteChannel, ShortReadChannel, ShortWriteChannel, StateChannel, StateCollectorChannel, StringReadChannel, StringWriteChannel

public interface Channel<T>
An OpenEMS Channel holds one specific piece of information of an OpenemsComponent.

A Channel has

Channels implement a 'Process Image' pattern. They provide an 'active' value which should be used for any operations on the channel value. The 'next' value is filled by asynchronous workers in the background. At the 'Process Image Switch' the 'next' value is copied to the 'current' value.

The recommended implementation of an OpenEMS Channel is via AbstractReadChannel.

  • Field Details


      static final TemporalAmount MAX_AGE_OF_PAST_VALUES
      Holds the maximum allowed age of past values based on the latest value for this Channel that are kept in the 'pastValues' variable.
  • Method Details

    • channelId

      ChannelId channelId()
      Gets the ChannelId of this Channel.
      the ChannelId
    • channelDoc

      default Doc channelDoc()
      Gets the ChannelDoc of this Channel.
      the ChannelDoc
    • getComponent

      OpenemsComponent getComponent()
      Gets the OpenemsComponent this Channel belongs to.
      the OpenemsComponent
    • address

      ChannelAddress address()
      Gets the address of this Channel.
      the ChannelAddress
    • nextProcessImage

      void nextProcessImage()
      Switches to the next process image, i.e. copies the "next"-value into "current"-value.
    • getType

      OpenemsType getType()
      Gets the type of this Channel, e.g. INTEGER, BOOLEAN,..
      the OpenemsType
    • setNextValue

      default void setNextValue(Object value)
      Updates the 'next value' of Channel.
      value - the 'next value'. It is going to be the 'value' after the next ProcessImage gets activated.
    • getNextValue

      Value<T> getNextValue()
      Gets the 'next value'.

      Note that usually you should prefer the value() method.

      the 'next value', never null
    • onSetNextValue

      Consumer<Value<T>> onSetNextValue(Consumer<Value<T>> callback)
      Add an onSetNextValue callback. It is called, after a new NextValue was set. Note that usually you should prefer the onUpdate() callback.

      Remember to remove the callback using removeOnSetNextValueCallback(Consumer) once it is not needed anymore, e.g. on deactivate().

      callback - the callback Consumer
      the callback to enable fluent programming
      See Also:
    • removeOnSetNextValueCallback

      void removeOnSetNextValueCallback(Consumer<?> callback)
      Removes an onSetNextValue callback.
      callback - the callback Consumer
      See Also:
    • _setNextValue

      @Deprecated void _setNextValue(T value)
      Internal method. Do not call directly.
      value - the 'next value'
    • value

      Gets the currently active value, wrapped in a @{link Value}.
      the active value, never null
      IllegalArgumentException - if value cannot be accessed, e.g. because the Channel is Write-Only.
    • getPastValues

      TreeMap<LocalDateTime,Value<T>> getPastValues()
      Gets the past values for this Channel.
      a map of recording time and historic value at that time
    • onUpdate

      Consumer<Value<T>> onUpdate(Consumer<Value<T>> callback)
      Add an onUpdate callback. It is called, after the active value was updated by nextProcessImage().
      callback - the callback
      the same callback for fluent coding
    • removeOnUpdateCallback

      void removeOnUpdateCallback(Consumer<Value<?>> callback)
      Removes an onUpdate callback.
      callback - the callback Consumer
      See Also:
    • onChange

      BiConsumer<Value<T>,Value<T>> onChange(BiConsumer<Value<T>,Value<T>> callback)
      Add an onChange callback. It is called, after a new, different active value was set by nextProcessImage().
      callback - old value and new value
      the same callback for fluent coding
    • removeOnChangeCallback

      void removeOnChangeCallback(BiConsumer<?,?> callback)
      Removes an onChange callback.
      callback - the callback BiConsumer
      See Also:
    • deactivate

      void deactivate()
      Deactivates the Channel and makes sure all callbacks are released for garbe collection to avoid memory-leaks.
    • setMetaInfo

      <META_INFO> void setMetaInfo(META_INFO metaInfo) throws IllegalArgumentException
      Sets an object that holds meta information about the Channel, e.g. a read source or write target of this Channel, like a Modbus Register or REST-Api endpoint address. Defaults to null.
      Type Parameters:
      META_INFO - the type of the meta info
      metaInfo - the meta info object
      IllegalArgumentException - if there is already a different meta-info registered with the Channel
    • getMetaInfo

      <META_INFO> META_INFO getMetaInfo()
      Gets the meta information object. Defaults to null.
      Type Parameters:
      META_INFO - the type of the meta info attachment
      the meta info object