Search in sources :

Example 1 with Iec21Port

use of org.openmuc.j62056.Iec21Port 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 2 with Iec21Port

use of org.openmuc.j62056.Iec21Port in project openhab-addons by openhab.

the class Iec62056_21SerialConnector method openConnection.

@Override
public void openConnection() throws IOException {
    Builder iec21Builder = new Iec21Port.Builder(getPortName());
    if (Baudrate.fromBaudrate(this.baudrate) != Baudrate.AUTO) {
        iec21Builder.setInitialBaudrate(this.baudrate);
    }
    iec21Builder.setBaudRateChangeDelay(baudrateChangeDelay);
    iec21Builder.enableVerboseMode(true);
    iec21Port = iec21Builder.buildAndOpen();
}
Also used : Builder(org.openmuc.j62056.Iec21Port.Builder)

Example 3 with Iec21Port

use of org.openmuc.j62056.Iec21Port 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)2 DataMessage (org.openmuc.j62056.DataMessage)2 Builder (org.openmuc.j62056.Iec21Port.Builder)2 DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)1 ScanException (org.openmuc.framework.config.ScanException)1 DataSet (org.openmuc.j62056.DataSet)1 Iec21Port (org.openmuc.j62056.Iec21Port)1