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.modbus.e3dc.internal.dto;
15 import javax.measure.quantity.ElectricCurrent;
16 import javax.measure.quantity.ElectricPotential;
17 import javax.measure.quantity.Power;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.modbus.e3dc.internal.modbus.Data;
21 import org.openhab.core.io.transport.modbus.ValueBuffer;
22 import org.openhab.core.library.types.QuantityType;
23 import org.openhab.core.library.unit.Units;
26 * The {@link StringBlock} Data object for E3DC Info Block
28 * @author Bernd Weymann - Initial contribution
31 public class StringBlock implements Data {
32 public QuantityType<ElectricPotential> string1Volt;
33 public QuantityType<ElectricPotential> string2Volt;
34 public QuantityType<ElectricPotential> string3Volt;
35 public QuantityType<ElectricCurrent> string1Ampere;
36 public QuantityType<ElectricCurrent> string2Ampere;
37 public QuantityType<ElectricCurrent> string3Ampere;
38 public QuantityType<Power> string1Watt;
39 public QuantityType<Power> string2Watt;
40 public QuantityType<Power> string3Watt;
43 * For decoding see Modbus Register Mapping Chapter 3.1.2 page 14-16
45 * @param bArray - Modbus Registers as bytes from 40096 to 40104
47 public StringBlock(byte[] bArray) {
48 ValueBuffer wrap = ValueBuffer.wrap(bArray);
49 // straight forward - for each String the values Volt, Ampere and then Watt. All unt16 = 2 bytes values
50 string1Volt = QuantityType.valueOf(wrap.getUInt16(), Units.VOLT);
51 string2Volt = QuantityType.valueOf(wrap.getUInt16(), Units.VOLT);
52 string3Volt = QuantityType.valueOf(wrap.getUInt16(), Units.VOLT);
53 // E3DC Modbus Spec chapter 3.1.2, page 16 - Ampere values shall be handled with factor 0.01
54 string1Ampere = QuantityType.valueOf(DataConverter.getUDoubleValue(wrap, 0.01), Units.AMPERE);
55 string2Ampere = QuantityType.valueOf(DataConverter.getUDoubleValue(wrap, 0.01), Units.AMPERE);
56 string3Ampere = QuantityType.valueOf(DataConverter.getUDoubleValue(wrap, 0.01), Units.AMPERE);
57 string1Watt = QuantityType.valueOf(wrap.getUInt16(), Units.WATT);
58 string2Watt = QuantityType.valueOf(wrap.getUInt16(), Units.WATT);
59 string3Watt = QuantityType.valueOf(wrap.getUInt16(), Units.WATT);