Update AnalogNumeric Display when tag value (array element)

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
MathewBowden
Posts: 1
Joined: Mon Feb 10, 2014 6:42 pm

Update AnalogNumeric Display when tag value (array element)

Post 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.

stuartm
Posts: 61
Joined: Thu Jun 06, 2013 9:21 am

Re: Update AnalogNumeric Display when tag value (array eleme

Post 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.

wlederer
Posts: 175
Joined: Fri Jan 27, 2012 4:20 am

Re: Update AnalogNumeric Display when tag value (array eleme

Post 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

AMitchneck
Posts: 137
Joined: Mon Jun 11, 2012 2:10 pm

Re: Update AnalogNumeric Display when tag value (array eleme

Post 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.

wlederer
Posts: 175
Joined: Fri Jan 27, 2012 4:20 am

Re: Update AnalogNumeric Display when tag value (array eleme

Post 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?

AMitchneck
Posts: 137
Joined: Mon Jun 11, 2012 2:10 pm

Re: Update AnalogNumeric Display when tag value (array eleme

Post 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

wlederer
Posts: 175
Joined: Fri Jan 27, 2012 4:20 am

Re: Update AnalogNumeric Display when tag value (array eleme

Post by wlederer »

Thank You Adam.

Post Reply