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.
Update AnalogNumeric Display when tag value (array element)
-
- Posts: 1
- Joined: Mon Feb 10, 2014 6:42 pm
Re: Update AnalogNumeric Display when tag value (array eleme
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.
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
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
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
-
- Posts: 137
- Joined: Mon Jun 11, 2012 2:10 pm
Re: Update AnalogNumeric Display when tag value (array eleme
(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.
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
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?
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?
-
- Posts: 137
- Joined: Mon Jun 11, 2012 2:10 pm
Re: Update AnalogNumeric Display when tag value (array eleme
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
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
Thank You Adam.