This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

setup modbus tcp slave
#18
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:

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? Wink

P.S. No, two scripts don't working in same timeWink

Attached Files Thumbnail(s)
   
Done is better than perfect
Reply


Messages In This Thread
setup modbus tcp slave - by Patrik1985 - 12.02.2018, 07:24
RE: setup modbus tcp slave - by Daniel - 12.02.2018, 09:31
RE: setup modbus tcp slave - by Patrik1985 - 12.02.2018, 09:50
RE: setup modbus tcp slave - by Daniel - 12.02.2018, 10:13
RE: setup modbus tcp slave - by admin - 12.02.2018, 10:32
RE: setup modbus tcp slave - by Patrik1985 - 12.02.2018, 11:18
RE: setup modbus tcp slave - by admin - 12.02.2018, 12:17
RE: setup modbus tcp slave - by Patrik1985 - 12.02.2018, 12:59
RE: setup modbus tcp slave - by admin - 12.02.2018, 13:01
RE: setup modbus tcp slave - by Patrik1985 - 12.02.2018, 13:16
RE: setup modbus tcp slave - by Daniel - 12.02.2018, 13:28
RE: setup modbus tcp slave - by Patrik1985 - 13.02.2018, 09:29
RE: setup modbus tcp slave - by Patrik1985 - 13.02.2018, 11:25
RE: setup modbus tcp slave - by Daniel - 13.02.2018, 11:31
RE: setup modbus tcp slave - by Patrik1985 - 13.02.2018, 11:39
RE: setup modbus tcp slave - by Daniel - 13.02.2018, 11:42
RE: setup modbus tcp slave - by Patrik1985 - 13.02.2018, 13:36
RE: setup modbus tcp slave - by buuuudzik - 01.03.2018, 08:05
RE: setup modbus tcp slave - by admin - 01.03.2018, 08:20
RE: setup modbus tcp slave - by buuuudzik - 01.03.2018, 08:45
RE: setup modbus tcp slave - by admin - 01.03.2018, 11:11
RE: setup modbus tcp slave - by fabiorusco - 07.05.2018, 10:28
RE: setup modbus tcp slave - by admin - 07.05.2018, 11:30
RE: setup modbus tcp slave - by fabiorusco - 09.05.2018, 08:12
RE: setup modbus tcp slave - by admin - 09.05.2018, 08:30
RE: setup modbus tcp slave - by fabiorusco - 09.05.2018, 17:28

Forum Jump: