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.

While Loop for reading values
#1
Hello.
I'm writing av script to read several values from different GA and comparing all of these values to get the highest of them as an output.
I can structure the GA's so that they come with increment of +1.
Any tips from people who have done this before?




-Regards
Reply
#2
Why not use tags? You can get values for all objects with a single function call this way.
Reply
#3
Oh, I did not know.
Could you give an example?

Sent fra min SM-G980F via Tapatalk
Reply
#4
Code:
function tag_max(tag)
  local objects = grp.tag(tag)
  local result = -math.huge

  for _, object in ipairs(objects) do
    result = math.max(result, object.value)
  end

  return result
end

max = tag_max('my_tag_name')
log(max)
Reply
#5
works perfekt, thank you!
Reply
#6
Spinoff on this post.
Here we use tags to calculate the max value. Is there any clever way to disregard a value if a GA is "true"? I want to check if the damper is in faultstate before running the "max"script.
Reply
#7
This is an or gate, this
https://forum.logicmachine.net/showthrea...5#pid11545
or this
https://forum.logicmachine.net/showthrea...18#pid1518
------------------------------
Ctrl+F5
Reply
#8
i don't think that will work. There is one fault GA for each damper, and I only want to dismiss the value from that one damper. Is it possible to alter tags on GAs from script?
Reply
#9
Do you mean that you want to check another status object before including value in the calculation? In this case you need some addressing rules so you can get status object address for another tagged object.
Reply
#10
(19.01.2021, 13:30)admin Wrote: Do you mean that you want to check another status object before including value in the calculation? In this case you need some addressing rules so you can get status object address for another tagged object.

That is correct yes. If the Fault GA is "true" then the other value should be ignored.
Reply
#11
In this example each fault object has the next middle group (shift = 256, 1/1/123 => 1/2/123). Change as needed, shift can be negative.
Code:
function tag_max(tag, shift)
  local objects = grp.tag(tag)
  local result = -math.huge

  for _, object in ipairs(objects) do
    local fault = grp.getvalue(object.id + shift)
    if not fault then
      result = math.max(result, object.value)
    end
  end

  return result
end

max = tag_max('my_tag_name', 256)
log(max)
Reply
#12
Code:
input = event.getvalue()

if input == true then
  grp.removetags('Damper_1_Angle', 'Supply')
else
  grp.addtags('Damper_1_Angle', 'Supply')
end
This worked fine. This script is eventbased and used in all fault GA's. Will have to enter the Alias for each damper, but that is a one time thing.

Could this have been done easier?
Reply
#13
(19.01.2021, 15:00)tomnord Wrote:
Code:
input = event.getvalue()

if input == true then
  grp.removetags('Damper_1_Angle', 'Supply')
else
  grp.addtags('Damper_1_Angle', 'Supply')
end
This worked fine. This script is eventbased and used in all fault GA's. Will have to enter the Alias for each damper, but that is a one time thing.

Could this have been done easier?

Hi

Just to give my toughts....

I am doing smililar things as you describe here in many projects. What I have found to be the best way is to aloways use a very strict naming policy. By doing that I can find the address for fault (as you mention here) by replacin the code for temp with the code for fault.

To find the address I need I can then do something like this;
Code:
adresse = string.gsub(grp.find(event.dst).name, 'TRIGGER_OUTPUT', 'TRIGGER_INPUT')
LOCK = grp.getvalue('32/1/2')

if not LOCK then
  grp.write(adresse, event.getvalue())
end

Here I replace the TRIGGER_OUTPUT with TRIGGER_INPUT to find the address to forward the value to if the locking is not true.

You could do the same by simply replacing 'TEMPERATURE' with 'FAULT', or whatever would be your naming policy.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Forum Jump: