correct math for energy metering - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: correct math for energy metering (/showthread.php?tid=2126) |
correct math for energy metering - AlexLV - 24.06.2019 Hi, how correctly make math for my power meter device's data: I receive 2 byte sighned integer 2083 kWh. But real is 208.3kWh. If I use value myltiplayer for modbus mapper I have only integer part - 208 kWh. If I just divide 2083 /10 anyway I have only 208. So how correctly convert value to floating point to have integer and 2 digits after point for more accurate power metering data?? BR, Alex RE: correct math for energy metering - admin - 25.06.2019 Set bus_datatype to float32, value_multiplier to 0.1. Then make sure that your object also has 4 byte floating point data type. RE: correct math for energy metering - AlexLV - 25.06.2019 Hi Admin, unfortunatelly such way not working for me : In attachment pictures with different datatypes I used with modbus LM reader... As I think my device - Gavazzi PM 340 gives out int32 format - as example 2341 (this is L1 phase voltage, real should be 234.1V). If I use float32 type I see something wrong... But from documentation - I see smething not correct, in real received data should be divided by 10 not multiplied.. 300001 0000h 2 V L1-N INT32 Value weight: Volt*10 What you can recommend? Alex
3-phase Modbus serial protocol EM and ET-rev.2.11.pdf (Size: 164.62 KB / Downloads: 16)
RE: correct math for energy metering - Daniel - 25.06.2019 Set datatype to int32 RE: correct math for energy metering - AlexLV - 25.06.2019 Daniel, big thanks, I did so. But I receive only integer part of whole meaning. But customer wants see also data after point - I need as example have 243.1. But I don't know how correctly rearrange received 2341 int32 type to 234.1 (float32??). If I just divide 2341 /10 I have only integer part = 234 (customer wants see 234.1 ) In simple math foolish question, but not so easy with datatype formats for me Alex RE: correct math for energy metering - Daniel - 25.06.2019 datatype and bus_datatype are two different things. Set datatype to int32 and bus_datatype to float32. First one is modbus dpt and second KNX RE: correct math for energy metering - AlexLV - 25.06.2019 Daniel, so bus datatype should be : 13. 4 byte signed integer = int32 ?? Alex RE: correct math for energy metering - Daniel - 25.06.2019 No "datatype": "int32", "bus_datatype": 14, http://openrb.com/docs/modbus.htm RE: correct math for energy metering - AlexLV - 25.06.2019 AAA my brains Anyway I am wrong somewhere.. part of my .json file: { "product_code": "Gavazzi EM-340", "mapping": [ { "bus_datatype": 14, "address": 0, "type": "register", "units": "V", "value_multiplier": 0.1, "name": "Voltage L1-N", "datatype": "int32" }, { "bus_datatype": 14, "address": 2, "type": "register", "units": "V", "value_multiplier": 0.1, "name": "Voltage L2-N", "datatype": "int32" }, { "bus_datatype": 14, "address": 4, "type": "register", "units": "V", "value_multiplier": 0.1, "name": "Voltage L3-N", "datatype": "int32" }, { "bus_datatype": 14, "address": 6, "type": "register", "units": "V", "value_multiplier": 0.1, "name": "Voltage L1-L2", "datatype": "int32" }, but at modbus mapper again formats not correct.. Maybe because from register 0 I need read 2 words by length?? Alex RE: correct math for energy metering - Daniel - 25.06.2019 This is already happening. Do you have any errors? RE: correct math for energy metering - AlexLV - 25.06.2019 No, no any errors. I think it could be modbus speed, but I use middle - 38.4 and now only one device. So may be just try to do changes mathematically? By the way, what is last modbus lua library? I using this: genohm-scada-modbus 20180822 RE: correct math for energy metering - admin - 26.06.2019 You need to set correct read_swap field value. Use RTU read test to find correct swap value when reading registers using int32 data type. RE: correct math for energy metering - AlexLV - 26.06.2019 Admin, thanks, but how correctly to add read_swap to .json: Is it right way: "read_swap": "0xCDAB", And where in between I should insert additional arguments?? BR, Alex RE: correct math for energy metering - admin - 26.06.2019 0xCDAB is swap w which is the default, you probably need swap type n. Here you have read correct value via read test: Code: { RE: correct math for energy metering - AlexLV - 26.06.2019 Thanks, will check today later. Alex |