Scripting a tag group refresh

I have a project where we have several "Check IP" buttons. The buttons trigger a sequence in the PLC where it runs a bunch of GSVs, gets the IP addresses from the several dozen ethernet devices in that section, and then updates some string tags.

I'm trying to figure out the best way to coordinate this function with the PLC. I have the string tags for the IP addresses made up now, and they're on a driven tag group that has a base rate of 0 and a driven rate of 1000ms. I also have the groups set up as One Shot, and Read after Write. I really don't want to be reading all those string tags if I don't have to. I also would REALLY like to avoid having to rely on timers.

So far, I figured I would tie my tag group trigger to the appropriate Check IPs button tag. The problem is, my PLC program resets the button boolean immediately, and it's happening fast enough to where it's not triggering the tag group...apparently. If I put the PLC in program mode and just toggle the bit on and off, it works.

My next thought was to put a tag change script on the button, but I ran into issues there trying to pass tag parameters into a script (I don't know how to do it, if it's even possible, and didn't have much luck searching).

At this point, I'm thinking I might have to have the PLC do its' thing, flag a bit, and have that trigger my tag group, and then a run a tag change script off that to turn itself off. But I'm still concerned about the reliability and timing of it all. I essentially need both the PLC and then Ignition perform the update in a sequence. Push Button to read the IPs triggers the PLC to run our AOIs and load the IP addresses into strings, then Ignition triggers the tag group to read the tags. Is that the best way to go about it?

Consider not using tags, but simply scripting with system.opc.readValues().

Also consider not using strings. IP addresses and netmask (and gateway IPs) all fit nicely in byte arrays. Much more efficient communications to retrieve such.

1 Like

Awesome. I didn't know I could read opc values without tags. I'll bring up the IP address thing to the programmer as well. Thanks!

Regarding the byte arrays. If the PLC is sending me a 32-bit integer for the IP address instead of a string, what would be the best way to get that into a readable IP address format? I tried setting that tag as a byte array and I get an array of 64 bytes with the 0s and 1s in each coded in binary. Is there a lot of scripting involved on Ignition's end to translate that?

An expression tag for each byte, with shift and mask. Like so:

{path/to/address} & 255
({path/to/address} >> 8) & 255
({path/to/address} >> 16) & 255
({path/to/address} >> 24) & 255
2 Likes

First 8 bits of 32 bit integer as a binary to decimal is β€˜192’, second 8 bits as decimal is β€˜168’ and so on.
Right shift β€˜>>’ and bitmasking β€˜value & 0x08’ are your friends

1 Like

Yet more tools I didn't know existed. This is great. Thanks!

So here's what I ended up with:

image

I made a UDT with an OPC tag for the raw input and an expression tag for the human-readable IP address. Here's the expression:

I wasn't sure if four expression tags for each octet and then another expression tag to concatenate them would be the best idea, so I combined it all into a single expression. I have the expression tag and the OPC tag on the same leased tag group, so I'm hoping the expression tag isn't going to lease my Raw Input tag all the time since it itself is on a leased group. But even if it does, it's just an Int4 instead of a string now.

3 Likes