SpaceLogic KNX Forum
Schneider Electric SpaceLogic KNX forum to get support and share knowledge including selection, installation and troubleshooting for spaceLYnk, Wiser for KNX, eConfigure KNX, SpaceLogic KNX Hybrid module and other topics.
Link copied. Please paste this link to share this article on your social media post.
Hello,
I am testing the AN016_V1.0 spacelynk as a modbus slave.
When updating KNX registers they are updated to the "slave modbus registers in HL" that works fine.
Now I want to update KNX registers when a modbus master writes to HL as a slave.
I used the code in the application note and slightly modified it.
When writing to MB register 1, 2 or 3 this need to be updated in the KNX group addresses 4/5/1-4/5/2-4/5/3, and thois part don't work
I did the test with PMC modbus to write to HL slave registers and this seems to work, when after writing i read these registers the value is updated.
But internally it is not send to the KNX group address...
PMC modbus write to HL as a slave
and when i read the registers with PMC modbus
But in HL they are not mapped to the KNX registers... therefore i use the code below, Modbus IP handler=>
------------------------------------------------------------------------------
-- modbus init
if not mb then
--****************************************************
-->>>>>>>>>Modbus slave setting<<<<<<<<<<<<<<<<<<<<<<<
require('luamodbus')
mb = luamodbus.tcp()
-- IP:192.168.0.69, port: 502
mb:open('192.168.0.69', 502)
mb:connect()
-- slave id
mb:setslave(10)
-- init slave storage for coils, discrete inputs, holding registers and input registers
mb:setmapping(10, 10, 10, 10)
--*****************************************************
-->>>>>>>>>>>Register write callback<<<<<<<<<<<<<<<<<<<
mb:setwriteregistercb(function(register, value)
alert("register %d has been changed to %d", register, value)
if register == 1 then
grp.write('4/5/1',value)
end
end)
--*****************************************************
-->>>>>>>>>>>Register write callback<<<<<<<<<<<<<<<<<<<
mb:setwriteregistercb(function(register, value)
alert("register %d has been changed to %d", register, value)
if register == 2 then
grp.write('4/5/2',value)
end
end)
--*****************************************************
-->>>>>>>>>>>Register write callback<<<<<<<<<<<<<<<<<<<
mb:setwriteregistercb(function(register, value)
alert("register %d has been changed to %d", register, value)
if register == 3 then
grp.write('4/5/3',value)
end
end)
--*****************************************************
end
-- server part init
if not server then
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)
end
mb:handleslave()
server:step()
-----------------------------------------------------------------------
Another question, when defining the number of registers for -> MB:setmapping(10, 10, 10, 10)
Is this starting from modbus address 0 or will this mapping start from the first callback address...
What is the maximum number of registers that you would advise so HL would not get instable...
Kind regards
Koen
Link copied. Please paste this link to share this article on your social media post.
Hello Koen,
I have just test it with both version 1.0 and 1.1 and it works OK.
You are asking good question about the registers. It starts from zero in spaceLYnk.
It means that register 0 in sL corresponds to register 1 in your PMC.
When you map 10 registers using command MB:setmapping(10, 10, 10, 10),
10 holding registers is created, it means 0-9 in spaceLYnk point of view.
We have not performed tests for modbus slave load yet. But it is in our plan.
I cannot say maximum number of registers, but it is more about the modbus activity then count of modbus registers.
Even if you have 1 modbus resgister and you write into its value very often (in order of hundreds per minute), it can be very exhaustive load for spaceLYnks.
I am copying my modbus handler script here:
-- modbus init
if not mb then
--****************************************************
-->>>>>>>>>Modbus slave setting<<<<<<<<<<<<<<<<<<<<<<<
require('luamodbus')
mb = luamodbus.tcp()
-- IP:10.154.12.78, port: 502
mb:open('10.154.12.78', 502)
mb:connect()
-- slave id
mb:setslave(10)
-- init slave storage for coils, discrete inputs, holding registers and input registers
mb:setmapping(10, 10, 10, 10)
--*****************************************************
-->>>>>>>>>>>Register write callback<<<<<<<<<<<<<<<<<<<
mb:setwriteregistercb(function(register, value)
if register == 0 then
grp.write('4/5/1',value)
elseif register == 1 then
grp.write('4/5/2',value)
elseif register == 2 then
grp.write('4/5/3', value)
end
alert('register: %d = %d', register, value)
end)
--*****************************************************
end
-- server part init
if not server then
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)
end
mb:handleslave()
server:step()
Link copied. Please paste this link to share this article on your social media post.
Hello Koen,
I have just test it with both version 1.0 and 1.1 and it works OK.
You are asking good question about the registers. It starts from zero in spaceLYnk.
It means that register 0 in sL corresponds to register 1 in your PMC.
When you map 10 registers using command MB:setmapping(10, 10, 10, 10),
10 holding registers is created, it means 0-9 in spaceLYnk point of view.
We have not performed tests for modbus slave load yet. But it is in our plan.
I cannot say maximum number of registers, but it is more about the modbus activity then count of modbus registers.
Even if you have 1 modbus resgister and you write into its value very often (in order of hundreds per minute), it can be very exhaustive load for spaceLYnks.
I am copying my modbus handler script here:
-- modbus init
if not mb then
--****************************************************
-->>>>>>>>>Modbus slave setting<<<<<<<<<<<<<<<<<<<<<<<
require('luamodbus')
mb = luamodbus.tcp()
-- IP:10.154.12.78, port: 502
mb:open('10.154.12.78', 502)
mb:connect()
-- slave id
mb:setslave(10)
-- init slave storage for coils, discrete inputs, holding registers and input registers
mb:setmapping(10, 10, 10, 10)
--*****************************************************
-->>>>>>>>>>>Register write callback<<<<<<<<<<<<<<<<<<<
mb:setwriteregistercb(function(register, value)
if register == 0 then
grp.write('4/5/1',value)
elseif register == 1 then
grp.write('4/5/2',value)
elseif register == 2 then
grp.write('4/5/3', value)
end
alert('register: %d = %d', register, value)
end)
--*****************************************************
end
-- server part init
if not server then
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)
end
mb:handleslave()
server:step()
Link copied. Please paste this link to share this article on your social media post.
Hello Tomas, this script works fine, Thank you!
I have noticed when scanning for modbusdevices with PMC that he recognises multiple devices and not only slave on address 10,
Also when writing to the HL he will save the value even if you put in a different slave address...
Could it be because we are on Modbus/TCP, so the IP address is unique to the slave... and the slave address doesn't matter that much?
Link copied. Please paste this link to share this article on your social media post.
Koen,
you are right. The slaveid has no function in this case.
The slave device is fully determined by IP address and port number.
Note:
You can use this specification (IP,port+slave ID) in homeLYnk as a master, when you want to connect to Modbus gateway and access the devices behind the gateway.
If you use e.g. Smartlink IP, you can connect to Smartlink via modbus IP and read the the values from Modbus RTU devices(specified by slaveid) connected to Smartlink.
This is the situation when you can use both IP,port specification and slaveid together.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.