2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dsmr.internal.device;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.dsmr.internal.device.connector.DSMRSerialConnector;
17 import org.openhab.binding.dsmr.internal.device.connector.DSMRSerialSettings;
18 import org.openhab.binding.dsmr.internal.device.p1telegram.P1TelegramListener;
19 import org.openhab.core.io.transport.serial.SerialPortManager;
22 * Implementation of a DSMRDevice with fixed serial port settings. With fixed port settings the code is much simpler
23 * because no detecting of settings needs to be done and when things fail no redirecting is needed either.
25 * @author Hilbrand Bouwkamp - Initial contribution
28 public class DSMRFixedConfigDevice implements DSMRDevice {
30 private final DSMRSerialConnector dsmrPort;
31 private final DSMRSerialSettings fixedPortSettings;
32 private final DSMRTelegramListener telegramListener;
37 * @param serialPortManager the manager to get a new serial port connecting from
38 * @param serialPortName the port name (e.g. /dev/ttyUSB0 or COM1)
39 * @param fixedPortSettings The serial port connection settings
40 * @param listener the parent {@link P1TelegramListener}
41 * @param telegramListener listener to report found telegrams or errors
43 public DSMRFixedConfigDevice(final SerialPortManager serialPortManager, final String serialPortName,
44 final DSMRSerialSettings fixedPortSettings, final P1TelegramListener listener,
45 final DSMRTelegramListener telegramListener) {
46 this.fixedPortSettings = fixedPortSettings;
47 this.telegramListener = telegramListener;
48 telegramListener.setP1TelegramListener(listener);
50 dsmrPort = new DSMRSerialConnector(serialPortManager, serialPortName, telegramListener);
55 dsmrPort.open(fixedPortSettings);
59 public void restart() {
60 dsmrPort.restart(fixedPortSettings);
69 public void setLenientMode(final boolean lenientMode) {
70 telegramListener.setLenientMode(lenientMode);