This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Event Scripting
#1
Hello,

I have 160 modbus points and I am using an event script to combine in groups of two as below. Do I need to write this script to each point or is there a short way to do this?

Thanks.

Code:
value1 = event.getvalue()
value2 = grp.getvalue('34/1/15')

if (value1 == 0 ) then
grp.write('34/1/35', 0)

elseif (value1 == 1 and value2 == 0) then
  grp.write('34/1/35', 1)

elseif (value1 == 1 and value2 == 85) then
  grp.write('34/1/35', 2)
end
Reply
#2
It can be a single event script mapped to a tag. All related group addresses must follow a certain pattern so other addresses can be calculated from the address that triggered the event. The easiest way is to use a different middle group address. Like in this example: https://forum.logicmachine.net/showthrea...0#pid28970
Reply
#3
Hi admin,

Thanks for your reply. How can be an event script mapped to a tag?
Reply
#4
Add a tag to your object(s), create an event based script and attach it to the TAG in the dropdown box, they are all the way at the bottom under the object addresses
Reply
#5
I could not do it. Can you do an example for my group addresses below;

g1-input1:34/1/1
g1-input2:34/1/15
g1-output:34/1/35
---
g2-input1:34/1/2
g2-input2:34/1/16
g2-output:34/1/36
-----
g3-input1:34/1/51
g3-input2:34/1/65
g3-output:34/1/85
-----
g4-input1:34/1/52
g4-input2:34/1/66
g4-output:34/1/86
Reply
#6
event.dstraw can be used for this. Be careful not to create am infinite script loop. Only input1 objects must be mapped to the event script tag.
Code:
value1 = event.getvalue()

addr2 = event.dstraw + 14
value2 = grp.getvalue(addr2)

outaddr = event.dstraw + 34

if value1 == 0 then
  grp.write(outaddr, 0)
elseif value1 == 1 and value2 == 0 then
  grp.write(outaddr, 1)
elseif value1 == 1 and value2 == 85 then
  grp.write(outaddr, 2)
end
Reply
#7
Thanks admin,

Last thing is if only the value2 changes when value1 is 1, the output should change but now not changing. How can this be added?
Reply
#8
You will need another similar script mapped to input 2 groups.
Code:
value2 = event.getvalue()

addr1 = event.dstraw - 14
value1 = grp.getvalue(addr1)

outaddr = event.dstraw + 20

if value1 == 0 then
  grp.write(outaddr, 0)
elseif value1 == 1 and value2 == 0 then
  grp.write(outaddr, 1)
elseif value1 == 1 and value2 == 85 then
  grp.write(outaddr, 2)
end
Reply
#9
Thank you for your support.
Regards.
Reply


Forum Jump: