Logic Machine Forum
rewrite - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: rewrite (/showthread.php?tid=2192)



rewrite - Gadjoken - 09.08.2019

Hello,
I use scripts to read or write BACNET values.
I would like to know if there is an easy way to rewrite this script more clearly and not send the values every time (If the value read on the BACNET is the same as the previous one then we do not rewrite it) :


Code:
require('bacnet')


--CASSETTE 2
value2 = bacnet.readvalue(16002, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/2', value2)

--CASSETTE 3
value3 = bacnet.readvalue(16003, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/3', value3)

--CASSETTE 4
value4 = bacnet.readvalue(16004, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/4', value4)

--CASSETTE 5
value5 = bacnet.readvalue(16005, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/5', value5)

--CASSETTE 6
value6 = bacnet.readvalue(16006, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/6', value6)

--CASSETTE 7
value7 = bacnet.readvalue(16007, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/7', value7)

--CASSETTE 8
value8 = bacnet.readvalue(16008, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/8', value8)

--CASSETTE 9
value9 = bacnet.readvalue(16009, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/9', value9)

--CASSETTE 10
value10 = bacnet.readvalue(16010, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/10', value10)

--CASSETTE 11
value11 = bacnet.readvalue(16011, 'binary value', 8) -- Prise du statut Fenetre

grp.write('5/3/11', value11)

This script is one of the resident scripts for reading values I have many and some are for writing.
B.R.


RE: rewrite - admin - 09.08.2019

You can use for loop and checkwrite which will not send the same value again.

Code:
require('bacnet')

for i = 2, 11 do
  id = 16000 + i
  value = bacnet.readvalue(id, 'binary value', 8) -- Prise du statut Fenetre
  grp.checkwrite('5/3/' .. i, value)
end



RE: rewrite - Gadjoken - 09.08.2019

(09.08.2019, 06:34)admin Wrote: You can use for loop and checkwrite which will not send the same value again.

Code:
require('bacnet')

for i = 2, 11 do
  id = 16000 + i
  value = bacnet.readvalue(id, 'binary value', 8) -- Prise du statut Fenetre
  grp.checkwrite('5/3/' .. i, value)
end
Thanks !!