Help with RS485 Power Meter HEX to Number conversion

Hiking DDS238-2 ZN/S energy meter

Modbus holding registers:

|000Ch |voltage         |1/10 V  |unsigned word |R|
|000Dh |current         |1/100 A |unsigned word |R|
|000Eh |active power    |1 W     |signed word   |R|
|000Fh |reactive power  |1 VAr   |unsigned word |R|
|0010h |power factor    |1/1000  |unsigned word |R|
|0011h |frequency       |1/100 Hz|unsigned word |R|

Here is readings array beginning from 000Ch, 6 registers :

02  03  0c  08  d9  00  0f  ff  fa  ff  de  00  aa  13  89
 0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  
//This 4 Items work OK
sysSens_PowMeterVoltage.postUpdate(Short.parseShort(bytes2.get(3) + bytes2.get(4),  16) as Number / 10)
sysSens_PowMeterCurrent.postUpdate(Short.parseShort(bytes2.get(5) + bytes2.get(6),  16) as Number / 100)
sysSens_PowMeterPFactor.postUpdate(Short.parseShort(bytes2.get(11) + bytes2.get(12), 16) as Number / 1000)
sysSens_PowMeterFreq.postUpdate   (Short.parseShort(bytes2.get(13) + bytes2.get(14), 16) as Number / 100)

//This line DON'T work because of "fffa" =  65530
sysSens_PowMeterPowerLoad.postUpdate(Short.parseShort(bytes2.get(7) + bytes2.get(8),  16) as Number )

How to get “6.2” from “FFFA” (signed word)?

Have you considered using the Modbus binding?

I don’t know how to use this requests with Modbus binding

//Request data
//Get data

How have you connected to this thing? It has a serial interface, so there’s some box in between. Is that not giving you a gateway function?

Anyway, working wih bytes and hex in DSL rules is not at all easy. Your register 0E is in “two’s complement” signed form, where FFFA represents integer -6

This post looks helpful

var input = "FFFA"
var result = Integer.parseInt(input, 16).shortValue() as Number
logInfo("test", "parsed " + result)

logs -6, seems to work

Power meter connected via rs485<>uart adapter to HomeAutomation Ethernet controller.


Thank you, your example works fine.
I add Math.abs to example, to ignore negative values (why it negative?), because power meter shows 6.5w

While there’s no such thing as negative energy, electric meters can measure current flow in two directions - A to B or B to A.
Conventionally, you might represent A to B as positive current ad B to A as negative current. Swap the wires around, it’ll read the other way. So negative numbers are pretty routine in metering.

Of course you would then expect the power calculations to also reflect the same negative numbers, which they’re not really in your case. It’s hiding some negatives.
That’s a question for the meter manufacturer.