Search in sources :

Example 6 with DataSet

use of org.openmuc.openiec61850.DataSet in project openhab1-addons by openhab.

the class Meter method read.

/**
     * Reads data from meter
     * 
     * @return a map of DataSet objects with the obis as key.
     */
public Map<String, DataSet> read() {
    // the frequently executed code (polling) goes here ...
    Map<String, DataSet> dataSetMap = new HashMap<String, DataSet>();
    Connection connection = new Connection(config.getSerialPort(), config.getInitMessage(), config.getEchoHandling(), config.getBaudRateChangeDelay());
    try {
        try {
            connection.open();
        } catch (IOException e) {
            logger.error("Failed to open serial port {}: {}", config.getSerialPort(), e.getMessage());
            return dataSetMap;
        }
        List<DataSet> dataSets = null;
        try {
            dataSets = connection.read();
            for (DataSet dataSet : dataSets) {
                logger.debug("DataSet: {};{};{}", dataSet.getId(), dataSet.getValue(), dataSet.getUnit());
                dataSetMap.put(dataSet.getId(), dataSet);
            }
        } catch (IOException e) {
            logger.error("IOException while trying to read: {}", e.getMessage());
        } catch (TimeoutException e) {
            logger.error("Read attempt timed out");
        }
    } finally {
        connection.close();
    }
    return dataSetMap;
}
Also used : HashMap(java.util.HashMap) DataSet(org.openmuc.j62056.DataSet) Connection(org.openmuc.j62056.Connection) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

DateTime (org.joda.time.DateTime)4 FcModelNode (org.openmuc.openiec61850.FcModelNode)4 IOException (java.io.IOException)3 DataSet (org.openmuc.openiec61850.DataSet)3 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 Iec61850BdaOptFldsHelper (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850BdaOptFldsHelper)2 HashMap (java.util.HashMap)2 DataSet (org.openmuc.j62056.DataSet)2 BdaReasonForInclusion (org.openmuc.openiec61850.BdaReasonForInclusion)2 ReadOnlyNodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.ReadOnlyNodeContainer)1 GetDataResponseDto (com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto)1 GetDataSystemIdentifierDto (com.alliander.osgp.dto.valueobjects.microgrids.GetDataSystemIdentifierDto)1 MeasurementDto (com.alliander.osgp.dto.valueobjects.microgrids.MeasurementDto)1 ReportDto (com.alliander.osgp.dto.valueobjects.microgrids.ReportDto)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1 Iec6205621MeterBindingProvider (org.openhab.binding.iec6205621meter.Iec6205621MeterBindingProvider)1 DecimalType (org.openhab.core.library.types.DecimalType)1