Class ModbusDataDatumDataSourceSupport<T extends ModbusData & net.solarnetwork.node.domain.DataAccessor>
- All Implemented Interfaces:
net.solarnetwork.service.Identifiable
ModbusNetwork based
DatumDataSource implementations using ModbusData as a model
object.- Since:
- 2.9
- Version:
- 2.0
- Author:
- matt
-
Field Summary
Fields inherited from class net.solarnetwork.node.io.modbus.support.ModbusDeviceDatumDataSourceSupport
DEFAULT_UNIT_IDFields inherited from class net.solarnetwork.node.service.support.DatumDataSourceSupport
DEFAULT_PUBLISH_DEVICE_INFO_METADATA, DEFAULT_SUBSAMPLE_START_DELAY, SUB_SAMPLE_PROPSFields inherited from class net.solarnetwork.node.service.support.BaseIdentifiable
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.net.solarnetwork.domain.DeviceInfoGet the device info.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.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.ModbusDeviceDatumDataSourceSupport
getDeviceInfo, getDeviceInfoMap, getDeviceInfoMessage, getModbusNetwork, getModbusNetworkSettingSpecifiers, getUnitId, modbusDeviceName, modbusNetwork, modbusNetworkSettingSpecifiers, performAction, setDeviceInfoMap, setModbusNetwork, setUnitIdMethods inherited from class net.solarnetwork.node.service.support.DatumDataSourceSupport
addSourceMetadata, applyDatumFilter, canPublishDeviceInfo, clearSourceMetadataCache, getDatumFilterService, getDatumMetadataService, getDatumQueue, getDatumService, getDeviceInfoMetadataSettingSpecifiers, getExpressionConfigs, getExpressionConfigsCount, getIdentifiableSettingSpecifiers, getSubSampleFrequency, getSubSampleSettingSpecifiers, getSubSampleStartDelay, getTaskScheduler, isPublishDeviceInfoMetadata, isSubSampling, offerDatumCapturedEvent, populateExpressionDatumProperties, populateExpressionDatumProperties, readSubSampleDatum, saveMetadata, setDatumFilterService, setDatumMetadataService, setDatumQueue, setDatumService, setExpressionConfigs, setExpressionConfigsCount, setPublishDeviceInfoMetadata, setSubSampleFrequency, setSubSampleStartDelay, setTaskScheduler, startSubSampling, stopSubSamplingMethods 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
-
Constructor Details
-
ModbusDataDatumDataSourceSupport
Constructor.- Parameters:
data- the data
-
-
Method Details
-
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
-
deviceInfo
public net.solarnetwork.domain.DeviceInfo deviceInfo()Get the device info.- Overrides:
deviceInfoin classModbusDeviceDatumDataSourceSupport- Returns:
- the info
- Since:
- 1.5
-
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:ModbusDeviceDatumDataSourceSupportRead general device info and return a map of the results.See the various
INFO_KEY_*constants for information on the values returned in the result map.- Specified by:
readDeviceInfoin classModbusDeviceDatumDataSourceSupport- Parameters:
conn- the connection to use- Returns:
- a map with general device information populated
- Throws:
IOException- if any communication error occurs
-
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
-