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;
}
Aggregations