Troubles making a Derived Boolean Tag work as a mask for a Short Tag

Hi!

I have long wanted a clean way in Ignition to create an internal boolean tag that points at an OPC based integer or short so I can easily link graphics to set/clear a bit of an OPC tag without scripting. I have used the setBit and getBit functions in scripting posted elsewhere in the forum but this seems overly complex. I have a number of modbus devices that don’t allow the function to mask write an integer, so I cannot do this directly through OPC tags.

I thought derived tags should be able to do a masked read and write from a base integer tag pretty easily - create a boolean derived tag and point it to the integer OPC tag. In the Read Expression section - take the source value from the int tag, shift and AND it appropriately to mask out the bit, and in the In the Write Expression, reverse the process and rebuild the tag out of the source.

However, Ignition doesn’t seem to like me making a derived tag of a different type than the source tag it points to. It’ll work if I don’t change the Read Expression and Write Expression, just converting the int tag directly into a bool and back. But as soon as I change the read and write expressions it breaks. Here are two pictures of the setup:

I’ve toyed around with conversions and such, but believe the derived tag is doing conversions behind the scenes before I get the source and value.

Is there a way to achieve bit masking with the derived tag?

Thanks much!

Jeff

1 Like

I’ve made it work using the following expressions:

Read:

(toInt({source}) >> N) & 1

Write:

if({value}, 
	toInt({source}) | (1 << N), 
	toInt({source}) & ~(1 << N))

Where N will vary based on the bit number (0-15 for a Modbus register).

You should also turn on the “OPC Optimistic Writes” flag for the scan class these tags belong to or you’re going to have a race condition if you try to write to multiple bits in the same word too quickly.

2 Likes

Hi Kevin-

I was excited when I saw your reply, but unfortunately I still can’t get it to work. I am running Version: 7.9.3 (b2017060210).

Here is the Tag Diagnostics:

Not sure what I am doing different from your example. My “Base tag” is a short and the “Derived Base Tag Bit 1” is a Boolean.

I did turn on Optimistic writes in the scan class.

Any more ideas?

1 Like

Your "Write expression" was shifting the wrong way, and not accounting for any other bits that you might need to leave on in that word.

1 Like

this is what I used to read (SINT)tag value. Is there a way to change the Background Color according to the tag values?

for example,

   if (Flt.0 = 1) then Red else green
  If(Flt.1 = 1) then Red else green

Thank you
Jinil

I imagine that it would simply be this:

if({[default]ST010/C01/Flt} > 0, color(255, 0, 0), color(0,255,0))