Search in sources :

Example 1 with DataMessage

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;
}
Also used : ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) DataSet(org.openmuc.j62056.DataSet) DataMessage(org.openmuc.j62056.DataMessage) ArrayList(java.util.ArrayList) Record(org.openmuc.framework.data.Record) IOException(java.io.IOException)

Example 2 with DataMessage

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!");
}
Also used : DataMessage(org.openmuc.j62056.DataMessage) IOException(java.io.IOException)

Example 3 with DataMessage

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;
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ScanException(org.openmuc.framework.config.ScanException) DataSet(org.openmuc.j62056.DataSet) DataMessage(org.openmuc.j62056.DataMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 4 with DataMessage

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();
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) ScanException(org.openmuc.framework.config.ScanException) DataSet(org.openmuc.j62056.DataSet) DataMessage(org.openmuc.j62056.DataMessage) Builder(org.openmuc.j62056.Iec21Port.Builder) Iec21Port(org.openmuc.j62056.Iec21Port) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 DataMessage (org.openmuc.j62056.DataMessage)4 DataSet (org.openmuc.j62056.DataSet)3 ArrayList (java.util.ArrayList)2 ScanException (org.openmuc.framework.config.ScanException)2 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)1 DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)1 Record (org.openmuc.framework.data.Record)1 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)1 Iec21Port (org.openmuc.j62056.Iec21Port)1 Builder (org.openmuc.j62056.Iec21Port.Builder)1