Class AbstractOpenemsModbusComponent

    • Constructor Detail

      • AbstractOpenemsModbusComponent

        protected AbstractOpenemsModbusComponent​(ChannelId[] firstInitialChannelIds,
                                                 ChannelId[]... furtherInitialChannelIds)
        Default constructor for AbstractOpenemsModbusComponent.

        Automatically initializes (i.e. creates Channel instances for each given OpenemsComponent.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)
      • 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 @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,
                                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 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,
                                   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 @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,
                                java.lang.String id,
                                java.lang.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?
      • 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
      • 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 the AbstractModbusElementd
        Parameters:
        channelId - the Channel-ID
        element - the ModbusElement
        Returns:
        the element parameter