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, AbstractEssFeneconCommercial40Pv, AbstractFeneconDessCharger, AbstractGoodWe, AbstractGoodWeEtCharger, AbstractKmtronicRelay, AbstractOpenemsSunSpecComponent, AbstractSocomecMeter, BatteryFeneconCommercialImpl, BatteryFeneconHomeImpl, BatteryInverterRefuStore88kImpl, BatteryInverterSinexcelImpl, BatterySoltaroClusterVersionBImpl, BatterySoltaroClusterVersionCImpl, BatterySoltaroSingleRackVersionAImpl, BatterySoltaroSingleRackVersionBImpl, BatterySoltaroSingleRackVersionCImpl, BmwBatteryImpl, BydBatteryBoxCommercialC130Impl, EssAdstecStoraxeImpl, EssFeneconBydContainerImpl, EssFeneconCommercial40Impl, EssSmaSunnyIslandImpl, EvcsAlpitronicHyperchargerImpl, EvcsSpelsbergSmartImpl, EvcsWebastoNextImpl, EvcsWebastoUniteImpl, FeneconDessEssImpl, FeneconDessGridMeterImpl, FeneconDessPvMeterImpl, FeneconMiniEssImpl, FeneconMiniGridMeterImpl, FeneconMiniPvMeterImpl, FeneconProEssImpl, FeneconProPvMeterImpl, GoodWeEmergencyPowerMeterImpl, GoodWeGridMeterImpl, GridconPcsImpl, IoFilipowskiMrAo1Impl, IoWagoImpl, IoWeidmuellerUr20Impl, MeterArtemesAM2Impl, MeterBControlEM300Impl, MeterBgeTechDrt428M2Impl, MeterCamillebauerAplusImpl, MeterCarloGavazziEm300Impl, MeterJanitzaUmg511Impl, MeterJanitzaUmg604Impl, MeterJanitzaUmg96rmeImpl, MeterKdk2puctImpl, MeterMicrocareSdm630Impl, MeterPlexlogDataloggerImpl, MeterPqplusUmd96Impl, MeterPqplusUmd97Impl, MeterSchneiderActi9SmartlinkImpl, MeterSiemensPac1600Impl, MeterSiemensPac2200Impl, MeterSmaShm20Impl, MeterWeidmueller525Impl, MeterZiehlEfr4001IpImpl, PhoenixContactMeterImpl, PvInverterSolarlogImpl

public abstract class AbstractOpenemsModbusComponent extends AbstractOpenemsComponent implements ModbusComponent
  • 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

      protected void activate(String id)
      Overrides:
      activate in class AbstractOpenemsComponent
    • 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 @Activate
      id - ID of this component. Typically 'config.id()'
      alias - Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if empty
      enabled - Whether the component should be enabled. Typically 'config.enabled()'
      unitId - Unit-ID of the Modbus target
      cm - An instance of ConfigurationAdmin. Receive it using @Reference
      modbusReference - The name of the @Reference setter method for the Modbus bridge - e.g. 'Modbus' if you have a setModbus()-method
      modbusId - 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 class AbstractOpenemsComponent
      Parameters:
      context - the OSGi ComponentContext
      id - the unique OpenEMS Component ID
      alias - Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if empty
      enabled - 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 @Activate
      id - ID of this component. Typically 'config.id()'
      alias - Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if empty
      enabled - Whether the component should be enabled. Typically 'config.enabled()'
      unitId - Unit-ID of the Modbus target
      cm - An instance of ConfigurationAdmin. Receive it using @Reference
      modbusReference - The name of the @Reference setter method for the Modbus bridge - e.g. 'Modbus' if you have a setModbus()-method
      modbusId - 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 class AbstractOpenemsComponent
      Parameters:
      context - the OSGi ComponentContext
      id - the unique OpenEMS Component ID
      alias - Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if empty
      enabled - is the Component enabled?
    • deactivate

      protected void deactivate()
      Description copied from class: AbstractOpenemsComponent
      Handles @Deactivate of implementations. Prints log output.
      Overrides:
      deactivate in class AbstractOpenemsComponent
    • getUnitId

      public 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 - either BridgeModbusSerial or BridgeModbusTcp
    • getModbusProtocol

      protected ModbusProtocol getModbusProtocol() throws OpenemsException
      Gets the ModbusProtocol. Creates it via defineModbusProtocol() 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 interface ModbusComponent
    • defineModbusProtocol

      protected abstract ModbusProtocol defineModbusProtocol() throws OpenemsException
      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 the ModbusElement
      Parameters:
      element - the ModbusElement
      Returns:
      a AbstractOpenemsModbusComponent.ChannelMapper
    • m

      protected final BitsWordElement m(BitsWordElement bitsWordElement)
      Maps the given BitsWordElement.
      Parameters:
      bitsWordElement - the ModbusElement
      Returns:
      the element parameter
    • m

      protected final <T extends ModbusElement> 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 the ModbusElement
      Parameters:
      channelId - the Channel-ID
      element - 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 the ModbusElement
      Parameters:
      channelId - the Channel-ID
      element - the ModbusElement
      channelMetaInfo - 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 the ModbusElement
      Parameters:
      channelId - the Channel-ID
      element - the ModbusElement
      converter - 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 the ModbusElement
      Parameters:
      channelId - the Channel-ID
      element - the ModbusElement
      converter - the ElementToChannelConverter
      channelMetaInfo - an object that holds meta information about the Channel
      Returns:
      the element parameter