LogicMachine Forum
w4k fails reading modbus rtu float32 - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: w4k fails reading modbus rtu float32 (/showthread.php?tid=6390)



w4k fails reading modbus rtu float32 - cgn - 15.04.2026

I've a eastron sdm72d modbus meter and I use the following lua code: 
Code:
require('luamodbus') mb = luamodbus.rtu() mb:open('/dev/RS485', 9600, 'N', 8, 1, 'H')   -- SDM72 nutzt 8N1 mb:setslave(20) mb:connect() local r1, r2 = mb:readinputregisters(70, 2) local value = mb:readregistervalue(70, "float32") log(r1, r2, value) mb:close()

I get the following result:
Code:
* arg: 1   * number: 16967 * arg: 2   * number: 57672 * arg: 3   * number: 0

So in general the code seems to work. Why do I get a 0 for value? 
The modbus register can be found here: https://data.xn--stromzhler-v5a.eu/manuals/eastron_sdm72dmv2.pdf


RE: w4k fails reading modbus rtu float32 - admin - 15.04.2026

Use mb:readinputregistervalue(). It's highly recommended to use profiles instead of scripts.


RE: w4k fails reading modbus rtu float32 - cgn - 16.04.2026

Using a profile was my first try, but it didn't work. So I tried so solve it with this script. 

Code:
{   "manufacturer": "Eastron",   "description": "3-phasiger Energiezähler SDM72D-M",   "mapping": [     {       "name": "Frequency",       "address": 70,       "type": "inputregister",       "bus_datatype": "float32",       "unit": "Hz"     }   ] }

With this profile I get the value 16967.000. Which is wrong, it should be around 50. 

readinputregistervalue() - seems to be the problem. 
Code:
require('luamodbus') mb = luamodbus.rtu() mb:open('/dev/RS485', 9600, 'N', 8, 1, 'H') mb:setslave(20) mb:connect() local r1 = mb:readregistervalue(70,"float16") local r2 = mb:readregistervalue(71,"float16") local value = mb:readregistervalue(70, "float32") log(r1, r2, value) mb:close()

log:
Code:
* arg: 1   * number: 0 * arg: 2   * number: 0 * arg: 3   * number: 0



RE: w4k fails reading modbus rtu float32 - admin - 16.04.2026

Your profile is missing "datatype": "float32"


RE: w4k fails reading modbus rtu float32 - cgn - 16.04.2026

Thank you verry much. Now I can use the profile.