Class ModbusDeviceSupport
java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.io.modbus.support.ModbusDeviceSupport
- All Implemented Interfaces:
net.solarnetwork.service.Identifiable
- Direct Known Subclasses:
ModbusDataDeviceSupport
public abstract class ModbusDeviceSupport
extends net.solarnetwork.node.service.support.BaseIdentifiable
A base helper class to support
ModbusNetwork based services.- Since:
- 2.0
- Version:
- 3.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default value for theIdentifiable.getUid()property filter value.static final intThe default value for theunitIdproperty.static final StringKey for the device manufacture date, as aLocalDate.protected final org.slf4j.LoggerA class-level logger.Fields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the device info data as a Map.Get direct access to the device info data.Return an informational message composed of general device info.net.solarnetwork.service.OptionalService.OptionalFilterableService<ModbusNetwork>Get the Modbus network to use.intGet the Modbus unit ID.Get the configured Modbus device name.protected final ModbusNetworkGet theModbusNetworkfrom the configuredmodbusNetworkservice, or null if not available or not configured.static List<net.solarnetwork.settings.SettingSpecifier>modbusNetworkSettings(String prefix) Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.protected final <T> TperformAction(ModbusConnectionAction<T> action) Perform some work with a ModbusModbusConnection.Read general device info and return a map of the results.protected voidsetDeviceInfoMap(Map<String, Object> deviceInfo) Set the device info data.voidsetModbusNetwork(net.solarnetwork.service.OptionalService.OptionalFilterableService<ModbusNetwork> modbusDevice) Set the Modbus network to use.voidsetUnitId(int unitId) Set the Modbus unit ID.Methods inherited from class net.solarnetwork.node.service.support.BaseIdentifiable
baseIdentifiableSettings, baseIdentifiableSettings, getExpressionServices, getPlaceholderService, populateExpressionDatumProperties, resolvePlaceholders, resolvePlaceholders, setExpressionServices, setPlaceholderServiceMethods inherited from class net.solarnetwork.service.support.BasicIdentifiable
basicIdentifiableMetadataSettings, basicIdentifiableSettings, basicIdentifiableSettings, basicIdentifiableSettings, doubleMetadataValue, getDisplayName, getGroupUid, getGroupUID, getMessageSource, getMetadata, getMetadataCount, getUid, getUID, integerMetadataValue, metadataValue, numberMetadataValue, saveMetadataValue, saveMetadataValue, setDisplayName, setGroupUid, setGroupUID, setMessageSource, setMetadata, setMetadataCount, setUid, setUID, smartMetadataValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.service.Identifiable
getDisplayName, getGroupUid, getUid
-
Field Details
-
DEFAULT_UNIT_ID
public static final int DEFAULT_UNIT_IDThe default value for theunitIdproperty.- Since:
- 1.2
- See Also:
-
DEFAULT_NETWORK_UID
The default value for theIdentifiable.getUid()property filter value.- Since:
- 1.2
- See Also:
-
INFO_KEY_DEVICE_MANUFACTURE_DATE
Key for the device manufacture date, as aLocalDate.- See Also:
-
log
protected final org.slf4j.Logger logA class-level logger.
-
-
Constructor Details
-
ModbusDeviceSupport
public ModbusDeviceSupport()
-
-
Method Details
-
modbusNetworkSettings
Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.- Parameters:
prefix- the setting prefix to prepend- Returns:
- list of setting specifiers
- Since:
- 1.2
-
modbusNetwork
Get theModbusNetworkfrom the configuredmodbusNetworkservice, or null if not available or not configured.- Returns:
- ModbusNetwork
-
readDeviceInfo
Read general device info and return a map of the results. See the variousINFO_KEY_*constants for information on the values returned in the result map.- Parameters:
conn- the connection to use- Returns:
- a map with general device information populated
- Throws:
IOException- if any IO error occurs
-
getDeviceInfoMessage
Return an informational message composed of general device info. This method will callgetDeviceInfo()and return a/(forward slash) delimited string of the resulting values, or null if that method returns null.- Returns:
- info message
-
getDeviceInfo
Get the device info data as a Map. This method will callreadDeviceInfo(ModbusConnection). The map is cached so subsequent calls will not attempt to read from the device. Note the returned map cannot be modified.- Returns:
- the device info, or null
- See Also:
-
performAction
Perform some work with a ModbusModbusConnection. This method attempts to obtain aModbusNetworkfrom the configuredmodbusNetworkservice, callingModbusNetwork.performAction(int, ModbusConnectionAction)if one can be obtained.- Type Parameters:
T- the result type- Parameters:
action- the connection action- Returns:
- the result of the callback, or null if the action is never invoked
- Throws:
IOException- if any IO error occurs
-
getDeviceInfoMap
Get direct access to the device info data.- Returns:
- the device info, or null
-
setDeviceInfoMap
Set the device info data. Setting thedeviceInfoto null will force the next call togetDeviceInfo()to read from the device to populate this data, and setting this to anything else will force all subsequent calls togetDeviceInfo()to simply return that map.- Parameters:
deviceInfo- the device info map to set
-
modbusDeviceName
Get the configured Modbus device name.- Returns:
- the modbus device name
- Since:
- 1.1
-
getModbusNetwork
public net.solarnetwork.service.OptionalService.OptionalFilterableService<ModbusNetwork> getModbusNetwork()Get the Modbus network to use.- Returns:
- the network
-
setModbusNetwork
public void setModbusNetwork(net.solarnetwork.service.OptionalService.OptionalFilterableService<ModbusNetwork> modbusDevice) Set the Modbus network to use.- Parameters:
modbusDevice- the network
-
getUnitId
public int getUnitId()Get the Modbus unit ID.- Returns:
- the unit ID; defaults to
DEFAULT_UNIT_ID
-
setUnitId
public void setUnitId(int unitId) Set the Modbus unit ID.The unit ID is the unique ID of the device on the Modbus network.
- Parameters:
unitId- the ID to use
-