Page 1 of 1
Update AnalogNumeric Display when tag value (array element)
Posted: Mon Feb 10, 2014 7:29 pm
by MathewBowden
Hi,
I have been using arrays and therefore need to access them via scripting. I can get and set data and display in appropriate format etc. The problem is if the valve in the array element changes the AnalogNumeric display doesn't automatically update. Is there some sort of event I can tie it to that will update the display?
I see that if I do not use a script and associate a tag with the display, the display updates when the value in the tag changes, this is great but in the script I cannot get this to happen.
Any suggestions welcome. Thanks in advance.
Re: Update AnalogNumeric Display when tag value (array eleme
Posted: Wed Feb 12, 2014 4:44 pm
by stuartm
Most scripting is better done within a tag event. If you are using a script module, to access a tag directly:
static Screen1() {
Globals.Tags.Tag1.ValueChange += (o,oo) => {
Globals.Tags.Tag2.Value = Globals.Tags.Tag1.Value;
};
}
You can find the same scripts located inside that "Tags" script tab.
Re: Update AnalogNumeric Display when tag value (array eleme
Posted: Mon Mar 17, 2014 5:55 am
by wlederer
Thank You dear stuartm for this example.
But, what actually does it do?
As, I guess, it adds to the tag's Tag1 value a value of zero and if result equal or more than original value of the tag, it assigns the new value to the Tag2. Is that true?
Previously, another way of refreshing a tag was shown:
Globals.Tags.Tag1.Read();
Does it do the same?
Regards, Waldemar
Re: Update AnalogNumeric Display when tag value (array eleme
Posted: Tue Mar 18, 2014 7:15 am
by AMitchneck
(arg1, arg2, ...) => { statements } is how to write inline functions in C#.
Using the line:
Globals.Tags.Tag1.ValueChange += (o,oo) => {
Globals.Tags.Tag2.Value = Globals.Tags.Tag1.Value;
adds an event handler to tag1 such that every time tag1's value changes tag1 copies it's value into tag2.
Re: Update AnalogNumeric Display when tag value (array eleme
Posted: Tue Mar 18, 2014 9:18 am
by wlederer
Thank You AMitchneck,
what means +=(0,00), may be, if the tag's value changes more than 0.01 (absolut), then do next? Where is tutorial for .ValueChange?
Re: Update AnalogNumeric Display when tag value (array eleme
Posted: Mon Mar 24, 2014 10:06 am
by AMitchneck
ValueChanged is an event in the tags class which raises an event when the tag's value changes (this could be due to any change, it's simply "value now" is not equal to "value before"). To add event handles to the event delegate, you use the += operator. To remove handlers, you use the -= operator.
You can read more about event handlers here:
http://msdn.microsoft.com/en-us/library ... 90%29.aspx
To learn more about inline functions (also known as a lambda expression), you can look here:
http://msdn.microsoft.com/en-us/library ... 90%29.aspx
Re: Update AnalogNumeric Display when tag value (array eleme
Posted: Tue Mar 25, 2014 3:45 am
by wlederer
Thank You Adam.