I've tried to use this modbus TCP slave script and it works perfectly but only when other LM which is master reads by a script it doesn't work via mapper.
The minimum version of profile which I've tested:
This is the first part of slave script from LM4:
This is currently used master script (it is working very nice, i let only 1 address):
So currently I am working with above script but I want switch it to the mapper. But in above mapper settings it's not working e.g. when I change value on slave it isn't changed by new read on master. Maybe some advice from some experienced Modbus TCP user?
P.S. No, two scripts don't working in same time
The minimum version of profile which I've tested:
Code:
{
"manufacturer": "PEGO",
"description": "LM4",
"mapping": [
{ "bus_address": "32/2/0", "name": "Room humidity", "bus_datatype": "uint16", "type": "register", "datatype": "uint16", "address": 0, "units": "%" }
]
}
This is the first part of slave script from LM4:
Code:
if not mb then
require('genohm-scada.eibdgm')
require('luamodbus')
-- list of coil mapping, starting from 0
coils = { }
-- list of register mapping, starting from 0
registers = { '32/2/0' }
-- list of register data types, element count must match registers table
regdt = { dt.uint16 }
This is currently used master script (it is working very nice, i let only 1 address):
Code:
require('json')
require('luamodbus')
mb = luamodbus.tcp()
mb:open('192.168.2.17')
mb:connect()
-- verbose output and select slave number 1
mb:setdebug(true)
mb:setslave(1)
pego_1_profile_json = [[{
"manufacturer": "PEGO",
"description": "PEGO_Goscinna",
"mapping": [
{ "bus_address": "32/2/0", "name": "Room humidity", "bus_datatype": "uint16", "type": "register", "datatype": "uint16", "address": 0, "units": "%" }
]}]]
function readAndUpdatePEGOGAs(pego_profiles)
for i, profile in ipairs(pego_profiles) do
pego_profile = json.decode(profile)
for k,v in ipairs(pego_profile.mapping) do
value, err = mb:readregistervalue(v.address, v.datatype, 'n')
if v.value_multiplier == 0.1 then delta = 0.1 else delta = 1 end
grp.checkwrite(v.bus_address, value, delta)
end
end
end
pego_profiles = {pego_1_profile_json}
readAndUpdatePEGOGAs(pego_profiles)
-- close serial connection
mb:close()
-- wait 5 seconds before next read
os.sleep(5)
So currently I am working with above script but I want switch it to the mapper. But in above mapper settings it's not working e.g. when I change value on slave it isn't changed by new read on master. Maybe some advice from some experienced Modbus TCP user?
P.S. No, two scripts don't working in same time
Done is better than perfect