public abstract class AbstractOpenemsModbusComponent extends AbstractOpenemsComponent
Modifier and Type | Class and Description |
---|---|
static class |
AbstractOpenemsModbusComponent.BitConverter |
class |
AbstractOpenemsModbusComponent.ChannelMapper<T extends AbstractModbusElement<?>>
Maps an Element to one or more ModbusChannels using converters, that convert
the value forward and backwards.
|
OpenemsComponent.ChannelId
Modifier | Constructor and Description |
---|---|
protected |
AbstractOpenemsModbusComponent(ChannelId[] firstInitialChannelIds,
ChannelId[]... furtherInitialChannelIds)
Default constructor for AbstractOpenemsModbusComponent.
|
Modifier and Type | Method and Description |
---|---|
protected void |
activate(org.osgi.service.component.ComponentContext context,
java.lang.String id,
java.lang.String alias,
boolean enabled)
Handles @Activate of implementations.
|
protected boolean |
activate(org.osgi.service.component.ComponentContext context,
java.lang.String id,
java.lang.String alias,
boolean enabled,
int unitId,
org.osgi.service.cm.ConfigurationAdmin cm,
java.lang.String modbusReference,
java.lang.String modbusId)
Call this method from Component implementations activate().
|
protected void |
activate(java.lang.String id) |
static java.lang.Short |
convert(int value,
int upperBytes)
Converts upper/lower bytes to Short.
|
protected void |
deactivate()
Handles @Deactivate of implementations.
|
protected abstract ModbusProtocol |
defineModbusProtocol()
Defines the Modbus protocol.
|
java.lang.Integer |
getUnitId() |
protected AbstractModbusElement<?> |
m(BitsWordElement bitsWordElement)
Maps the given BitsWordElement.
|
protected <T extends AbstractModbusElement<?>> |
m(ChannelId channelId,
T element)
Maps the given element 1-to-1 to the Channel identified by channelId.
|
protected <T extends AbstractModbusElement<?>> |
m(ChannelId channelId,
T element,
ElementToChannelConverter converter)
Maps the given element to the Channel identified by channelId, applying the
given @link{ElementToChannelConverter}.
|
protected <T extends AbstractModbusElement<?>> |
m(T element)
Creates a ChannelMapper that can be used with builder pattern inside the
protocol definition.
|
protected void |
setModbus(BridgeModbus modbus)
Set the Modbus bridge.
|
protected void |
unsetModbus(BridgeModbus modbus)
Unset the Modbus bridge.
|
_channel, addChannel, addChannels, addChannels, alias, channels, getComponentContext, id, isEnabled, logDebug, logError, logInfo, logWarn, modified, removeChannel
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
_getChannelAs, channel, channel, debugLog, getModbusSlaveNatureTable, getState, getStateChannel, hasFaults, serviceFactoryPid, servicePid, updateConfigurationProperty, updateReferenceFilter
protected AbstractOpenemsModbusComponent(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds)
Automatically initializes (i.e. creates Channel
instances for each
given ChannelId
using the Channel-Doc
.
It is important to list all Channel-ID enums of all inherited OpenEMS-Natures, i.e. for every OpenEMS Java interface you are implementing, you need to list the interface' ChannelID-enum here like Interface.ChannelId.values().
Use as follows:
public YourPhantasticOpenemsComponent() { super(// OpenemsComponent.ChannelId.values(), // YourPhantasticOpenemsComponent.ChannelId.values()); }
Note: the separation in firstInitialChannelIds and furtherInitialChannelIds is only there to enforce that calling the constructor cannot be forgotten. This way it needs to be called with at least one parameter - which is always at least "OpenemsComponent.ChannelId.values()". Just use it as if it was:
AbstractOpenemsComponent(ChannelId[]... channelIds)
firstInitialChannelIds
- the Channel-IDs to initialize.furtherInitialChannelIds
- the Channel-IDs to initialize.protected void activate(java.lang.String id)
protected boolean activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, java.lang.String modbusReference, java.lang.String modbusId) throws OpenemsException
context
- ComponentContext of this component. Receive it from
parameter for @Activateid
- ID of this component. Typically 'config.id()'alias
- Human-readable name of this Component. Typically
'config.alias()'. Defaults to 'id' if emptyenabled
- Whether the component should be enabled. Typically
'config.enabled()'unitId
- Unit-ID of the Modbus targetcm
- An instance of ConfigurationAdmin. Receive it
using @ReferencemodbusReference
- The name of the @Reference setter method for the
Modbus bridge - e.g. 'Modbus' if you have a
setModbus()-methodmodbusId
- The ID of the Modbus bridge. Typically
'config.modbus_id()'OpenemsException
- on errorprotected void activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled)
AbstractOpenemsComponent
activate
in class AbstractOpenemsComponent
context
- the OSGi ComponentContextid
- the unique OpenEMS Component IDalias
- Human-readable name of this Component. Typically
'config.alias()'. Defaults to 'id' if emptyenabled
- is the Component enabled?protected void deactivate()
AbstractOpenemsComponent
deactivate
in class AbstractOpenemsComponent
public java.lang.Integer getUnitId()
protected void setModbus(BridgeModbus modbus)
modbus
- the BridgeModbus Referenceprotected void unsetModbus(BridgeModbus modbus)
modbus
- the BridgeModbus Referenceprotected abstract ModbusProtocol defineModbusProtocol() throws OpenemsException
OpenemsException
- on errorprotected final <T extends AbstractModbusElement<?>> AbstractOpenemsModbusComponent.ChannelMapper<T> m(T element)
element
- the ModbusElementAbstractOpenemsModbusComponent.ChannelMapper
protected final AbstractModbusElement<?> m(BitsWordElement bitsWordElement)
bitsWordElement
- the ModbusElementprotected final <T extends AbstractModbusElement<?>> T m(ChannelId channelId, T element)
channelId
- the Channel-IDelement
- the ModbusElementprotected final <T extends AbstractModbusElement<?>> AbstractModbusElement<?> m(ChannelId channelId, T element, ElementToChannelConverter converter)
channelId
- the Channel-IDelement
- the ModbusElementconverter
- the ElementToChannelConverterpublic static java.lang.Short convert(int value, int upperBytes)
value
- the int valueupperBytes
- 1 = upper two bytes, 0 = lower two bytes