Flipping Boolean tag

Is it possibly to switch a Boolean tag to always read the opposite of what it really is? I need it to say true when its false and vise versa.

Hi,
Is it an OPC tag or not?

You can use derived tags that references another tag and can transform its read or write value with an expression.

Otherwise anywhere you read or bind this tag value you can just invert its value in scripts or expressions. It all depends on what you're trying to do here.

@benp It’s an OPC tag

You need a second tag. If you only need to read it can be an expression tag, otherwise a derived tag.

Is this related to your previous question, Adding values together only if tag is true?

The Expression Language has a built-in negation, !. The expression I gave would convert to,

!{[default]Bool0} * {[default]Other0} +
!{[default]Bool1} * {[default]Other1} +
!{[default]Bool2} * {[default]Other2} +
... +
!{[default]Bool159} * {[default]Other159}

Python / Jython has the not operator.

4 Likes

@Kevin.Herron I will need historian for it if that’s what you’re asking.

@Transistor it is related to it. I used your method for my expression. Didn’t realize one of the tags is reading the opposite of what I need it to. So it’s ignoring the tags when it shouldn’t.

{[default]779/CabTrimAGVs/AGVProgram/AGV01/B2} * {[default]779/CabTrimAGVs/AGVStatus/AGV01/R5} * {[default]779/CabTrimAGVs/AGVStatus/AGV01/B30} +

I need the third line to read the opposite.

You haven't added the NOT operator, '!' as shown in post #5.

I was confused by that post. I completely missed the "!" you added at the beginning.

OK.

Tip: if you are responding to someone on the forum then either, hit the reply button below their post or use the @username syntax. Then that user will receive a notification in their inbox (as you have for this post).

More reading:

Depends on the exact use case, but there is a bitInversion value scaling option for tags.

4 Likes

Bit inversion

Oooh! I didn't know that!

@thomas_wallace that might work for you if you don't need it in it's non-inverted format somewhere else.

@amarks @Transistor That is very useful to know. I do need it in its normal state for other things. So I used transistors way. I will remember this though. Thank you.