use of org.openmuc.j62056.DataMessage in project OpenMUC by isc-konstanz.
the class Iec62056Connection method read.
private List<DataSet> read(List<ChannelRecordContainer> containers) {
List<DataSet> dataSetsRet = new ArrayList<>();
DataMessage dataMessage;
for (int i = 0; i <= retries; ++i) {
try {
dataMessage = iec21Port.read();
List<DataSet> dataSets = dataMessage.getDataSets();
if (dataSetsRet != null) {
i = retries;
dataSetsRet = dataSets;
}
} catch (IOException e) {
if (i >= retries) {
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_READ_FAILURE));
}
}
}
}
return dataSetsRet;
}
use of org.openmuc.j62056.DataMessage in project openhab-addons by openhab.
the class Iec62056_21SerialConnector method readNext.
@Override
protected DataMessage readNext(byte @Nullable [] initMessage) throws IOException {
if (iec21Port != null) {
DataMessage dataMessage = iec21Port.read();
logger.debug("Datamessage read: {}", dataMessage);
return dataMessage;
}
throw new IOException("SerialPort was not yet created!");
}
use of org.openmuc.j62056.DataMessage in project OpenMUC by isc-konstanz.
the class Iec62056Connection method scanForChannels.
@Override
public List<ChannelScanInfo> scanForChannels(String settings) throws UnsupportedOperationException, ScanException, ConnectionException {
List<DataSet> dataSets;
DataMessage dataMessage;
try {
dataMessage = iec21Port.read();
} catch (IOException e) {
throw new ScanException(e);
}
dataSets = dataMessage.getDataSets();
if (dataSets == null) {
throw new ScanException("Read timeout.");
}
List<ChannelScanInfo> scanInfos = new ArrayList<>(dataSets.size());
for (DataSet dataSet : dataSets) {
try {
Double.parseDouble(dataSet.getValue());
scanInfos.add(new ChannelScanInfo(dataSet.getAddress(), "", ValueType.DOUBLE, null));
} catch (NumberFormatException e) {
scanInfos.add(new ChannelScanInfo(dataSet.getAddress(), "", ValueType.STRING, dataSet.getValue().length()));
}
}
return scanInfos;
}
use of org.openmuc.j62056.DataMessage in project OpenMUC by isc-konstanz.
the class Iec62056Driver method scanForDevices.
@Override
public void scanForDevices(String settings, DriverDeviceScanListener listener) throws UnsupportedOperationException, ArgumentSyntaxException, ScanException, ScanInterruptedException {
handleScanParameter(settings);
Iec21Port iec21Port = null;
Builder iec21PortBuilder = getConfiguredBuilder();
try {
iec21Port = iec21PortBuilder.buildAndOpen();
} catch (IOException e) {
throw new ScanException("Failed to open serial port: " + e.getMessage());
}
try {
DataMessage dataMessage = iec21Port.read();
List<DataSet> dataSets = dataMessage.getDataSets();
StringBuilder deviceSettings = new StringBuilder();
if (baudRateChangeDelay > 0) {
deviceSettings.append(' ').append(BAUD_RATE_CHANGE_DELAY).append(' ').append(baudRateChangeDelay);
}
String deviceSettingsString = deviceSettings.toString().trim();
listener.deviceFound(new DeviceScanInfo(serialPortName, deviceSettingsString, dataSets.get(0).getAddress().replaceAll("\\p{Cntrl}", "")));
} catch (IOException e) {
throw new ScanException(e);
} finally {
iec21Port.close();
}
}
Aggregations