Class ModbusDataDatumDataSourceSupport<T extends ModbusData & net.solarnetwork.node.domain.DataAccessor>

java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.service.support.DatumDataSourceSupport
net.solarnetwork.node.io.modbus.support.ModbusDeviceDatumDataSourceSupport
net.solarnetwork.node.io.modbus.support.ModbusDataDatumDataSourceSupport<T>
All Implemented Interfaces:
net.solarnetwork.service.Identifiable

public abstract class ModbusDataDatumDataSourceSupport<T extends ModbusData & net.solarnetwork.node.domain.DataAccessor> extends ModbusDeviceDatumDataSourceSupport
A base helper class to support 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_ID

    Fields inherited from class net.solarnetwork.node.service.support.DatumDataSourceSupport

    DEFAULT_PUBLISH_DEVICE_INFO_METADATA, DEFAULT_SUBSAMPLE_START_DELAY, SUB_SAMPLE_PROPS

    Fields inherited from class net.solarnetwork.node.service.support.BaseIdentifiable

    log

    Fields inherited from interface net.solarnetwork.service.Identifiable

    GROUP_UID_PROPERTY, UID_PROPERTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected T
    Create s snapshot copy of the sample data.
    net.solarnetwork.domain.DeviceInfo
    Get the device info.
    protected T
    Get an up-to-date snapshot of the device data.
    protected T
    Get an up-to-date snapshot of the device data.
    Get the Modbus data instance.
    long
    Get the sample cache maximum age, in milliseconds.
    protected boolean
    Test if the sample data has expired.
    protected Map<String,Object>
    Read general device info and return a map of the results.
    protected void
    Read device information when first attempting to communicate with the device.
    protected abstract void
    refreshDeviceData(ModbusConnection connection, T sample)
    Refresh the device data.
    protected abstract void
    refreshDeviceInfo(ModbusConnection connection, T sample)
    Refresh the device info data.
    void
    setSampleCacheMs(long sampleCacheMs)
    Set the sample cache maximum age, in milliseconds.

    Methods 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, stopSubSampling

    Methods inherited from class net.solarnetwork.node.service.support.BaseIdentifiable

    baseIdentifiableSettings, baseIdentifiableSettings, getExpressionServices, getPlaceholderService, populateExpressionDatumProperties, resolvePlaceholders, resolvePlaceholders, setExpressionServices, setPlaceholderService

    Methods 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, smartMetadataValue

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.solarnetwork.service.Identifiable

    getDisplayName, getGroupUid, getUid
  • Constructor Details

    • ModbusDataDatumDataSourceSupport

      public ModbusDataDatumDataSourceSupport(T data)
      Constructor.
      Parameters:
      data - the data
  • Method Details

    • getCurrentSample

      protected T getCurrentSample() throws IOException
      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 call refreshDeviceInfo(ModbusConnection, ModbusData). A copy of the sample data is returned via createSampleSnapshot(ModbusData).

      Returns:
      the sample data copy
      Throws:
      IOException - if a communication error occurs
    • getCurrentSample

      protected T getCurrentSample(ModbusConnection connection) throws IOException
      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 call refreshDeviceInfo(ModbusConnection, ModbusData). A copy of the sample data is returned via createSampleSnapshot(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

      protected void readDeviceInfoFirstTime(ModbusConnection connection, T sample) throws IOException
      Read device information when first attempting to communicate with the device.

      This method will be called only once by getCurrentSample(), before calling refreshDeviceData(ModbusConnection, ModbusData). This implementation simply calls refreshDeviceInfo(ModbusConnection, ModbusData).

      Parameters:
      connection - the Modbus connection
      sample - the sample to refresh
      Throws:
      IOException - if any communication error occurs
    • deviceInfo

      public net.solarnetwork.domain.DeviceInfo deviceInfo()
      Get the device info.
      Overrides:
      deviceInfo in class ModbusDeviceDatumDataSourceSupport
      Returns:
      the info
      Since:
      1.5
    • refreshDeviceInfo

      protected abstract void refreshDeviceInfo(ModbusConnection connection, T sample) throws IOException
      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 connection
      sample - the sample to refresh
      Throws:
      IOException - if any communication error occurs
    • refreshDeviceData

      protected abstract void refreshDeviceData(ModbusConnection connection, T sample) throws IOException
      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 connection
      sample - the sample to refresh
      Throws:
      IOException - if any communication error occurs
    • createSampleSnapshot

      protected T createSampleSnapshot(T sample)
      Create s snapshot copy of the sample data.

      This implementation calls ModbusData.copy() and casts the result to T.

      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

      protected Map<String,Object> readDeviceInfo(ModbusConnection conn) throws IOException
      Description copied from class: ModbusDeviceDatumDataSourceSupport
      Read 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:
      readDeviceInfo in class ModbusDeviceDatumDataSourceSupport
      Parameters:
      conn - the connection to use
      Returns:
      a map with general device information populated
      Throws:
      IOException - if any communication error occurs
    • getSample

      public T 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