Class AbstractModbusElement<T>
- java.lang.Object
-
- io.openems.edge.bridge.modbus.api.element.AbstractModbusElement<T>
-
- Type Parameters:
T
- the target OpenemsType
- All Implemented Interfaces:
ModbusElement<T>
- Direct Known Subclasses:
AbstractModbusRegisterElement
,CoilElement
,DummyCoilElement
,DummyRegisterElement
public abstract class AbstractModbusElement<T> extends java.lang.Object implements ModbusElement<T>
A ModbusElement represents one row of a Modbus definition table.
-
-
Field Summary
Fields Modifier and Type Field Description protected AbstractTask
abstractTask
protected java.util.List<java.util.function.Consumer<java.util.Optional<T>>>
onSetNextWriteCallbacks
-
Constructor Summary
Constructors Constructor Description AbstractModbusElement(OpenemsType type, int startAddress)
AbstractModbusElement(OpenemsType type, int startAddress, boolean isIgnored)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deactivate()
This is called on deactivate of the Modbus-Bridge.AbstractModbusElement<T>
debug()
Activate Debug-Mode.AbstractTask
getModbusTask()
int
getStartAddress()
Gets the start address of this Modbus element.OpenemsType
getType()
Gets the type of this Register, e.g.boolean
invalidate(AbstractModbusBridge bridge)
Invalidates the Channel in case it could not be read from the Modbus device, i.e.protected boolean
isDebug()
boolean
isIgnored()
Whether this Element should be ignored (= DummyElement).void
onSetNextWrite(java.util.function.Consumer<java.util.Optional<T>> callback)
Add an onSetNextWrite callback.AbstractModbusElement<T>
onUpdateCallback(java.util.function.Consumer<T> onUpdateCallback)
The onUpdateCallback is called on reception of a new value.void
setModbusTask(AbstractTask abstractTask)
Set theAbstractTask
, where this Element belongs to.protected void
setValue(T value)
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.openems.edge.bridge.modbus.api.element.ModbusElement
_setNextWriteValue, getLength
-
-
-
-
Field Detail
-
onSetNextWriteCallbacks
protected final java.util.List<java.util.function.Consumer<java.util.Optional<T>>> onSetNextWriteCallbacks
-
abstractTask
protected AbstractTask abstractTask
-
-
Constructor Detail
-
AbstractModbusElement
public AbstractModbusElement(OpenemsType type, int startAddress)
-
AbstractModbusElement
public AbstractModbusElement(OpenemsType type, int startAddress, boolean isIgnored)
-
-
Method Detail
-
onSetNextWrite
public final void onSetNextWrite(java.util.function.Consumer<java.util.Optional<T>> callback)
Description copied from interface:ModbusElement
Add an onSetNextWrite callback. It is called when a 'next write value' was set.- Specified by:
onSetNextWrite
in interfaceModbusElement<T>
- Parameters:
callback
- the callback
-
getType
public OpenemsType getType()
Description copied from interface:ModbusElement
Gets the type of this Register, e.g. INTEGER, BOOLEAN,..- Specified by:
getType
in interfaceModbusElement<T>
- Returns:
- the OpenemsType
-
onUpdateCallback
public AbstractModbusElement<T> onUpdateCallback(java.util.function.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
-
getStartAddress
public int getStartAddress()
Description copied from interface:ModbusElement
Gets the start address of this Modbus element.- Specified by:
getStartAddress
in interfaceModbusElement<T>
- Returns:
- the start address
-
isIgnored
public boolean isIgnored()
Description copied from interface:ModbusElement
Whether this Element should be ignored (= DummyElement).- Specified by:
isIgnored
in interfaceModbusElement<T>
- Returns:
- true for ignored elements
-
setModbusTask
public void setModbusTask(AbstractTask abstractTask)
Description copied from interface:ModbusElement
Set theAbstractTask
, where this Element belongs to.This is called by the
AbstractTask
constructor.- Specified by:
setModbusTask
in interfaceModbusElement<T>
- Parameters:
abstractTask
- the AbstractTask
-
getModbusTask
public AbstractTask getModbusTask()
-
setValue
protected void setValue(T value)
-
invalidate
public boolean invalidate(AbstractModbusBridge bridge)
Description copied from interface: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 interfaceModbusElement<T>
- Parameters:
bridge
- theAbstractModbusBridge
- Returns:
- true if Channel was invalidated
-
debug
public AbstractModbusElement<T> debug()
Activate Debug-Mode.- Returns:
- myself
-
isDebug
protected boolean isDebug()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
deactivate
public void deactivate()
Description copied from interface:ModbusElement
This is called on deactivate of the Modbus-Bridge. It can be used to clear any references like listeners.- Specified by:
deactivate
in interfaceModbusElement<T>
-
-