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.apache.commons.lang3.StringUtils;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.openhab.core.io.transport.serial.SerialPort;
21 * @author Matthias Steigenberger - Initial contribution
25 public enum SerialParameter {
27 _8N1(SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE),
28 _7N1(SerialPort.DATABITS_7, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE),
29 _7O1(SerialPort.DATABITS_7, SerialPort.STOPBITS_1, SerialPort.PARITY_ODD),
30 _7E1(SerialPort.DATABITS_7, SerialPort.STOPBITS_1, SerialPort.PARITY_EVEN);
36 private SerialParameter(int databits, int stopbits, int parity) {
37 this.databits = databits;
38 this.stopbits = stopbits;
42 public int getDatabits() {
46 public int getStopbits() {
50 public int getParity() {
55 public String toString() {
56 return name().substring(1);
60 * Returns the enum constant for the serial parameter string.
61 * The parameters must be in format 'StartbitsParityStopbits'
65 * @return The found {@link SerialParameter} or {@link SerialParameter#_8N1} if not found
67 public static SerialParameter fromString(String params) {
69 return valueOf("_" + StringUtils.upperCase(params));
70 } catch (IllegalArgumentException e) {
71 return SerialParameter._8N1;