use of org.openmuc.jmbus.DataRecord in project OpenMUC by isc-konstanz.
the class DriverConnection method read.
@Override
public Object read(List<ChannelRecordContainer> containers, Object containerListHandle, String samplingGroup) throws ConnectionException {
synchronized (connectionInterface) {
List<DataRecord> dataRecords = new ArrayList<>();
if (!connectionInterface.isOpen()) {
throw new ConnectionException("Connection " + connectionInterface.getInterfaceAddress() + " is closed.");
}
MBusConnection mBusConnection = connectionInterface.getMBusConnection();
if (secondaryAddress != null) {
try {
mBusConnection.selectComponent(secondaryAddress);
sleep(delay);
} catch (IOException e) {
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_UNSPECIFIED));
}
connectionInterface.close();
logger.error(e.getMessage());
throw new ConnectionException(e);
}
}
try {
if (secondaryAddress == null) {
if (resetLink) {
mBusConnection.linkReset(mBusAddress);
sleep(delay);
}
if (resetApplication) {
mBusConnection.resetReadout(mBusAddress);
sleep(delay);
}
}
VariableDataStructure variableDataStructure = null;
do {
variableDataStructure = mBusConnection.read(mBusAddress);
sleep(delay);
dataRecords.addAll(variableDataStructure.getDataRecords());
} while (variableDataStructure.moreRecordsFollow());
} catch (IOException e) {
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_UNSPECIFIED));
}
connectionInterface.close();
logger.error(e.getMessage());
throw new ConnectionException(e);
}
long timestamp = System.currentTimeMillis();
String[] dibvibs = new String[dataRecords.size()];
setDibVibs(dataRecords, dibvibs);
boolean selectForReadoutSet = setRecords(containers, mBusConnection, timestamp, dataRecords, dibvibs);
if (selectForReadoutSet) {
try {
mBusConnection.resetReadout(mBusAddress);
sleep(delay);
} catch (IOException e) {
try {
mBusConnection.linkReset(mBusAddress);
sleep(delay);
} catch (IOException e1) {
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.CONNECTION_EXCEPTION));
}
connectionInterface.close();
logger.error("{}\n{}", e.getMessage(), e1.getMessage());
throw new ConnectionException(e);
}
}
}
return null;
}
}
Aggregations