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!");
}
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();
}
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();
}
}
Aggregations