Class ModbusDataDeviceSupport<T extends ModbusData & net.solarnetwork.node.domain.DataAccessor>
- Type Parameters:
T- theModbusDatatype
- All Implemented Interfaces:
net.solarnetwork.service.Identifiable
ModbusNetwork based device
implementations using ModbusData as a model object.- Since:
- 2.14
- Version:
- 2.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default value for thesampleCacheMsproperty.Fields inherited from class net.solarnetwork.node.io.modbus.support.ModbusDeviceSupport
DEFAULT_NETWORK_UID, DEFAULT_UNIT_ID, INFO_KEY_DEVICE_MANUFACTURE_DATE, logFields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TcreateSampleSnapshot(T sample) Create s snapshot copy of the sample data.protected TGet an up-to-date snapshot of the device data.protected TgetCurrentSample(ModbusConnection connection) Get an up-to-date snapshot of the device data.Get the Modbus data instance.longGet the sample cache maximum age, in milliseconds.protected booleanTest if the sample data has expired.static List<net.solarnetwork.settings.SettingSpecifier>modbusDeviceNetworkSettings(String prefix) Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.Read general device info and return a map of the results.protected voidreadDeviceInfoFirstTime(ModbusConnection connection, T sample) Read device information when first attempting to communicate with the device.protected abstract voidrefreshDeviceData(ModbusConnection connection, T sample) Refresh the device data.protected abstract voidrefreshDeviceInfo(ModbusConnection connection, T sample) Refresh the device info data.voidsetSampleCacheMs(long sampleCacheMs) Set the sample cache maximum age, in milliseconds.Methods inherited from class net.solarnetwork.node.io.modbus.support.ModbusDeviceSupport
getDeviceInfo, getDeviceInfoMap, getDeviceInfoMessage, getModbusNetwork, getUnitId, modbusDeviceName, modbusNetwork, modbusNetworkSettings, performAction, setDeviceInfoMap, setModbusNetwork, setUnitIdMethods 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_SAMPLE_CACHE_MS
public static final long DEFAULT_SAMPLE_CACHE_MSThe default value for thesampleCacheMsproperty.- See Also:
-
-
Constructor Details
-
ModbusDataDeviceSupport
Constructor.- Parameters:
data- the data
-
-
Method Details
-
modbusDeviceNetworkSettings
public static List<net.solarnetwork.settings.SettingSpecifier> modbusDeviceNetworkSettings(String prefix) Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.- Parameters:
prefix- a setting prefix to prepend- Returns:
- list of setting specifiers
- Since:
- 1.2
-
getCurrentSample
Get an up-to-date snapshot of the device data.If the sample data has expired, or never been read, this method will refresh it from the device by calling
refreshDeviceData(ModbusConnection, ModbusData). If the data has never been read, it will also first callrefreshDeviceInfo(ModbusConnection, ModbusData). A copy of the sample data is returned viacreateSampleSnapshot(ModbusData).- Returns:
- the sample data copy
- Throws:
IOException- if a communication error occurs
-
getCurrentSample
Get an up-to-date snapshot of the device data.If the sample data has expired, or never been read, this method will refresh it from the device by calling
refreshDeviceData(ModbusConnection, ModbusData). If the data has never been read, it will also first callrefreshDeviceInfo(ModbusConnection, ModbusData). A copy of the sample data is returned viacreateSampleSnapshot(ModbusData).- Parameters:
connection- an optional existing connection to use; otherwise a new connection will be acquired- Returns:
- the sample data copy
- Throws:
IOException- if a communication error occurs
-
readDeviceInfoFirstTime
Read device information when first attempting to communicate with the device.This method will be called only once by
getCurrentSample(), before callingrefreshDeviceData(ModbusConnection, ModbusData). This implementation simply callsrefreshDeviceInfo(ModbusConnection, ModbusData).- Parameters:
connection- the Modbus connectionsample- the sample to refresh- Throws:
IOException- if any communication error occurs
-
refreshDeviceInfo
Refresh the device info data.This should refresh the Modbus registers that contain device information such as the serial number, name, etc.
- Parameters:
connection- the Modbus connectionsample- the sample to refresh- Throws:
IOException- if any communication error occurs
-
refreshDeviceData
Refresh the device data.This should refresh the Modbus registers that contain the actual information being captured by this class and stored in datum instances. The
getCurrentSample()method calls this when the sample data is expired.- Parameters:
connection- the Modbus connectionsample- the sample to refresh- Throws:
IOException- if any communication error occurs
-
createSampleSnapshot
Create s snapshot copy of the sample data.This implementation calls
ModbusData.copy()and casts the result toT.- Parameters:
sample- the sample to copy- Returns:
- the copy of the sample data
-
isCachedSampleExpired
protected boolean isCachedSampleExpired()Test if the sample data has expired.- Returns:
- true if the sample data has expired
-
readDeviceInfo
Description copied from class:ModbusDeviceSupportRead 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.- Specified by:
readDeviceInfoin classModbusDeviceSupport- Parameters:
conn- the connection to use- Returns:
- a map with general device information populated
-
getSample
Get the Modbus data instance.- Returns:
- the data
-
getSampleCacheMs
public long getSampleCacheMs()Get the sample cache maximum age, in milliseconds.- Returns:
- the cache milliseconds
-
setSampleCacheMs
public void setSampleCacheMs(long sampleCacheMs) Set the sample cache maximum age, in milliseconds.- Parameters:
sampleCacheMs- the cache milliseconds
-