Class AbstractOpenemsModbusComponent
- java.lang.Object
-
- io.openems.edge.common.component.AbstractOpenemsComponent
-
- io.openems.edge.bridge.modbus.api.AbstractOpenemsModbusComponent
-
- All Implemented Interfaces:
ModbusComponent
,OpenemsComponent
- Direct Known Subclasses:
AbstractEdge2Edge
,AbstractEssDcChargerFeneconCommercial40
,AbstractFeneconDessCharger
,AbstractGoodWe
,AbstractGoodWeEtCharger
,AbstractKmtronicRelay
,AbstractOpenemsSunSpecComponent
,AbstractSocomecMeter
,AdstecStoraxeEssImpl
,BatteryBoxC130Impl
,BmwBatteryImpl
,ClusterVersionB
,ClusterVersionCImpl
,EssFeneconBydContainer
,EssFeneconCommercial40Impl
,EvcsWebastoNextImpl
,FeneconCommercialBatteryImpl
,FeneconDessEssImpl
,FeneconDessGridMeterImpl
,FeneconDessPvMeterImpl
,FeneconHomeBatteryImpl
,FeneconMiniEssImpl
,FeneconMiniGridMeterImpl
,FeneconMiniPvMeterImpl
,FeneconProEssImpl
,FeneconProPvMeter
,GoodWeEmergencyPowerMeterImpl
,GoodWeGridMeterImpl
,GridconPcsImpl
,HyperchargerImpl
,MeterArtemesAM2
,MeterBControlEM300Impl
,MeterBgeTechDrt428M2Impl
,MeterCarloGavazziEm300Impl
,MeterJanitzaUmg511Impl
,MeterJanitzaUmg604Impl
,MeterJanitzaUmg96rme
,MeterKdk2puctImpl
,MeterMicrocareSdm630Impl
,MeterPqplusUmd96Impl
,MeterPqplusUmd97Impl
,MeterSchneiderActi9Smartlink
,MeterSmaShm20Impl
,MeterWeidmueller525
,MeterZiehlEfr4001IpImpl
,PlexlogDataloggerImpl
,RefuStore88kImpl
,SiemensPacMeterImpl
,SinexcelImpl
,SingleRack
,SingleRackVersionBImpl
,SingleRackVersionCImpl
,SolarLogImpl
,SunnyIslandEssImpl
,Wago
,WebastoImpl
,WeidmuellerUR20Impl
public abstract class AbstractOpenemsModbusComponent extends AbstractOpenemsComponent implements ModbusComponent
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.-
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
Constructors Modifier Constructor Description protected
AbstractOpenemsModbusComponent(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds)
Default constructor for AbstractOpenemsModbusComponent.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
activate(java.lang.String id)
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
deactivate()
Handles @Deactivate of implementations.protected abstract ModbusProtocol
defineModbusProtocol()
Defines the Modbus protocol.BridgeModbus
getBridgeModbus()
Gets the Modbus-Bridge.protected ModbusProtocol
getModbusProtocol()
Gets theModbusProtocol
.java.lang.Integer
getUnitId()
Gets the Modbus Unit-ID.protected AbstractModbusElement<?>
m(BitsWordElement bitsWordElement)
Maps the given BitsWordElement.protected <T extends AbstractModbusElement<?>>
Tm(ChannelId channelId, T element)
Maps the given element 1-to-1 to the Channel identified by channelId.protected <T extends AbstractModbusElement<?>>
Tm(ChannelId channelId, T element, ChannelMetaInfo channelMetaInfo)
Maps the given element 1-to-1 to the Channel identified by channelId.protected <T extends AbstractModbusElement<?>>
Tm(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<?>>
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 <T extends AbstractModbusElement<?>>
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, java.lang.String id, java.lang.String alias, boolean enabled)
Handles @Modified of implementations.protected boolean
modified(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
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 Detail
-
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 Detail
-
activate
protected void activate(java.lang.String id)
- Overrides:
activate
in classAbstractOpenemsComponent
-
activate
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
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, java.lang.String id, java.lang.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, 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
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, java.lang.String id, java.lang.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
public java.lang.Integer getUnitId()
Gets the Modbus Unit-ID.- Returns:
- the Modbus Unit-ID
-
setModbus
protected void setModbus(BridgeModbus modbus)
Set the Modbus bridge. Should be called by @Reference- Parameters:
modbus
- the BridgeModbus Reference
-
unsetModbus
protected void unsetModbus(BridgeModbus modbus)
Unset the Modbus bridge. Should be called by @Reference- Parameters:
modbus
- the BridgeModbus Reference
-
getBridgeModbus
public BridgeModbus getBridgeModbus()
Gets the Modbus-Bridge.- Returns:
- the
BridgeModbus
- eitherBridgeModbusSerial
orBridgeModbusTcp
-
getModbusProtocol
protected ModbusProtocol getModbusProtocol() throws OpenemsException
Gets theModbusProtocol
. Creates it viadefineModbusProtocol()
if it does not yet exist.- Returns:
- the
ModbusProtocol
- Throws:
OpenemsException
- on error
-
defineModbusProtocol
protected abstract ModbusProtocol defineModbusProtocol() throws OpenemsException
Defines the Modbus protocol.- Returns:
- the ModbusProtocol
- Throws:
OpenemsException
- on error
-
m
protected final <T extends AbstractModbusElement<?>> 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 theAbstractModbusElement
d- Parameters:
element
- the ModbusElement- Returns:
- a
AbstractOpenemsModbusComponent.ChannelMapper
-
m
protected final AbstractModbusElement<?> m(BitsWordElement bitsWordElement)
Maps the given BitsWordElement.- Parameters:
bitsWordElement
- the ModbusElement- Returns:
- the element parameter
-
m
protected final <T extends AbstractModbusElement<?>> T m(ChannelId channelId, T element)
Maps the given element 1-to-1 to the Channel identified by channelId.- Type Parameters:
T
- the type of theAbstractModbusElement
d- Parameters:
channelId
- the Channel-IDelement
- the ModbusElement- Returns:
- the element parameter
-
m
protected final <T extends AbstractModbusElement<?>> 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 theAbstractModbusElement
d- 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 AbstractModbusElement<?>> 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 theAbstractModbusElement
d- Parameters:
channelId
- the Channel-IDelement
- the ModbusElementconverter
- the ElementToChannelConverter- Returns:
- the element parameter
-
m
protected final <T extends AbstractModbusElement<?>> 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 theAbstractModbusElement
d- Parameters:
channelId
- the Channel-IDelement
- the ModbusElementconverter
- the ElementToChannelConverterchannelMetaInfo
- an object that holds meta information about the Channel- Returns:
- the element parameter
-
-