Posts: 35
Threads: 6
Joined: Dec 2023
Reputation:
0
27.03.2024, 16:57
(This post was last modified: 27.03.2024, 17:13 by djaval .)
(26.02.2024, 09:08) Daniel Wrote: This is how it meant to work. You need to convert it back to float on master device.
mb.setfloat16precision(2) sets how float16 is converted to integer. By default it's 2 decimals (0.01 precision). Change 2 to 0 to convert to integer without any decimals.
Hi! Yes, it works. Not a big problem to convert back to float on master device, but just to clarify. Is it possible to make pure float register (either it can be little or big endian)?
Posts: 8199
Threads: 43
Joined: Jun 2015
Reputation:
473
float32 data type is handled as is without any conversion. The script can be modified to convert float16 to float32 instead of int16.
Edit: script has been updated with optional conversion of float16 to float32:
https://kb.logicmachine.net/integration/...tcp-slave/
Posts: 60
Threads: 22
Joined: Jul 2017
Reputation:
0
How do i set up the script to use slave id 1 on the first RS-485 port and slave id 2 on the second RS-485 port on an LM5 Lite?
Posts: 8199
Threads: 43
Joined: Jun 2015
Reputation:
473
Create two separate scripts, one for each port.
Posts: 21
Threads: 0
Joined: Jul 2023
Reputation:
0
I am Using Daikin Ac and Ac Guy Given me address and holding register ID. So query is that when I'm triggering from Logic Machine not getting response from AC. even i used json file.
Attached Files
Thumbnail(s)
Posts: 5040
Threads: 28
Joined: Aug 2017
Reputation:
230
This thread is for modbus slave and you are using master so if you have issues create dedicated topic for your case please.
------------------------------
Ctrl+F5
Posts: 21
Threads: 0
Joined: Jul 2023
Reputation:
0
Hi Sir,
When I am doing read test in Modbus in Logic Machine then it is showing me this number, what does it mean?
I have Attached Sceenshot
Attached Files
Thumbnail(s)
Posts: 5040
Threads: 28
Joined: Aug 2017
Reputation:
230
It is what the text says, result of the read request.
------------------------------
Ctrl+F5
Posts: 21
Threads: 0
Joined: Jul 2023
Reputation:
0
Thanks For Reply
sir I want to Know that how to understand this result and What it means
Posts: 8199
Threads: 43
Joined: Jun 2015
Reputation:
473
Check the register description in the device documentation.
Posts: 21
Threads: 2
Joined: Nov 2022
Reputation:
0
We have 5 Zones in our project and each zone has an Automation DB having KNX Actuators and a KNX keypad.
So now we have to implement Auto/Manual logic in that way that if we press the button on KNX keypad the DB will go on the manual mode, it means now we are only able to control the DB devices (KNX Actuators) with keypad only and no command can be executed from the SCADA system until we remove the Manual mode by pressing the Auto mode key on the KNX keypad.
This Auto/Manual logic is to be implemented for all the 5 Zones.
Is it possible to make different resident script for different zone in MODBUS RTU so that we can disable the communication of particular zone by just disabling the resident script of that particular zone. We are using one LM5 as MODBUS RTU Slave for all 5 Zones.
Posts: 8199
Threads: 43
Joined: Jun 2015
Reputation:
473
Multiple resident scripts can't share the same RS-485 port. It should be enough just to block writing as needed.
Replace the whole
handlers.writeregister function with this, modify
writeallowed logic as needed.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
local function writeallowed (
slaveid )
if slaveid ==
1 then
return grp.getvalue (
'1/1/1' )
elseif slaveid ==
2 then
return grp.getvalue (
'1/1/2' )
end
end
handlers.writeregister =
function (
slaveid ,
fncode ,
data )
if #
data ~=
4 then
return
end
local addr =
touint16 (
data ,
1 )
local map =
getmapping (
slaveid ,
fncode )
if not map or not map [
addr ]
then
return excodes.illegaldataaddress
end
local mapobj =
map [
addr ]
if mapobj.len ~=
1 then
return excodes.illegaldataaddress
end
if writeallowed (
slaveid )
then
writevalue (
mapobj ,
data ,
3 )
end
return data
end
Replace the whole
handlers.writeregisters function with this.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
handlers.writeregisters =
function (
slaveid ,
fncode ,
data )
if #
data <
5 then
return
end
local addr =
touint16 (
data ,
1 )
local count =
touint16 (
data ,
3 )
local bytes =
touint8 (
data ,
5 )
if #
data ~= (
bytes +
5 )
then
return
end
if count ==
0 or count >
limits.writeregisters or bytes ~=
count *
2 then
return excodes.illegaldataaddress
end
local map =
getmapping (
slaveid ,
fncode )
if not map then
return excodes.illegaldataaddress
end
if writeallowed (
slaveid )
then
for i =
0 , (
count -
1 )
do
local mapobj =
map [
addr +
i ]
if mapobj and not mapobj.readonly then
local offset =
6 +
i *
2
writevalue (
mapobj ,
data ,
offset )
end
end
end
return data :
sub (
1 ,
4 )
end
Posts: 21
Threads: 2
Joined: Nov 2022
Reputation:
0
Hi, I have done the changes in the mbslave (user library script). But still I didn't understand how will I disable one Zone to communicate with the SCADA over modbus rtu. Do I need to make some changes in resident script as well. Please guide.
Posts: 21
Threads: 2
Joined: Nov 2022
Reputation:
0
(18.04.2025, 15:16) imprashant Wrote: Hi, I have done the changes in the mbslave (user library script). But still I didn't understand how will I disable one Zone to communicate with the SCADA over modbus rtu. Do I need to make some changes in resident script as well. Please guide.
Previously the script I was using was working but sometimes I have to send command 2-3 times from Modscan in order to execute command in LM5. The script I was using:
local mb = require('user.mbslave')
local mbrtu = require('luamodbus').rtu()
mbrtu:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
mbrtu:connect()
mbrtu:setslave('*') -- Accept multiple RTU slave IDs
mb.setswap('w')
mb.setfloat16precision(2)
local ga1 = '0/0/11' --zone 1 enable/disable
local ga2 = '0/0/12' --zone 2 enable/disable
local current_mapping = nil
-- Predefine mappings for easy reuse
local mapping1 = {
[1] = {
coils = {
[0] = '0/0/1',
},
registers = {
[0] = '0/0/2',
}
}
}
local mapping2 = {
[1] = {
coils = {
[1] = '0/0/3',
},
registers = {
[1] = '0/0/4',
}
}
}
while true do
local val1 = grp.getvalue(ga1)
local val2 = grp.getvalue(ga2)
if not val1 and current_mapping ~= "mapping1" then
mb.setmapping(mapping1)
current_mapping = "mapping1"
log("Applied Mapping 1")
elseif not val2 and current_mapping ~= "mapping2" then
mb.setmapping(mapping2)
current_mapping = "mapping2"
log("Applied Mapping 2")
end
mb.rtuhandler(mbrtu)
os.sleep(1) -- small delay to prevent CPU hogging
end
Posts: 8199
Threads: 43
Joined: Jun 2015
Reputation:
473
The previous solution is meant to be used with multiple slave IDs. Writing to slave ID 1 is allowed when 1/1/1 is true, writing to slave ID 2 is allowed when 1/1/2 is true.
writeallowed should be modified as needed.
Alternative solution is to add logic AND gates to mapped group addresses.
Updated user library:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
local _M = {}
local byteswap ,
wordswap
local f16mult =
1
local f16float =
false
local mapping = {}
local exception = {}
local reply = {}
local fncodes = {
[
1 ] =
'readcoils' ,
[
2 ] =
'readdiscreteinputs' ,
[
3 ] =
'readregisters' ,
[
4 ] =
'readinputregisters' ,
[
5 ] =
'writecoil' ,
[
6 ] =
'writeregister' ,
[
15 ] =
'writecoils' ,
[
16 ] =
'writeregisters' ,
}
local mapfncodes = {
[
1 ] =
'coils' ,
[
2 ] =
'discreteinputs' ,
[
3 ] =
'registers' ,
[
4 ] =
'inputregisters' ,
[
5 ] =
'coils' ,
[
6 ] =
'registers' ,
[
15 ] =
'coils' ,
[
16 ] =
'registers' ,
}
local dtlens = {
[
dt.bool ] =
1 ,
[
dt.bit4 ] =
1 ,
[
dt.int8 ] =
1 ,
[
dt.uint8 ] =
1 ,
[
dt.int16 ] =
1 ,
[
dt.uint16 ] =
1 ,
[
dt.float16 ] =
1 ,
[
dt.int32 ] =
2 ,
[
dt.uint32 ] =
2 ,
[
dt.float32 ] =
2 ,
[
dt.int64 ] =
4 ,
}
local maxpdu =
253
local maxaddr =
0x10000
local coilon =
0xFF00
local limits = {
readbits =
2000 ,
writebits =
1968 ,
readregisters =
125 ,
writeregisters =
123 ,
}
local excodes = {
illegalfunction =
1 ,
illegaldataaddress =
2 ,
illegaldatavalue =
3 ,
serverdevicefailure =
4 ,
acknowledge =
5 ,
serverdevicebusy =
6 ,
negativeacknowledge =
7 ,
memoryparityerror =
8 ,
gatewaypathunavailable =
10 ,
gatewaytargetdevicefailed =
11 ,
}
local handlers = {}
local function touint8 (
buf ,
off )
return buf :
byte (
off )
end
local function touint16 (
buf ,
off ,
swap )
local b1 ,
b2 =
buf :
byte (
off ,
off +
1 )
if swap then
b1 ,
b2 =
b2 ,
b1
end
return b1 *
0x100 +
b2
end
local function getmapping (
slaveid ,
fncode )
local mapfncode =
mapfncodes [
fncode ]
local slave =
mapping [
slaveid ]
if not slave then
slave =
mapping [
'*' ]
end
if slave then
return slave [
mapfncode ]
end
end
local function readbits (
slaveid ,
fncode ,
data )
if #
data ~=
4 then
return
end
local addr =
touint16 (
data ,
1 )
local count =
touint16 (
data ,
3 )
if count ==
0 or count >
limits.readbits then
return excodes.illegaldataaddress
elseif (
addr +
count ) >
maxaddr then
return excodes.illegaldataaddress
end
local map =
getmapping (
slaveid ,
fncode )
if not map then
return excodes.illegaldataaddress
end
local res = {}
local bits ,
byte =
0 ,
0
for i =
0 , (
count -
1 )
do
local mapaddr =
map [
addr +
i ]
if mapaddr then
local bval =
grp.getvalue (
mapaddr )
if toboolean (
bval )
then
byte =
byte +
bit.lshift (
1 ,
bits )
end
end
bits =
bits +
1
if bits ==
8 then
res [ #
res +
1 ] =
string.char (
byte )
bits ,
byte =
0 ,
0
end
end
if bits ~=
0 then
res [ #
res +
1 ] =
string.char (
byte )
end
return string.char (#
res ) ..
table.concat (
res )
end
local zeroreg =
string.char (
0 ,
0 )
local function readvalue (
res ,
value ,
dpt )
if dpt ==
dt.float16 then
if f16float then
dpt =
dt.float32
else
value =
value *
f16mult
dpt =
dt.int16
end
end
local enc =
busdatatype.encode (
value ,
dpt )
if not enc.dataraw then
return
end
local raw =
enc.dataraw
if #
raw %
2 ==
1 then
local pad =
value <
0 and 0xFF or 0
raw =
string.char (
pad ) ..
raw
end
local words = #
raw /
2
local offset = #
res
for i =
1 ,
words do
local word =
raw :
sub (
i *
2 -
1 ,
i *
2 )
if byteswap then
word =
word :
sub (
2 ,
2 ) ..
word :
sub (
1 ,
1 )
end
if wordswap then
res [
offset +
i ] =
word
else
res [
offset +
1 +
words -
i ] =
word
end
end
return true
end
local function readregisters (
slaveid ,
fncode ,
data )
if #
data ~=
4 then
return
end
local addr =
touint16 (
data ,
1 )
local count =
touint16 (
data ,
3 )
if count ==
0 or count >
limits.readregisters then
return excodes.illegaldataaddress
elseif (
addr +
count ) >
maxaddr then
return excodes.illegaldataaddress
end
local map =
getmapping (
slaveid ,
fncode )
if not map then
return excodes.illegaldataaddress
end
local res = {}
local max =
count -
1
while #
res <=
max do
local mapobj =
map [
addr + #
res ]
local success
if mapobj then
local value =
grp.getvalue (
mapobj.address )
if type (
value ) ==
'boolean' then
value =
value and 1 or 0
end
if type (
value ) ~=
'number' then
alert (
'invalid value ' ..
mapobj.address ..
' ' ..
tostring (
value ))
value =
0
end
success =
readvalue (
res ,
value ,
mapobj.dpt )
end
if not success then
res [ #
res +
1 ] =
zeroreg
end
end
if #
res ~=
count then
return excodes.illegaldataaddress
end
return string.char (
count *
2 ) ..
table.concat (
res )
end
local function writevalue (
obj ,
data ,
offset )
local words =
obj.len
local len =
words *
2
local raw =
data :
sub (
offset ,
offset +
len -
1 )
if #
raw <
len then
return
end
local buf = {}
for i =
1 ,
words do
local word =
touint16 (
raw ,
i *
2 -
1 ,
byteswap )
local hex =
string.format (
'%04X' ,
word )
if wordswap then
buf [ #
buf +
1 ] =
hex
else
table.insert (
buf ,
1 ,
hex )
end
end
local hexval =
table.concat (
buf )
local dpt =
obj.dpt
if dpt ==
dt.float16 then
dpt =
f16float and dt.float32 or dt.int16
end
local value =
busdatatype.decode (
hexval ,
dpt )
if obj.dpt ==
dt.float16 and not f16float then
value =
value /
f16mult
end
_M.write (
obj.address ,
value )
end
handlers.readcoils =
readbits
handlers.readdiscreteinputs =
readbits
handlers.readregisters =
readregisters
handlers.readinputregisters =
readregisters
handlers.writecoil =
function (
slaveid ,
fncode ,
data )
if #
data ~=
4 then
return
end
local addr =
touint16 (
data ,
1 )
local map =
getmapping (
slaveid ,
fncode )
if not map or not map [
addr ]
then
return excodes.illegaldataaddress
end
local bval =
touint16 (
data ,
3 ) ==
coilon
_M.write (
map [
addr ],
bval ,
dt.bool )
return data
end
handlers.writeregister =
function (
slaveid ,
fncode ,
data )
if #
data ~=
4 then
return
end
local addr =
touint16 (
data ,
1 )
local map =
getmapping (
slaveid ,
fncode )
if not map or not map [
addr ]
then
return excodes.illegaldataaddress
end
local mapobj =
map [
addr ]
if mapobj.len ~=
1 then
return excodes.illegaldataaddress
end
writevalue (
mapobj ,
data ,
3 )
return data
end
handlers.writecoils =
function (
slaveid ,
fncode ,
data )
if #
data <
5 then
return
end
local addr =
touint16 (
data ,
1 )
local count =
touint16 (
data ,
3 )
local bytes =
touint8 (
data ,
5 )
if #
data ~= (
bytes +
5 )
then
return
end
if count ==
0 or count >
limits.writebits or bytes ~=
math.ceil (
count /
8 )
then
return excodes.illegaldataaddress
end
local map =
getmapping (
slaveid ,
fncode )
if not map then
return excodes.illegaldataaddress
end
local offset =
6
local byte =
data :
byte (
offset )
local bits =
0
for i =
0 , (
count -
1 )
do
local bval =
bit.band (
bit.rshift (
byte ,
bits ),
1 )
local mapaddr =
map [
addr +
i ]
if mapaddr then
_M.write (
mapaddr ,
bval ,
dt.bool )
end
bits =
bits +
1
if bits ==
8 then
bits =
0
offset =
offset +
1
byte =
data :
byte (
offset )
end
end
return data :
sub (
1 ,
4 )
end
handlers.writeregisters =
function (
slaveid ,
fncode ,
data )
if #
data <
5 then
return
end
local addr =
touint16 (
data ,
1 )
local count =
touint16 (
data ,
3 )
local bytes =
touint8 (
data ,
5 )
if #
data ~= (
bytes +
5 )
then
return
end
if count ==
0 or count >
limits.writeregisters or bytes ~=
count *
2 then
return excodes.illegaldataaddress
end
local map =
getmapping (
slaveid ,
fncode )
if not map then
return excodes.illegaldataaddress
end
for i =
0 , (
count -
1 )
do
local mapobj =
map [
addr +
i ]
if mapobj and not mapobj.readonly then
local offset =
6 +
i *
2
writevalue (
mapobj ,
data ,
offset )
end
end
return data :
sub (
1 ,
4 )
end
exception.tcp =
function (
sock ,
hdr ,
excode )
local fncode =
bit.bor (
0x80 ,
hdr :
byte (
8 ))
local resp =
hdr :
sub (
1 ,
4 ) ..
string.char (
0 ,
3 ) ..
hdr :
sub (
7 ,
7 ) ..
string.char (
fncode ,
excode )
return sock :
send (
resp )
end
exception.rtu =
function (
mbrtu ,
hdr ,
excode )
local fncode =
bit.bor (
0x80 ,
hdr :
byte (
2 ))
local resp =
hdr :
sub (
1 ,
1 ) ..
string.char (
fncode ,
excode )
return mbrtu :
send (
resp )
end
reply.tcp =
function (
sock ,
hdr ,
data )
local resp =
hdr :
sub (
1 ,
4 ) ..
string.char (
0 , #
data +
2 ) ..
hdr :
sub (
7 ,
8 ) ..
data
return sock :
send (
resp )
end
reply.rtu =
function (
mbrtu ,
hdr ,
data )
local resp =
hdr :
sub (
1 ,
2 ) ..
data
return mbrtu :
send (
resp )
end
local function handler (
mode ,
ctx ,
hdr ,
data )
local slaveid ,
fncode =
hdr :
byte (#
hdr -
1 , #
hdr )
local fnname =
fncodes [
fncode ]
if not fnname then
return exception [
mode ](
ctx ,
hdr ,
excodes.illegalfunction )
end
local res =
handlers [
fnname ](
slaveid ,
fncode ,
data )
if type (
res ) ==
'number' then
return exception [
mode ](
ctx ,
hdr ,
res )
elseif type (
res ) ==
'string' then
return reply [
mode ](
ctx ,
hdr ,
res )
end
end
_M.tcphandler =
function (
sock )
local hdr ,
err =
sock :
receive (
8 )
if not hdr then
return nil ,
err
end
local len =
touint16 (
hdr ,
5 ) -
2
local data
if len <=
0 or len >
maxpdu then
err =
'protocol error'
else
data ,
err =
sock :
receive (
len )
end
if not data then
return nil ,
err
end
return handler (
'tcp' ,
sock ,
hdr ,
data )
end
_M.rtuhandler =
function (
mbrtu )
local data ,
err =
mbrtu :
receive ()
if not data then
return nil ,
err
end
local slaveid =
data :
byte (
1 )
if not mapping [
slaveid ]
then
return
end
return handler (
'rtu' ,
mbrtu ,
data :
sub (
1 ,
2 ),
data :
sub (
3 , #
data -
2 ))
end
_M.setswap =
function (
swap )
byteswap =
swap :
find (
'b' ) ~=
nil
wordswap =
swap :
find (
'w' ) ~=
nil
end
_M.setfloat16precision =
function (
prec )
prec =
tonumber (
prec )
or 0
f16mult =
math.pow (
10 ,
prec )
end
_M.setfloat16mode =
function (
mode )
f16float =
mode ==
'float'
dtlens [
dt.float16 ] =
f16float and 2 or 1
end
local function initobject (
obj ,
dbobj )
local dpt =
obj.datatype or dbobj.datatype
if type (
dpt ) ==
'string' then
dpt =
dt [
dpt ]
or 0
end
if type (
dpt ) ==
'number' and dpt >=
1000 then
dpt =
math.floor (
dpt /
1000 )
end
obj.dpt =
dpt
obj.len =
dtlens [
dpt ]
obj.address =
dbobj.address
if not obj.len then
alert (
'invalid data type ' ..
obj.address ..
' ' ..
tostring (
dpt ))
return
end
return obj
end
local function initobjects (
objects )
if type (
objects ) ~=
'table' then
return
end
for addr ,
obj in pairs (
objects )
do
if type (
obj ) ==
'string' then
obj = {
address =
obj }
end
local dbobj =
grp.find (
obj.address )
if dbobj then
obj =
initobject (
obj ,
dbobj )
else
alert (
'missing object ' ..
obj.address )
obj =
nil
end
objects [
addr ] =
obj
end
end
_M.write =
grp.write
_M.setmapping =
function (
map )
for _ ,
smap in pairs (
map )
do
initobjects (
smap.registers )
initobjects (
smap.inputregisters )
end
mapping =
map
end
return _M
Resident script example:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
local mb =
require (
'user.mbslave' )
local mbrtu =
require (
'luamodbus' ).
rtu ()
mbrtu :
open (
'/dev/RS485-1' ,
9600 ,
'E' ,
8 ,
1 ,
'H' )
mbrtu :
connect ()
mbrtu :
setslave (
'*' )
mb.setswap (
'w' )
mb.setfloat16precision (
2 )
mb.setmapping ({
[
1 ] = {
coils = {
[
0 ] =
'0/0/1' ,
[
1 ] =
'0/0/3' ,
[
2 ] =
'0/0/4' ,
},
discreteinputs = {
[
0 ] =
'1/0/1' ,
[
1 ] =
'1/0/3' ,
[
2 ] =
'1/0/4' ,
},
registers = {
[
0 ] =
'1/1/4' ,
[
1 ] =
'1/1/10' ,
[
3 ] =
'32/1/6' ,
[
5 ] =
'32/1/13' ,
},
inputregisters = {
[
0 ] =
'2/1/4' ,
[
1 ] =
'2/1/10' ,
}
}
})
local gates = {
[
'0/0/3' ] =
'32/0/1' ,
[
'1/0/1' ] =
'32/0/2' ,
[
'1/0/3' ] =
'32/0/2' ,
[
'1/0/4' ] =
'32/0/3' ,
}
mb.write =
function (
addr ,
value ,
dt )
local gate =
gates [
addr ]
if not gate or grp.getvalue (
gate )
then
grp.write (
addr ,
value ,
dt )
end
end
while true do
mb.rtuhandler (
mbrtu )
end
In
gates table key (left side) is mapped group address and value (right side) is controlling gate object. Write to the given mapped group address will only happen if the gate value is true. Writing to group addresses without a gate group address is always allowed.
Posts: 21
Threads: 2
Joined: Nov 2022
Reputation:
0
Hi, Thanks for sharing. It is working fine for the coils i.e 1 bit object. But we have holding registers as well that we are using for scene control in which we are sending 0,1 and 2 value from the same group address. How in the above script we can use gate function for the holding registers.
registers = {
[1] = '6/3/6',
[2] = '6/0/10',
[3] = '6/0/11',
[4] = '6/2/6',-
[5] = '6/2/7',
},
Posts: 8199
Threads: 43
Joined: Jun 2015
Reputation:
473
gates table is shared, it works the same for coils and registers.