Interface Channel<T>

Type Parameters:
T - the type of the Channel. One out of OpenemsType.
All Known Subinterfaces:
WriteChannel<T>
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

    • MAX_AGE_OF_PAST_VALUES

      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.
      Returns:
      the ChannelId
    • channelDoc

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

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

      ChannelAddress address()
      Gets the address of this Channel.
      Returns:
      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,..
      Returns:
      the OpenemsType
    • setNextValue

      default void setNextValue(Object value)
      Updates the 'next value' of Channel.
      Parameters:
      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.

      Returns:
      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().

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

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

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

      Gets the currently active value, wrapped in a @{link Value}.
      Returns:
      the active value, never null
      Throws:
      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.
      Returns:
      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().
      Parameters:
      callback - the callback
      Returns:
      the same callback for fluent coding
    • removeOnUpdateCallback

      void removeOnUpdateCallback(Consumer<Value<?>> callback)
      Removes an onUpdate callback.
      Parameters:
      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().
      Parameters:
      callback - old value and new value
      Returns:
      the same callback for fluent coding
    • removeOnChangeCallback

      void removeOnChangeCallback(BiConsumer<?,?> callback)
      Removes an onChange callback.
      Parameters:
      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
      Parameters:
      metaInfo - the meta info object
      Throws:
      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
      Returns:
      the meta info object