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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.openems.edge.bridge.modbus.api.BridgeModbus
BridgeModbus.ChannelId
Nested classes/interfaces inherited from interface io.openems.edge.common.component.OpenemsComponent
OpenemsComponent.ChannelId
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
Default Modbus retries.protected static final int
Default Modbus timeout in [ms].protected final ModbusWorker
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractModbusBridge
(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
activate
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled) Deprecated.protected void
activate
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, LogVerbosity logVerbosity, int invalidateElementsAfterReadErrors) void
addProtocol
(String sourceId, ModbusProtocol protocol) Adds the protocol.abstract void
Closes the Modbus connection.protected void
Handles @Deactivate of implementations.debugLog()
Gets some output that is suitable for a continuous Debug log.Gets the configuredLogVerbosity
.abstract com.ghgande.j2mod.modbus.io.ModbusTransaction
Creates a new Modbus Transaction on an open Modbus connection.void
handleEvent
(org.osgi.service.event.Event event) int
Gets the configured max number of errors before an element should be invalidated?.protected void
modified
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled) Deprecated.protected void
modified
(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, LogVerbosity logVerbosity, int invalidateElementsAfterReadErrors) void
removeProtocol
(String sourceId) Removes the protocol.void
retryModbusCommunication
(String sourceId) The Modbus Bridge marks defective Components, e.g.Methods inherited from class io.openems.edge.common.component.AbstractOpenemsComponent
_channel, activate, 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.BridgeModbus
_setCycleDelay, _setCycleTimeIsTooShort, getCycleDelay, getCycleDelayChannel, getCycleTimeIsTooShort, getCycleTimeIsTooShortChannel
Methods inherited from interface io.openems.edge.common.component.OpenemsComponent
_channel, _getChannelAs, alias, channel, channel, channels, getComponentContext, getState, getStateChannel, hasFaults, id, isEnabled, serviceFactoryPid, servicePid
-
Field Details
-
DEFAULT_TIMEOUT
protected static final int DEFAULT_TIMEOUTDefault Modbus timeout in [ms].Modbus library default is 3000 ms
- See Also:
-
DEFAULT_RETRIES
protected static final int DEFAULT_RETRIESDefault Modbus retries.Modbus library default is 5
- See Also:
-
worker
-
-
Constructor Details
-
AbstractModbusBridge
-
-
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 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?
-
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 classAbstractOpenemsComponent
-
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 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 void modified(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, LogVerbosity logVerbosity, int invalidateElementsAfterReadErrors) -
addProtocol
Adds the protocol.- Specified by:
addProtocol
in interfaceBridgeModbus
- Parameters:
sourceId
- Component-ID of the sourceprotocol
- the ModbusProtocol
-
removeProtocol
Removes the protocol.- Specified by:
removeProtocol
in interfaceBridgeModbus
- Parameters:
sourceId
- Component-ID of the source
-
handleEvent
public void handleEvent(org.osgi.service.event.Event event) - Specified by:
handleEvent
in interfaceorg.osgi.service.event.EventHandler
-
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 interfaceOpenemsComponent
- Returns:
- the debug log output
-
getNewModbusTransaction
public abstract com.ghgande.j2mod.modbus.io.ModbusTransaction getNewModbusTransaction() throws OpenemsExceptionCreates 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
Gets the configuredLogVerbosity
.- Returns:
LogVerbosity
-
invalidateElementsAfterReadErrors
public int invalidateElementsAfterReadErrors()Gets the configured max number of errors before an element should be invalidated?.- Returns:
- value
-
retryModbusCommunication
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 interfaceBridgeModbus
- Parameters:
sourceId
- the unique source identifier
-