2 * Copyright (c) 2010-2022 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.core.io.transport.serial.SerialPortManager;
21 * Implementation of a DSMRDevice with fixed serial port settings. With fixed port settings the code is much simpler
22 * because no detecting of settings needs to be done and when things fail no redirecting is needed either.
24 * @author Hilbrand Bouwkamp - Initial contribution
27 public class DSMRFixedConfigDevice implements DSMRDevice {
29 private final DSMRSerialConnector dsmrPort;
30 private final DSMRSerialSettings fixedPortSettings;
31 private final DSMRTelegramListener telegramListener;
36 * @param serialPortManager the manager to get a new serial port connecting from
37 * @param serialPortName the port name (e.g. /dev/ttyUSB0 or COM1)
38 * @param fixedPortSettings The serial port connection settings
39 * @param listener the parent {@link DSMREventListener}
40 * @param telegramListener listener to report found telegrams or errors
42 public DSMRFixedConfigDevice(SerialPortManager serialPortManager, String serialPortName,
43 DSMRSerialSettings fixedPortSettings, DSMREventListener listener, DSMRTelegramListener telegramListener) {
44 this.fixedPortSettings = fixedPortSettings;
45 this.telegramListener = telegramListener;
46 telegramListener.setDsmrEventListener(listener);
48 dsmrPort = new DSMRSerialConnector(serialPortManager, serialPortName, telegramListener);
53 dsmrPort.open(fixedPortSettings);
57 public void restart() {
58 dsmrPort.restart(fixedPortSettings);
67 public void setLenientMode(boolean lenientMode) {
68 telegramListener.setLenientMode(lenientMode);