Dear Bernd,
I digged into the challenge of converting the Float64 values. And I think I actually succeeded. I can only not try it out practically yet as I miss a car to charge.
May you like to try the following code for converting the Float64 values? You have to read the registers as single int16 and provide the number to int1 … int4.
// https://babbage.cs.qc.cuny.edu/ieee-754.old/64bit.html
// https://babbage.cs.qc.cuny.edu/IEEE-754/
// https://en.wikipedia.org/wiki/Double-precision_floating-point_format
// https://de.wikipedia.org/wiki/IEEE_754
// https://community.openhab.org/t/serial-port-and-pulse-counter-byte-array-little-endian-to-double-precision/24782/15
// Wallbox neu // Ergebnis 112.34 // Ergebnis -1512.78 // Ergebnis 0
var int1 = WB_Energie_Geliefert_Gesamt_1.state as Number // 16422 // 16476 (405C) // 49303 (C097) // 0
var int2 = WB_Energie_Geliefert_Gesamt_2.state as Number // 0 // 5570 (15C2) // 41758 (A31E) // 0
var int3 = WB_Energie_Geliefert_Gesamt_3.state as Number // 0 // 36700 (8F5C) // 47185 (B851) // 0
var int4 = WB_Energie_Geliefert_Gesamt_4.state as Number // 0 // 10486 (28F6) // 60293 (EB85) // 0
var int1_hex = Integer::toHexString(int1.intValue)
var int2_hex = Integer::toHexString(int2.intValue)
var int3_hex = Integer::toHexString(int3.intValue)
var int4_hex = Integer::toHexString(int4.intValue)
while (int1_hex.length < 4) int1_hex = int1_hex + "0"
while (int2_hex.length < 4) int2_hex = int2_hex + "0"
while (int3_hex.length < 4) int3_hex = int3_hex + "0"
while (int4_hex.length < 4) int4_hex = int4_hex + "0"
var hex_komplett = String::format(int1_hex + int2_hex + int3_hex + int4_hex)
logInfo("Float64 konvertieren", "Hex-String: " + hex_komplett)
var hex_vorzexp = hex_komplett.substring(0, 3)
var hex_sig = hex_komplett.substring(3, hex_komplett.length)
logInfo("Float64 konvertieren", "Geteilter Hex-String: Erste 3 Zeichen (Vorzeichen + Exponent): " + hex_vorzexp + ", Rest (Signifikant): " + hex_sig)
var dec_vorzexp = new DecimalType(Integer.parseInt(hex_vorzexp, 16))
var dec_sig = new DecimalType(Long.valueOf(hex_sig, 16).longValue())
logInfo("Float64 konvertieren", "Vorzeichen + Exponent als Dezimalwert: " + dec_vorzexp + ", Signifikant (roh-Wert): " + dec_sig)
var bin_vorzexp = Integer::toBinaryString(dec_vorzexp.intValue)
logInfo("Float64 konvertieren", "Vorzeichen + Exponent als Binärwert: " + bin_vorzexp)
var vorz = 0
var double dec_exp = 0
if (bin_vorzexp.substring(0, 1) == "1" && bin_vorzexp.length == 12) {
vorz = -1
dec_exp = (dec_vorzexp - Math.pow(2, bin_vorzexp.length - 1)).doubleValue
}
else {
vorz = 1
dec_exp = (dec_vorzexp).doubleValue
}
logInfo("Float64 konvertieren", "Vorzeichen: " + vorz + ", Exponent (roh-Wert): " + dec_exp)
var sig = (1 + (dec_sig / Math.pow(2,52)))
logInfo("Float64 konvertieren", "Signifikant: " + sig)
var double exp = dec_exp - 1023
logInfo("Float64 konvertieren", "Exponent: " + exp)
var ergebnis = vorz * sig * Math.pow(2, exp)
logInfo("Float64 konvertieren", "Wert: " + ergebnis)
logInfo("Float64 konvertieren", "Wert (formatiert): " + String::format("%1$.3f", ergebnis))
ergebnis = ergebnis / 1000
WB_Energie_Geliefert_Gesamt.postUpdate(ergebnis)