BinEnc function help

I have successfully used the BinEnc function to change the color of an object through a number to color translation using an expression like this:
BinEnc(Tag1, Tag2)
Works great.

Now I am building a template and want to add this object to it. I need to use Indirect Binding but that only works using a single tag as far as I can tell (ex. Test/Tag{1}_OIT) where {1} is a property value from the root container like TagNum.

Since I can’t examine the values of multiple tags in an Indirect Binding (or can I???), I tried using an expression as above with the BinEnc function.
binEnc(tag(“Test/JJ”+toStr({Tank.EqpNum})+“Op”),tag(“Test/JJ”+toStr({Tank.EqpNum})+“CL”))

This expression fails. I assume it is because the BinEnc function has issues evaluating the tag functions inside of it.

Anybody see any syntax errors I may have made?
If this is not possible, does anybody know of a good work around?

Ok I found this entry about Indirect Expression binding in the Ignition help:
tag(“Facility/Valves/Valve” + {Root Container.ValveNumber} + “/OpenPct”) * 100.0

When I try this with my own tag it does not work. If I delete the “* 100.0” it evaluates the tag path.
Apparently there is something wrong with the math expression.

It states directly in the help that it should work but it obviously fails. Is this a glitch with version 7.6.6?

If I can get it to work then I should be able to build an Indirect Expression using 2 Boolean Tags to generate an integer value of 0, 1, 2 or 3. With these values I can set the color of an object inside my template based on the states of these two Boolean tags.

Finally I got something to work. After ready through posts that kind of related to my problem.

I had to use the ToInt() function on the expression from the Help file that should have worked. Here is what I ended up with:

toint(tag(“Test/JJ”+{Tank.EqpNum}+“O”),0)+(toint(tag(“Test/JJ”+{Tank.EqpNum}+“C”),0)*2)

What this does is adds the value of the first bit to the value of the second bit * 2. This gives me a value from 0 to 3 that I can use to change the color of my valve object in my Template.

I would be interest if anyone has a better way. I feel that even though this works that it kind of ugly.

Can anyone answer this? I too have tried the example from the documentation, without success.

Karen

tag() really returns an object, not a number. In order to do math on the result it must first be cast to a number (i.e. toInt(), toFloat(), etc.).

EDIT: Sorry for my stupid sounding beginning. Technically, a number is an object, but for our purposes I was trying to illustrate that there is a type mismatch going on. :wink:

Thanks. I did see conflicting documentation, one of which says it returned the object, the other which says it returned the value.

We are trying to find a way to NOT the value - i.e., if it’s true, we need false and vice versa.

Easy to do on it’s own, but I can’t find a way to do this when using a variable substitution. For example, is there anyway to do something like this: (I know it’s wrong as it’s returning a value, but I’m just illustrating what I need, ie a substitution to happen first, then applying the NOT to the value)

!{Chidd_plc/{1}/Unavailable}

Essentially, I need to display various options if the pump is available, and the PLC reports on unavailability rather than availability, thus the need to negate. We have worked around it for now by negating in the tag itself, but I’m wondering if there is a way to do this with expressions?

Well, not conflicting, per se. One is used in expressions and the other is used for scripts. Treat them as separate entities. :slight_smile:

[quote="AndyP"]
We are trying to find a way to NOT the value - i.e., if it's true, we need false and vice versa.

Easy to do on it's own, but I can't find a way to do this when using a variable substitution. For example, is there anyway to do something like this: (I know it's wrong as it's returning a value, but I'm just illustrating what I need, ie a substitution to happen first, then applying the NOT to the value)

!{Chidd_plc/{1}/Unavailable}

Essentially, I need to display various options if the pump is available, and the PLC reports on unavailability rather than availability, thus the need to negate. We have worked around it for now by negating in the tag itself, but I'm wondering if there is a way to do this with expressions?[/quote]
That's what the castings are there for. Even if it's for boolean operations:

!toBoolean(tag("Child_plc/"+{SomeDynamicName}+"/Unavailable"))

Alternatively, you can also use custom properties to get you desired effect. As an example, I create multistate button/indicators to use in manual functions for an assembly machine, usually a cylinder and associated switches. Each is a standard button with three custom properties added: Input, Output, and State. Input and Output are bound to tags. State has the expression:

{Root Container.Button.Input}+{Root Container.Button.Output}*2

State is then used to drive the Style Customizer. So now I can also use the button to verify I/O-- is the valve being called? is a sensor being made, or stuck on/off? etc.

This method has the advantage of not having to worry about casting. It also breaks things down into nice bite-sized chunks if you have to go back later and figure out what you did. Not that it's ever happened to me... :unamused:

Here's an example button to illustrate.
ButtonExample_2014-08-26_1317.proj (7.11 KB)

Thanks for the help! The ‘toBoolean’ was exactly the right thing.

Regards
Karen