Class AbstractModbusBridge

java.lang.Object
io.openems.edge.common.component.AbstractOpenemsComponent
io.openems.edge.bridge.modbus.api.AbstractModbusBridge
All Implemented Interfaces:
BridgeModbus, OpenemsComponent, org.osgi.service.event.EventHandler
Direct Known Subclasses:
BridgeModbusSerialImpl, BridgeModbusTcpImpl, DummyModbusBridge

public abstract class AbstractModbusBridge extends AbstractOpenemsComponent implements BridgeModbus, org.osgi.service.event.EventHandler
Abstract service for connecting to, querying and writing to a Modbus device.
  • Field Details

    • DEFAULT_TIMEOUT

      protected static final int DEFAULT_TIMEOUT
      Default Modbus timeout in [ms].

      Modbus library default is 3000 ms

      See Also:
    • DEFAULT_RETRIES

      protected static final int DEFAULT_RETRIES
      Default Modbus retries.

      Modbus library default is 5

      See Also:
    • worker

      protected final ModbusWorker worker
  • Constructor Details

    • AbstractModbusBridge

      protected AbstractModbusBridge(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds)
  • Method Details

    • activate

      @Deprecated protected void activate(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled)
      Deprecated.
      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?
    • activate

      protected void activate(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, LogVerbosity logVerbosity, int invalidateElementsAfterReadErrors)
    • deactivate

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

      @Deprecated protected void modified(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled)
      Deprecated.
      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?
    • modified

      protected void modified(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, LogVerbosity logVerbosity, int invalidateElementsAfterReadErrors)
    • addProtocol

      public void addProtocol(String sourceId, ModbusProtocol protocol)
      Adds the protocol.
      Specified by:
      addProtocol in interface BridgeModbus
      Parameters:
      sourceId - Component-ID of the source
      protocol - the ModbusProtocol
    • removeProtocol

      public void removeProtocol(String sourceId)
      Removes the protocol.
      Specified by:
      removeProtocol in interface BridgeModbus
      Parameters:
      sourceId - Component-ID of the source
    • handleEvent

      public void handleEvent(org.osgi.service.event.Event event)
      Specified by:
      handleEvent in interface org.osgi.service.event.EventHandler
    • debugLog

      public String debugLog()
      Description copied from interface: OpenemsComponent
      Gets some output that is suitable for a continuous Debug log. Returns 'null' by default which causes no output.
      Specified by:
      debugLog in interface OpenemsComponent
      Returns:
      the debug log output
    • getNewModbusTransaction

      public abstract com.ghgande.j2mod.modbus.io.ModbusTransaction getNewModbusTransaction() throws OpenemsException
      Creates a new Modbus Transaction on an open Modbus connection.
      Returns:
      the Modbus Transaction
      Throws:
      OpenemsException - on error
    • closeModbusConnection

      public abstract void closeModbusConnection()
      Closes the Modbus connection.
    • getLogVerbosity

      public LogVerbosity getLogVerbosity()
      Gets the configured LogVerbosity.
      Returns:
      LogVerbosity
    • invalidateElementsAfterReadErrors

      public int invalidateElementsAfterReadErrors()
      Gets the configured max number of errors before an element should be invalidated?.
      Returns:
      value
    • retryModbusCommunication

      public void retryModbusCommunication(String sourceId)
      Description copied from interface: BridgeModbus
      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 BridgeModbus
      Parameters:
      sourceId - the unique source identifier