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.

LM Modbus slave Application Note 016
#1
Hi all,

scripting Lua lines to tune my LM (a Wiser For KNX one) in order to make it a Modbus Slave, I use with succes the application note "AN016_spaceLYnk_as_a_Modbus slave_v2.0" from Schneider Electric in Modbus RTU.

Modbus master is an EGX150 Schneider Electric.

So, success is not forthcoming when I try to turn my LM to be a Modbus TCP Slave, as the application note explain it's possible to do.

-- modbus init
if not mb then
--****************************************************
-->>>>>>>>>Modbus slave setting<<<<<<<<<<<<<<<<<<<<<<<
require('luamodbus')
mb = luamodbus.tcp()
-- IP:10.154.12.73, port: 502
mb:open('192.168.1.49', 502)   -- my LM @IP
mb:connect()
-- slave id
mbConfusedetslave(10)

../..


All your ideas are welcome !
Thank's in advance.

Dominique
Reply
#2
Remove mb:connect() and use 0.0.0.0 as listening IP: mb:open('0.0.0.0', 502)
Reply
#3
Your pourpose :

Remove mb:connect() and use 0.0.0.0 as listening IP: mb:open('0.0.0.0', 502)


Sorry, but it doesn't work for me, only Modbus RTU run correctly (502 port is ok on LM and gateway) :

Note : I use LM as Modbus slave with an EGX150 Schneider Gateway

???
Reply
#4
Post your whole script.
Reply
#5
(9 hours ago)admin Wrote: Post your whole script.

Code:
-- modbus init

log("Modbus slave handler : IN")

if not mb then


require('luamodbus')

-->>>>>>>>>Modbus slave setting<<<<<<<<<<<<<<<<<<<<<<<<
 
------------------------------------------------------
-- Pour Modbus RTU
------------------------------------------------------
mb = luamodbus.rtu()
mb:open('/dev/RS485', 19200, 'E', 8, 1, 'H')
mb:connect()
------------------------------------------------------
-- Pour Modbus TCP
------------------------------------------------------
--mb = luamodbus.tcp()
--mb:open('0.0.0.0', 502)
------------------------------------------------------ 

-->>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
 
  -- slave id
mb:setslave(2)
 
-- init slave storage for coils, discrete inputs, holding registers and input registers
mb:setmapping(1, 1, 3300, 1)

  --*****************************************************
-- >>>>>>>>>>>Coil write callback<<<<<<<<<<<<<<<<<<<<<<
mb:setwritecoilcb(function(coil, value)
if coil == 0 then
grp.write('0/0/12', value, dt.bool)
else
alert('coil: %d = %s', coil, tostring(value))
end
end)
--*****************************************************
-->>>>>>>>>>>Register write callback<<<<<<<<<<<<<<<<<<<
mb:setwriteregistercb(function(register, value)
if register == 0 then
-- send value limited to 0..100
grp.write('0/0/13', math.min(100, value), dt.scale)
else
alert('register: %d = %d', register, value)
end
end)
--*****************************************************
end
-- server part init
if not server then
log("Modbus slave handler (cyclic) : IN...server init")
require('rpc')
-- incoming data handler
local handler = function(request)
local fn, res
fn = tostring(request.fn)
if not mb[ fn ] then
return { nil, 'unknown function ' .. fn }
end
if type(request.params) == 'table' then
table.insert(request.params, 1, mb)
res = { mb[ fn ](unpack(request.params)) }
else
res = { mb[ fn ](mb) }
end
return res
end
server = rpc.server('127.0.0.1', 28002, 'mbproxy', handler, 0.01)
log("Modbus slave handler (cyclic) : OUT...handleslave = ")
end
res, err = mb:handleslave()
res, err = server:step()
Reply


Forum Jump: