T
- the type of the Channel. One out of OpenemsType
.public interface Channel<T>
OpenemsComponent
.
A Channel has
ChannelId
)
Doc
as static meta information. (via
channelDoc()
)
ChannelAddress
built from Component-ID and
Channel-ID. (via address()
OpenemsType
which needs to map to the generic parameter
<T>. (via getType()
)
Value
. (via value()
)
Channel#onChange(Consumer)
, onUpdate(Consumer)
and
onSetNextValue(Consumer)
)
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
.
Modifier and Type | Method and Description |
---|---|
void |
_setNextValue(T value)
Deprecated.
|
ChannelAddress |
address()
Gets the address of this Channel.
|
default Doc |
channelDoc()
Gets the ChannelDoc of this Channel.
|
ChannelId |
channelId()
Gets the ChannelId of this Channel.
|
void |
deactivate()
Deactivates the Channel and makes sure all callbacks are released for garbe
collection to avoid memory-leaks.
|
OpenemsComponent |
getComponent()
Gets the OpenemsComponent this Channel belongs to.
|
Value<T> |
getNextValue()
Gets the 'next value'.
|
CircularTreeMap<java.time.LocalDateTime,Value<T>> |
getPastValues()
Gets the past values for this Channel.
|
OpenemsType |
getType()
Gets the type of this Channel, e.g.
|
void |
nextProcessImage()
Switches to the next process image, i.e.
|
java.util.function.BiConsumer<Value<T>,Value<T>> |
onChange(java.util.function.BiConsumer<Value<T>,Value<T>> callback)
Add an onChange callback.
|
java.util.function.Consumer<Value<T>> |
onSetNextValue(java.util.function.Consumer<Value<T>> callback)
Add an onSetNextValue callback.
|
java.util.function.Consumer<Value<T>> |
onUpdate(java.util.function.Consumer<Value<T>> callback)
Add an onUpdate callback.
|
void |
removeOnChangeCallback(java.util.function.BiConsumer<?,?> callback)
Removes an onChange callback.
|
void |
removeOnSetNextValueCallback(java.util.function.Consumer<?> callback)
Removes an onSetNextValue callback.
|
void |
removeOnUpdateCallback(java.util.function.Consumer<Value<?>> callback)
Removes an onUpdate callback.
|
default void |
setNextValue(java.lang.Object value)
Updates the 'next value' of Channel.
|
Value<T> |
value()
Gets the currently active value, wrapped in a @{link Value}.
|
ChannelId channelId()
default Doc channelDoc()
OpenemsComponent getComponent()
ChannelAddress address()
void nextProcessImage()
OpenemsType getType()
default void setNextValue(java.lang.Object value)
value
- the 'next value'. It is going to be the 'value' after the next
ProcessImage gets activated.Value<T> getNextValue()
Note that usually you should prefer the value() method.
java.util.function.Consumer<Value<T>> onSetNextValue(java.util.function.Consumer<Value<T>> callback)
Remember to remove the callback using
removeOnSetNextValueCallback(Consumer)
once it is not needed
anymore, e.g. on deactivate().
callback
- the callback Consumer
onUpdate(java.util.function.Consumer<io.openems.edge.common.channel.value.Value<T>>)
void removeOnSetNextValueCallback(java.util.function.Consumer<?> callback)
callback
- the callback Consumer
onSetNextValue(Consumer)
@Deprecated void _setNextValue(T value)
value
- the 'next value'Value<T> value() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if value cannot be access, e.g. because the
Channel is Write-Only.CircularTreeMap<java.time.LocalDateTime,Value<T>> getPastValues()
java.util.function.Consumer<Value<T>> onUpdate(java.util.function.Consumer<Value<T>> callback)
void removeOnUpdateCallback(java.util.function.Consumer<Value<?>> callback)
callback
- the callback Consumer
onUpdate(Consumer)
java.util.function.BiConsumer<Value<T>,Value<T>> onChange(java.util.function.BiConsumer<Value<T>,Value<T>> callback)
callback
- old value and new valuevoid removeOnChangeCallback(java.util.function.BiConsumer<?,?> callback)
callback
- the callback BiConsumer
onChange(BiConsumer)
void deactivate()