My setup is with a Raspberry Pi 3 running a NodeJS script through Modbus RTU.
For example, i want to read the active energy (address 1280 (dec) for Lo and 1281 (dec) for Hi). The data is big endian, so the Hi should be the MSB and the Lo the LSB, so im applying the following:
active energy = (data[hi]65536 + data[lo]) * multiplyingFactor
The total rate power is in the following range: 100kW or more and less than 1000kW, so the multiplying factor should be 1. Nevertheless im getting crazy numbers.
Assuming the line in your script is the same as the line in your post, it
looks like you’re missing the multiplication symbol between data[hi] and 65536.
IOW, shouldn’t it read ((data[hi] * 65536) + data[lo]) * multiplyingFactor?
Those registers are words, not bytes? If they are bytes, the multiplier should be 256.
And if signed, don’t forget the sign bit. The p-code for that (bytes - change the numbers for words):
p-code for extracting signed integer
x= ([low byte] + ( [high byte] * 2^8) )
if x > (2^15)
x = (x - (2^16))
return x
Bill, first of all thanks for the fast replies! I found this community searching for some information regarding the PZEM016 smart meter, and actually one of your posts solved my issues back then! Thanks for that!.
No, there is no strong reason for not using register 1304, but wanted to understand how to interpret correctly the number stored in adresses 1280 and 1281. Anyway ill try going directly for adress 1304.
How did you figured out that there where words and not bytes in each address? im a begginer in this, any books or learning material for this you can share?