Class AbstractOpenemsModbusComponent
- All Implemented Interfaces:
ModbusComponent
,OpenemsComponent
- Direct Known Subclasses:
AbstractEdge2Edge
,AbstractEssFeneconCommercial40Pv
,AbstractFeneconDessCharger
,AbstractGoodWe
,AbstractGoodWeEtCharger
,AbstractKmtronicRelay
,AbstractOpenemsSunSpecComponent
,AbstractSocomecMeter
,BatteryFeneconCommercialImpl
,BatteryFeneconHomeImpl
,BatteryInverterRefuStore88kImpl
,BatteryInverterSinexcelImpl
,BatterySoltaroClusterVersionBImpl
,BatterySoltaroClusterVersionCImpl
,BatterySoltaroSingleRackVersionAImpl
,BatterySoltaroSingleRackVersionBImpl
,BatterySoltaroSingleRackVersionCImpl
,BmwBatteryImpl
,BydBatteryBoxCommercialC130Impl
,EssAdstecStoraxeImpl
,EssFeneconBydContainerImpl
,EssFeneconCommercial40Impl
,EssSmaSunnyIslandImpl
,EvcsAlpitronicHyperchargerImpl
,EvcsWebastoNextImpl
,EvcsWebastoUniteImpl
,FeneconDessEssImpl
,FeneconDessGridMeterImpl
,FeneconDessPvMeterImpl
,FeneconMiniEssImpl
,FeneconMiniGridMeterImpl
,FeneconMiniPvMeterImpl
,FeneconProEssImpl
,FeneconProPvMeterImpl
,GoodWeEmergencyPowerMeterImpl
,GoodWeGridMeterImpl
,GridconPcsImpl
,IoFilipowskiMrAo1Impl
,IoWagoImpl
,IoWeidmuellerUr20Impl
,MeterArtemesAM2Impl
,MeterBControlEM300Impl
,MeterBgeTechDrt428M2Impl
,MeterCarloGavazziEm300Impl
,MeterJanitzaUmg511Impl
,MeterJanitzaUmg604Impl
,MeterJanitzaUmg96rmeImpl
,MeterKdk2puctImpl
,MeterMicrocareSdm630Impl
,MeterPlexlogDataloggerImpl
,MeterPqplusUmd96Impl
,MeterPqplusUmd97Impl
,MeterSchneiderActi9SmartlinkImpl
,MeterSiemensImpl
,MeterSmaShm20Impl
,MeterWeidmueller525Impl
,MeterZiehlEfr4001IpImpl
,PhoenixContactMeterImpl
,PvInverterSolarlogImpl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
class
Maps an Element to one or more ModbusChannels using converters, that convert the value forward and backwards.Nested classes/interfaces inherited from interface io.openems.edge.bridge.modbus.api.ModbusComponent
ModbusComponent.ChannelId
Nested classes/interfaces inherited from interface io.openems.edge.common.component.OpenemsComponent
OpenemsComponent.ChannelId
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractOpenemsModbusComponent
(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds) Default constructor for AbstractOpenemsModbusComponent. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
activate
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled) Handles @Activate of implementations.protected boolean
activate
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, String modbusReference, String modbusId) Call this method from Component implementations activate().protected void
Handles @Deactivate of implementations.protected abstract ModbusProtocol
Defines the Modbus protocol.Gets the Modbus-Bridge.protected ModbusProtocol
Gets theModbusProtocol
.Gets the Modbus Unit-ID.protected final BitsWordElement
m
(BitsWordElement bitsWordElement) Maps the given BitsWordElement.protected final <T extends ModbusElement>
TMaps the given element 1-to-1 to the Channel identified by channelId.protected final <T extends ModbusElement>
Tm
(ChannelId channelId, T element, ChannelMetaInfo channelMetaInfo) Maps the given element 1-to-1 to the Channel identified by channelId.protected final <T extends ModbusElement>
Tm
(ChannelId channelId, T element, ElementToChannelConverter converter) Maps the given element to the Channel identified by channelId, applying the given @link{ElementToChannelConverter}.protected final <T extends ModbusElement>
Tm
(ChannelId channelId, T element, ElementToChannelConverter converter, ChannelMetaInfo channelMetaInfo) Maps the given element to the Channel identified by channelId, applying the given @link{ElementToChannelConverter}.protected final <T extends ModbusElement>
AbstractOpenemsModbusComponent.ChannelMapper<T>m
(T element) Creates a ChannelMapper that can be used with builder pattern inside the protocol definition.protected void
modified
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled) Handles @Modified of implementations.protected boolean
modified
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, String modbusReference, String modbusId) Call this method from Component implementations activate().void
The Modbus Bridge marks defective Components, e.g.protected void
setModbus
(BridgeModbus modbus) Set the Modbus bridge.protected void
unsetModbus
(BridgeModbus modbus) Unset the Modbus bridge.Methods inherited from class io.openems.edge.common.component.AbstractOpenemsComponent
_channel, addChannel, addChannels, addChannels, alias, channels, getComponentContext, id, isEnabled, logDebug, logError, logInfo, logWarn, removeChannel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.openems.edge.bridge.modbus.api.ModbusComponent
_setModbusCommunicationFailed, getModbusCommunicationFailed, getModbusCommunicationFailedChannel
Methods inherited from interface io.openems.edge.common.component.OpenemsComponent
_channel, _getChannelAs, alias, channel, channel, channels, debugLog, getComponentContext, getState, getStateChannel, hasFaults, id, isEnabled, serviceFactoryPid, servicePid
-
Constructor Details
-
AbstractOpenemsModbusComponent
protected AbstractOpenemsModbusComponent(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds) Default constructor for AbstractOpenemsModbusComponent.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)
- Parameters:
firstInitialChannelIds
- the Channel-IDs to initialize.furtherInitialChannelIds
- the Channel-IDs to initialize.
-
-
Method Details
-
activate
- Overrides:
activate
in classAbstractOpenemsComponent
-
activate
protected boolean activate(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, String modbusReference, String modbusId) throws OpenemsException Call this method from Component implementations activate().- Parameters:
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()'- Returns:
- true if the target filter was updated. You may use it to abort the activate() method.
- Throws:
OpenemsException
- on error
-
activate
protected void activate(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled) Description copied from class:AbstractOpenemsComponent
Handles @Activate of implementations. Prints log output.- Overrides:
activate
in classAbstractOpenemsComponent
- Parameters:
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?
-
modified
protected boolean modified(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, String modbusReference, String modbusId) throws OpenemsException Call this method from Component implementations activate().- Parameters:
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()'- Returns:
- true if the target filter was updated. You may use it to abort the activate() method.
- Throws:
OpenemsException
- on error
-
modified
protected void modified(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled) Description copied from class:AbstractOpenemsComponent
Handles @Modified of implementations.- Overrides:
modified
in classAbstractOpenemsComponent
- Parameters:
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?
-
deactivate
protected void deactivate()Description copied from class:AbstractOpenemsComponent
Handles @Deactivate of implementations. Prints log output.- Overrides:
deactivate
in classAbstractOpenemsComponent
-
getUnitId
Gets the Modbus Unit-ID.- Returns:
- the Modbus Unit-ID
-
setModbus
Set the Modbus bridge. Should be called by @Reference- Parameters:
modbus
- the BridgeModbus Reference
-
unsetModbus
Unset the Modbus bridge. Should be called by @Reference- Parameters:
modbus
- the BridgeModbus Reference
-
getBridgeModbus
Gets the Modbus-Bridge.- Returns:
- the
BridgeModbus
- eitherBridgeModbusSerial
orBridgeModbusTcp
-
getModbusProtocol
Gets theModbusProtocol
. Creates it viadefineModbusProtocol()
if it does not yet exist.- Returns:
- the
ModbusProtocol
- Throws:
OpenemsException
- on error
-
retryModbusCommunication
public void retryModbusCommunication()Description copied from interface:ModbusComponent
The Modbus Bridge marks defective Components, e.g. if there are communication failures. If a component is marked as defective, reads and writes are paused for an increasing waiting time. This method resets the waiting time, causing the Modbus Bridge to retry if a Component is not anymore defective.Use this method if there is good reason that a Modbus Component should be available again 'now', e.g. because it was turned on manually.
- Specified by:
retryModbusCommunication
in interfaceModbusComponent
-
defineModbusProtocol
Defines the Modbus protocol.- Returns:
- the ModbusProtocol
- Throws:
OpenemsException
- on error
-
m
protected final <T extends ModbusElement> AbstractOpenemsModbusComponent.ChannelMapper<T> m(T element) Creates a ChannelMapper that can be used with builder pattern inside the protocol definition.- Type Parameters:
T
- the type of theModbusElement
- Parameters:
element
- the ModbusElement- Returns:
- a
AbstractOpenemsModbusComponent.ChannelMapper
-
m
Maps the given BitsWordElement.- Parameters:
bitsWordElement
- the ModbusElement- Returns:
- the element parameter
-
m
Maps the given element 1-to-1 to the Channel identified by channelId.- Type Parameters:
T
- the type of theModbusElement
- Parameters:
channelId
- the Channel-IDelement
- the ModbusElement- Returns:
- the element parameter
-
m
protected final <T extends ModbusElement> T m(ChannelId channelId, T element, ChannelMetaInfo channelMetaInfo) Maps the given element 1-to-1 to the Channel identified by channelId.- Type Parameters:
T
- the type of theModbusElement
- Parameters:
channelId
- the Channel-IDelement
- the ModbusElementchannelMetaInfo
- an object that holds meta information about the Channel- Returns:
- the element parameter
-
m
protected final <T extends ModbusElement> T m(ChannelId channelId, T element, ElementToChannelConverter converter) Maps the given element to the Channel identified by channelId, applying the given @link{ElementToChannelConverter}.- Type Parameters:
T
- the type of theModbusElement
- Parameters:
channelId
- the Channel-IDelement
- the ModbusElementconverter
- the ElementToChannelConverter- Returns:
- the element parameter
-
m
protected final <T extends ModbusElement> T m(ChannelId channelId, T element, ElementToChannelConverter converter, ChannelMetaInfo channelMetaInfo) Maps the given element to the Channel identified by channelId, applying the given @link{ElementToChannelConverter}.- Type Parameters:
T
- the type of theModbusElement
- Parameters:
channelId
- the Channel-IDelement
- the ModbusElementconverter
- the ElementToChannelConverterchannelMetaInfo
- an object that holds meta information about the Channel- Returns:
- the element parameter
-