Change of color in a Linear meter display based on bit value

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
jmkowol
Posts: 13
Joined: Wed Jul 31, 2013 10:23 am

Change of color in a Linear meter display based on bit value

Post by jmkowol »

Hello all,

Another small scripting issue as an iX developer beginner.
using Information designer it was really easy to change the color of the bar-graph in a Linear Meter element.
Now I want to use a similar function in the iX developer and it does not work quite I want to.

I created a Variable that based on value (0,1,2) should change colors from green, yellow to red depending on some error bits in my PLC code.
I do have the error bits and depending on the state of them I would like to set the color of my display

I was trying to use the code for Value change of my Level variable to initiate the check for the bits.
The code seem to be OK and translates without errors.
If I change the value of my "AlarmColorID_A" tag manually it will change the colors so this part is working. (just a NOTE)

But the function does not work :-(
Attached the code:

void _0__Level_A_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
if ( (Globals.Tags._0_A_Level_Error.Value == 0) && (Globals.Tags._0_A_Level_low_Error.Value == 0))
Globals.Tags.AlarmColorID_A.Value = 0;

{
if ((Globals.Tags._0_A_Level_Error.Value == 0) && (Globals.Tags._0_A_Level_low_Error.Value == 1))
Globals.Tags.AlarmColorID_A.Value = 1;

{
if ((Globals.Tags._0_A_Level_Error.Value == 1) && (Globals.Tags._0_A_Level_low_Error.Value == 1))
Globals.Tags.AlarmColorID_A.Value = 2;
}
}
}

I used if "expressions" before so ????... where is the bug ?
Am I blinded by something?

User avatar
Chris T.
Posts: 109
Joined: Mon Nov 20, 2017 5:29 pm

Re: Change of color in a Linear meter display based on bit v

Post by Chris T. »

JMkowol,

There are a few hitches i can see in your code. The brackets look a bit misplaced for me.

You can either do away with them like this:

void _0__Level_A_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
if ( (Globals.Tags._0_A_Level_Error.Value == 0) && (Globals.Tags._0_A_Level_low_Error.Value == 0))
Globals.Tags.AlarmColorID_A.Value = 0;


if ((Globals.Tags._0_A_Level_Error.Value == 0) && (Globals.Tags._0_A_Level_low_Error.Value == 1))
Globals.Tags.AlarmColorID_A.Value = 1;


if ((Globals.Tags._0_A_Level_Error.Value == 1) && (Globals.Tags._0_A_Level_low_Error.Value == 1))
Globals.Tags.AlarmColorID_A.Value = 2;
}

Or keep them like this:

void _0__Level_A_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
if ( (Globals.Tags._0_A_Level_Error.Value == 0) && (Globals.Tags._0_A_Level_low_Error.Value == 0))
{
Globals.Tags.AlarmColorID_A.Value = 0;
}

if ((Globals.Tags._0_A_Level_Error.Value == 0) && (Globals.Tags._0_A_Level_low_Error.Value == 1))
{
Globals.Tags.AlarmColorID_A.Value = 1;
}

if ((Globals.Tags._0_A_Level_Error.Value == 1) && (Globals.Tags._0_A_Level_low_Error.Value == 1))
{
Globals.Tags.AlarmColorID_A.Value = 2;
}

}

This should help.
Best regards,
Christopher
(801) 708-6690
Technical Support
Contact Us

Beijer Electronics AB
http://www.beijerelectronics.us

Post Reply