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
Fields Modifier and Type Field Description protected static int
DEFAULT_RETRIES
Default Modbus retries.protected static int
DEFAULT_TIMEOUT
Default Modbus timeout in [ms].protected ModbusWorker
worker
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractModbusBridge(ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled)
Handles @Activate of implementations.protected void
activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled, LogVerbosity logVerbosity, int invalidateElementsAfterReadErrors)
void
addProtocol(java.lang.String sourceId, ModbusProtocol protocol)
Adds the protocol.abstract void
closeModbusConnection()
Closes the Modbus connection.protected void
deactivate()
Handles @Deactivate of implementations.abstract Cycle
getCycle()
Gets theCycle
.LogVerbosity
getLogVerbosity()
abstract com.ghgande.j2mod.modbus.io.ModbusTransaction
getNewModbusTransaction()
Creates a new Modbus Transaction on an open Modbus connection.void
handleEvent(org.osgi.service.event.Event event)
int
invalidateElementsAfterReadErrors()
After how many errors should a element be invalidated?.protected void
logError(org.slf4j.Logger log, java.lang.String message)
Log an error message including the Component ID.void
logInfo(org.slf4j.Logger log, java.lang.String message)
Log an info message including the Component ID.protected void
logWarn(org.slf4j.Logger log, java.lang.String message)
Log a warn message including the Component ID.void
removeProtocol(java.lang.String sourceId)
Removes the protocol.-
Methods inherited from class io.openems.edge.common.component.AbstractOpenemsComponent
_channel, activate, addChannel, addChannels, addChannels, alias, channels, getComponentContext, id, isEnabled, logDebug, modified, 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
_setCycleTimeIsTooShort, _setExecutionDuration, getCycleTimeIsTooShort, getCycleTimeIsTooShortChannel, getExecutionDuration, getExecutionDurationChannel
-
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
-
-
-
-
Field Detail
-
DEFAULT_TIMEOUT
protected static final int DEFAULT_TIMEOUT
Default Modbus timeout in [ms].Modbus library default is 3000 ms
- See Also:
- Constant Field Values
-
DEFAULT_RETRIES
protected static final int DEFAULT_RETRIES
Default Modbus retries.Modbus library default is 5
- See Also:
- Constant Field Values
-
worker
protected final ModbusWorker worker
-
-
Method Detail
-
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?
-
activate
protected void activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.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
-
addProtocol
public void addProtocol(java.lang.String sourceId, ModbusProtocol protocol)
Adds the protocol.- Specified by:
addProtocol
in interfaceBridgeModbus
- Parameters:
sourceId
- Component-ID of the sourceprotocol
- the ModbusProtocol
-
removeProtocol
public void removeProtocol(java.lang.String sourceId)
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
-
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()
-
logInfo
public void logInfo(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log an info message including the Component ID.- Overrides:
logInfo
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
logWarn
protected void logWarn(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log a warn message including the Component ID.- Overrides:
logWarn
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
logError
protected void logError(org.slf4j.Logger log, java.lang.String message)
Description copied from class:AbstractOpenemsComponent
Log an error message including the Component ID.- Overrides:
logError
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
invalidateElementsAfterReadErrors
public int invalidateElementsAfterReadErrors()
After how many errors should a element be invalidated?.- Returns:
- value
-
-