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.smartmeter.internal.helper;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.io.transport.serial.SerialPort;
20 * @author Matthias Steigenberger - Initial contribution
24 public enum SerialParameter {
26 _8N1(SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE),
27 _7N1(SerialPort.DATABITS_7, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE),
28 _7O1(SerialPort.DATABITS_7, SerialPort.STOPBITS_1, SerialPort.PARITY_ODD),
29 _7E1(SerialPort.DATABITS_7, SerialPort.STOPBITS_1, SerialPort.PARITY_EVEN);
35 private SerialParameter(int databits, int stopbits, int parity) {
36 this.databits = databits;
37 this.stopbits = stopbits;
41 public int getDatabits() {
45 public int getStopbits() {
49 public int getParity() {
54 public String toString() {
55 return name().substring(1);
59 * Returns the enum constant for the serial parameter string.
60 * The parameters must be in format 'StartbitsParityStopbits'
64 * @return The found {@link SerialParameter} or {@link SerialParameter#_8N1} if not found
66 public static SerialParameter fromString(String params) {
68 return valueOf("_" + params.toUpperCase());
69 } catch (IllegalArgumentException e) {
70 return SerialParameter._8N1;