Logic Machine Forum
Modbus Float32 - 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: Modbus Float32 (/showthread.php?tid=3565)



Modbus Float32 - sjfp - 18.09.2021

Hi all need some with a float32 issue. 
When using Modbus profiles like: 
{
"product_code": "Socket Meter",
  "mapping": [
{"name": " Active Power", "bus_datatype": "float32", "datatype": "float32","units": "kWh", "type": "inputregister", "address": 52},
{"name": "Total System", "bus_datatype": "float32", "datatype": "float32","units": "kW", "type": "inputregister", "address": 72}],
  "manufacturer": "Eastron",
  "name": "1Phase Smart Meter",
  "product_range": "SDM-M",
  "description": "Modbus 3 Phase Meter Direct Connect"
}


Works fine and we get the correct values.

But we need to use modbus scripting rather than profiles, so using:

require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
res, err = mb:connect()
if res then
  mbConfusedetslave(1)
  value1 = mb:readregistervalue(52,"float32","n")  --Meter (n=no swap, w=word swap, b=byte swap, bw=byte and word swap)   
  value2 = mb:readregistervalue(72,"float32","n")
log('V1: ' .. value1 .. ' and V2: '..value2)
else
  log('Umm !!, connection failed : '.. err)
end
mb:close()


But not getting any figures (0 only), So I am assuming there must be a conversion problem with bus data type, I need to do as well.
Any suggestion's would be appreciated.


RE: Modbus Float32 - admin - 18.09.2021

Default swap is "w", try it instead of "n".


RE: Modbus Float32 - sjfp - 18.09.2021

(18.09.2021, 12:16)admin Wrote: Default swap is "w", try it instead of "n".

Unfortunately, changing n to w didn't sort the problem, any other suggestions.


RE: Modbus Float32 - sjfp - 20.09.2021

Hi admin
Have tried the Read Test using Input Register (#4) Address 52 Data Type Float32 Read Swap Word (CDAB) and all works as expected, but still cant get he script to correctly produce the correct value.

Do you have any other suggestions, or I have missed something in the script.


RE: Modbus Float32 - admin - 20.09.2021

In the script you are reading holding registers not input registers as in the profile. Use mb:readinputregistervalue()


RE: Modbus Float32 - sjfp - 20.09.2021

admin, magic, thank you. 
Completely missed that setting


RE: Modbus Float32 - Leo681 - 19.03.2022

Hello, i have and aditional problem,

I have working this and its ok:

grp.checkupdate('39/0/22',(mb:readregistervalue(23316,"int32","w")))

I want to add the value_delta and type like this:

grp.checkupdate('39/0/22',(mb:readregistervalue(23316,"int32","w","value_delta" 500))) 

but it doesnt work fine, no errors but dont filter the result.

Any idea?

Thanks in advance


RE: Modbus Float32 - admin - 21.03.2022

Use this:
Code:
value = mb:readregistervalue(23316, "int32", "w")
grp.checkupdate('39/0/22', value, 500)



RE: Modbus Float32 - Leo681 - 21.03.2022

(21.03.2022, 08:13)admin Wrote: Use this:
Code:
value = mb:readregistervalue(23316, "int32", "w")
grp.checkupdate('39/0/22', value, 500)

finally

grp.checkupdate('35/4/22', (mb:readregistervalue(23316,"int32","w")) * 0.01, 500) 


Great!!!!

Thanks admin