How to do a AND
How to do a AND
I have to enable a light when two controller tags are active so I was wondering if there is any way to do a AND without having to use a script?
Re: How to do a AND
Are you running on a PC or a Panel?
If you are running on a PC you could let the first tag operate the Visibility property and the second tag the Opacity property (I believe Opacity is only available on PC-targets).
On a panel you can put a rectangle (in the same color as your background) on top and let one of the tags hiding it and the other one the "light-icon"...
Maybe there is some other and more simpler way, but not that I know of (without using scripts).
Best Regards
Edmund
If you are running on a PC you could let the first tag operate the Visibility property and the second tag the Opacity property (I believe Opacity is only available on PC-targets).
On a panel you can put a rectangle (in the same color as your background) on top and let one of the tags hiding it and the other one the "light-icon"...
Maybe there is some other and more simpler way, but not that I know of (without using scripts).
Best Regards
Edmund
Re: How to do a AND
And with a script how would it be? I tried to code it referring myself to a website to learn how to code C # but it downt work at all.
-
- Posts: 824
- Joined: Tue Mar 13, 2012 9:53 am
Re: How to do a AND
Code: Select all
if((Globals.Tags.MyTag1.Value == 1) && (Globals.Tags.MyTag2.Value == 1)){
//Do Something here
}
http://csharp.net-tutorials.com/basics/if-statement/
Best Regards,
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Re: How to do a AND
Well, easiest way would be.
Go to tags, create a new tag (internal, BOOL) called Tag3.
Hit the script tab in the bottom.
To the left you have all your tags, expand tag 1 and DoubleClick ValueChange.
A new eventhandler is created for you
This function will be called every time the tag changes value.
Now we have to check if the tags are both true and if they are lets set our third tag to true as well.
So now we check if both are true then we set Tag3 to true or false.
But right now we only check the status each time Tag1 is changed, we also need to do this when Tag2 is changed.
This will work but it creates duplicated code, which is BAD!
Let´s create a little function that we can call from each eventhandlers.
And call the function from the eventhandlers
Of course we can make this even better and more flexible by passing the tags as parameters to the function and so on... But that’s the next lesion.
Complete code
Now you can use Tag3 to show or hide your light.
Best Regards
Go to tags, create a new tag (internal, BOOL) called Tag3.
Hit the script tab in the bottom.
To the left you have all your tags, expand tag 1 and DoubleClick ValueChange.
A new eventhandler is created for you
Code: Select all
void Tag1_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
}
Now we have to check if the tags are both true and if they are lets set our third tag to true as well.
Code: Select all
void Tag1_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
if(Tag1.Value == true && Tag2.Value == true)
{
Tag3.Value = true;
}
else
{
Tag3.Value = false;
}
}
But right now we only check the status each time Tag1 is changed, we also need to do this when Tag2 is changed.
Code: Select all
void Tag2_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
if(Tag1.Value == true && Tag2.Value == true)
{
Tag3.Value = true;
}
else
{
Tag3.Value = false;
}
}
Let´s create a little function that we can call from each eventhandlers.
Code: Select all
void DetermineStatusForTag3()
{
if(Tag1.Value == true && Tag2.Value == true)
{
Tag3.Value = true;
}
else
{
Tag3.Value = false;
}
}
Code: Select all
void Tag1_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
DetermineStatusForTag3();
}
void Tag2_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
DetermineStatusForTag3();
}
Complete code
Code: Select all
void Tag1_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
DetermineStatusForTag3();
}
void Tag2_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
DetermineStatusForTag3();
}
void DetermineStatusForTag3()
{
if(Tag1.Value == true && Tag2.Value == true)
{
Tag3.Value = true;
}
else
{
Tag3.Value = false;
}
}
Best Regards
- Attachments
-
- Script for Tags
- img1.png (63.75 KiB) Viewed 11363 times
-
- Tags
- img0.png (46.79 KiB) Viewed 11363 times
Re: How to do a AND
Great!! Thanks a lot Edmund, that really helped me to understand a bit more the way C# works, thank you very much!!