Perspective Background color on Text box

So I am having trouble find a way to have a text box in perspective change colors.

Basic Idea is I have safety lights that have three different tags that turn on a light to either red,yellow,green. I am trying to mimik the actual function in perspective.

The tags read a 1 on 0 off.

Here's one way:

    1. Add the backgroundColor property to the label.
  • 2, 3. Create an expression binding on it.
  • 4, 5, 6. Add the tags.
  • 7, 8, 9. Create an expression transform on the tags to encode them as a binary value.
  • 10, 11. Add a map transform. I've put a fallback of blue in case none or more than one tag is true.
    1. See the results of each transform.

Note: three tags for one light is probably not the right way to go. One integer tag for the machine status would be better and each state would be mutually exclusive.

2 Likes

What @Transistor said, except:

  1. Just use an expression binding at the root; no need for an expression structure then a transform.
  2. Output a style class name, instead of a direct color, to make it easier to recycle colors elsewhere in the project and to make changes if you ever need to down the road.

And, yeah, the meta comment of "make the states mutually exclusive in the PLC" is also valid.

What @PGriffith said, except:

  • I used the structure so the binding could possibly be reused with the tags passed in as parameters. :stuck_out_tongue_winking_eye:

G Y R background

case(
  binEnc(
       {[default]tagGreen},		// +1
       {[default]tagYellow},	// +2
       {[default]tagRed}		// +4
  ),
  1, "green",
  2, "yellow",
  4, "red",
  "blue"
)

I also use style classes and recommend them so ...

  • In Project Browser | Perspective | Styles, create three classes: "bgGreen", "bgYellow", "bgRed" with the background color set appropriately.
  • Delete the label backgroundColor property created above.
  • Create an expression binding on the style.classes property.
case(
  binEnc(
       {[default]tagGreen},		// +1
       {[default]tagYellow},	// +2
       {[default]tagRed}		// +4
  ),
  1, "bgGreen",
  2, "bgYellow",
  4, "bgRed",
  ""                            // no background color.
)

This will give you consistancy if you use this in multiple places. You only change the color in the style definition and every occurance will be updated.

I got this to work so far thanks... I have seen the beacon change color to red or none.
As for the Meta Statement... I don't get to program PLC where I work; I am the first to learn the Ignition at my location as Corporate is planning to fully implement it in stages going forward.

1 Like