EasyManua.ls Logo

Embedded Systems LogicMachine5 - Page 209

Default Icon
291 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
209
61.
-- request ok
62.
else
63.
-- reply with an error
64.
if res[ 1 ]==nil then
65.
return nil, res[2]
66.
-- normal reply
67.
else
68.
return unpack(res)
69.
end
70.
end
71.
end
Handler (resident script with 0 delay) configuration
1. mb:open()
Open Modbus TCP connection
2. mb:setslave(10)
set slave device id
3. mb:setmapping(10, 10, 10, 10)
set number coils, discrete inputs, holding registers and input registers
4.mb:setwritecoilcb(function(coil, value)...
callback function which is executed for each coil write
5. mb:setwriteregistercb(function(coil, value)...
callback function which is executed for each register write
Handler script example
1.
-- modbus init
2.
if not mb then
3.
require('luamodbus')
4.
mb = luamodbus.tcp()
5.
mb:open()
6.
7.
-- init slave storage for coils, discrete inputs, holding registers and input registers
8.
mb:setmapping(10, 10, 10, 10)
9.
10.
-- coil write callback
11.
mb:setwritecoilcb(function(coil, value)
12.
if coil == 0 then
13.
grp.write('1/1/1', value, dt.bool)
14.
else
15.
alert('coil: %d = %s', coil, tostring(value))

Table of Contents

Other manuals for Embedded Systems LogicMachine5

Related product manuals