132
Handler script example
1.
-- modbus init
2.
if
not
mb
then
3.
require
(
'luamodbus'
)
4.
mb
=
luamodbus.rtu
()
5.
mb:open
(
'/dev/ttyS2'
,
38400
,
'E'
,
8
,
1
,
'H'
)
6.
mb:connect
()
7.
8.
-- slave id
9.
mb:setslave
(
10
)
10.
11.
-- init slave storage for coils, discrete inputs, holding registers and input registers
12.
mb:setmapping
(
10
,
10
,
10
,
10
)
13.
14.
-- coil write callback
15.
mb:setwritecoilcb
(
function
(
coil, value
)
16.
if
coil
==
0
then
17.
grp.
write
(
'1/1/1'
, value, dt.bool
)
18.
else
19.
alert
(
'coil: %d = %s'
, coil,
tostring
(
value
))
20.
end
21.
end
)
22.
23.
-- register write callback
24.
mb:setwriteregistercb
(
function
(
register, value
)
25.
if
register
==
0
then
26.
-- send value limited to 0..100
27.
grp.
write
(
'4/1/5'
,
math.min
(
100, value
)
, dt.scale
)
28.
else
29.
alert
(
'register: %d = %d'
, register, value
)
30.
end
31.
end
)
32.
end
33.
34.
-- server part init
35.
if
not
server
then
36.
require
(
'rpc'
)
37.
38.
-- incoming data handler
39.
local
handler
=
function
(
request
)
40.
local
fn, res
41.
42.
fn
=
tostring
(
request.fn
)
43.
44.
if
not
mb
[
fn
]
then
45.
return
{
nil
,
'unknown function '
.. fn
}
Содержание LogicMachine3 Re:actor
Страница 10: ...10 Terminal connection schemes KNX TP...
Страница 12: ...12 24V power supply...
Страница 13: ...13 Analog inputs e g reed contact...
Страница 14: ...14 Analog inputs 0 10V...
Страница 15: ...15 Digital output...
Страница 16: ...16 Resistive sensor input...
Страница 17: ...17 Analog output...
Страница 26: ...26 Make sure that bus status is Online press button in ETS...
Страница 35: ...35 o Then minimize side bar by pressing on left arrow icon to make the map more visible...
Страница 83: ...83 66 if err then 67 alert FTP upload failed s err 68 end...
Страница 107: ...107...
Страница 108: ...108 1 14 Help Documentation for scripting syntaxes is displayed in Help tab...
Страница 122: ...122 4 16 Running processes System running processes can be seen in Status Running processes window...
Страница 126: ...126 Datapoints can be shown also in a way of table which can be later exported as CSV file...
Страница 141: ...141...