Edit Gain and Offset dynamically

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
ric
Posts: 17
Joined: Wed Nov 16, 2011 4:35 am

Edit Gain and Offset dynamically

Post by ric »

Hi everyone, is it possible to change dynamically gain and offset for a specific controller's tag?

Skylar
Posts: 42
Joined: Wed Jan 04, 2012 11:17 am

Re: Edit Gain and Offset dynamically

Post by Skylar »

Hi Ric,

You could accomplish this with a global variable and a script. On the "Tags" screen, I would write a little script that scales a tag on "ValueChange" using a value that is stored in a variable, or another tag. Here is an example of what I'm talking about (I used tags for my variables):

Code: Select all

    public partial class Tags
    {
		
		void TagToScale_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
		{
			double input = Globals.Tags.TagToScale.Value;
			double gain = Globals.Tags.TagWithGain.Value;
			double offset = Globals.Tags.TagWithOffset.Value;
			
			double output = (input * gain) + offset;
			
			Globals.Tags.TagWithResult.Value = (int) output;
		}

    }
Best Regards,

Beijer Electronics, Inc.
Skylar Walker | Applications Engineer

scott
Posts: 2
Joined: Sun Feb 09, 2014 4:55 pm

Re: Edit Gain and Offset dynamically

Post by scott »

Perhaps this might be of help.

It is a common problem with PLCs that don't support floats that we must scale our values up in order to gain resolution. When displayed on the HMI, however, we must scale it back again.

I have a tag defined as "SensorValue", and I want to change the gain on this at runtime. The number of decimal places I want I am storing in a second tag called "SensorResolution". The following code will update the gain on the SensorValue tag so that it has the number of decimal places as shown in SensorResolution.

Code: Select all

Globals.Tags.SensorValue.Gain = System.Math.Pow(10, -(double)Globals.Tags.SensorResolution.Value);
For a value of 0 in SensorResolution, the gain on SensorValue will be 1.
For a value of 1 in SensorResolution, the gain on SensorValue will be 0.1.
For a value of 2 in SensorResolution, the gain on SensorValue will be 0.01.

etc.

Don't forget to change the tag data type to float for the tag who's gain you are adjusting - the controller data type doesn't need to be changed.

jmkowol
Posts: 13
Joined: Wed Jul 31, 2013 10:23 am

Re: Edit Gain and Offset dynamically

Post by jmkowol »

Just saw this post and....wanted to say thanks.....I always was looking for the solution for the "scaling" problem.
J

Post Reply