Class ModbusDeviceDatumDataSourceSupport

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
All Implemented Interfaces:
net.solarnetwork.service.Identifiable
Direct Known Subclasses:
ModbusDataDatumDataSourceSupport

public abstract class ModbusDeviceDatumDataSourceSupport extends net.solarnetwork.node.service.support.DatumDataSourceSupport
A base helper class to support ModbusNetwork based DatumDataSource implementations.
Version:
3.1
Author:
matt
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The unitId property default value.

    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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.solarnetwork.domain.DeviceInfo
    Get device info.
    Get the device info data as a Map.
    protected Map<String,Object>
    Get direct access to the device info data.
    Return an informational message composed of general device info.
    net.solarnetwork.service.OptionalService<ModbusNetwork>
    Get the configured ModbusNetwork.
    protected List<net.solarnetwork.settings.SettingSpecifier>
    Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.
    int
    Get the Modbus unit ID.
    Get the configured Modbus device name.
    protected final ModbusNetwork
    Get the ModbusNetwork from the configured modbusNetwork service, or null if not available or not configured.
    static List<net.solarnetwork.settings.SettingSpecifier>
    Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.
    protected final <T> T
    Perform some work with a Modbus ModbusConnection.
    protected abstract Map<String,Object>
    Read general device info and return a map of the results.
    protected void
    Set the device info data.
    void
    setModbusNetwork(net.solarnetwork.service.OptionalService<ModbusNetwork> modbusDevice)
    Set the ModbusNetwork to use.
    void
    setUnitId(int unitId)
    Set the Modbus unit ID.

    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
  • Field Details

    • DEFAULT_UNIT_ID

      public static final int DEFAULT_UNIT_ID
      The unitId property default value.
      See Also:
  • Constructor Details

    • ModbusDeviceDatumDataSourceSupport

      public ModbusDeviceDatumDataSourceSupport()
  • Method Details

    • getModbusNetworkSettingSpecifiers

      protected List<net.solarnetwork.settings.SettingSpecifier> getModbusNetworkSettingSpecifiers()
      Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.
      Returns:
      list of setting specifiers
      Since:
      1.1
    • modbusNetworkSettingSpecifiers

      public static List<net.solarnetwork.settings.SettingSpecifier> modbusNetworkSettingSpecifiers(String uid, int unitId)
      Get setting specifiers for the unitId and modbusNetwork.propertyFilters['uid'] properties.
      Parameters:
      uid - the Modbus Network UID property filter default value to use
      unitId - the unit ID default value to use
      Returns:
      list of setting specifiers
      Since:
      3.1
    • modbusNetwork

      protected final ModbusNetwork modbusNetwork()
      Get the ModbusNetwork from the configured modbusNetwork service, or null if not available or not configured.
      Returns:
      ModbusNetwork
    • readDeviceInfo

      protected abstract Map<String,Object> readDeviceInfo(ModbusConnection conn) throws IOException
      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.

      Parameters:
      conn - the connection to use
      Returns:
      a map with general device information populated
      Throws:
      IOException - if any communication error occurs
    • getDeviceInfoMessage

      public String getDeviceInfoMessage()
      Return an informational message composed of general device info.

      This method will call getDeviceInfo() and return a / (forward slash) delimited string of the resulting values, or null if that method returns null.

      Returns:
      info message
    • getDeviceInfo

      public Map<String,?> getDeviceInfo()
      Get the device info data as a Map.

      This method will call readDeviceInfo(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

      protected final <T> T performAction(ModbusConnectionAction<T> action) throws IOException
      Perform some work with a Modbus ModbusConnection.

      This method attempts to obtain a ModbusNetwork from the configured modbusNetwork service, calling ModbusNetwork.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

      protected Map<String,Object> getDeviceInfoMap()
      Get direct access to the device info data.
      Returns:
      the device info, or null
    • setDeviceInfoMap

      protected void setDeviceInfoMap(Map<String,Object> deviceInfo)
      Set the device info data.

      Setting the deviceInfo to null will force the next call to getDeviceInfo() to read from the device to populate this data, and setting this to anything else will force all subsequent calls to getDeviceInfo() to simply return that map.

      Parameters:
      deviceInfo - the device info map to set
    • deviceInfo

      public net.solarnetwork.domain.DeviceInfo deviceInfo()
      Get device info.
      Returns:
      the device info based on calling the getDeviceInfo() method
      Since:
      2.2
    • modbusDeviceName

      public String modbusDeviceName()
      Get the configured Modbus device name.
      Returns:
      the modbus device name
      Since:
      1.3
    • getModbusNetwork

      public net.solarnetwork.service.OptionalService<ModbusNetwork> getModbusNetwork()
      Get the configured ModbusNetwork.
      Returns:
      the modbus network
    • setModbusNetwork

      public void setModbusNetwork(net.solarnetwork.service.OptionalService<ModbusNetwork> modbusDevice)
      Set the ModbusNetwork to use.
      Parameters:
      modbusDevice - the modbus network
    • getUnitId

      public int getUnitId()
      Get the Modbus unit ID.
      Returns:
      the unit ID; defauts to DEFAULT_UNIT_ID
    • setUnitId

      public void setUnitId(int unitId)
      Set the Modbus unit ID.
      Parameters:
      unitId - the unit ID