01-04-2021 02:03 PM
Hey guys,
I have written a PLC emulator in labview that uses global variables for the tag database. I have several routines that reference a global tag many times. This is a "template" routine that will be copied/pasted and only the referenced global variable is changed. Going through and changing this manually (potentially hundreds of times per routine) is too much, so I was looking into changing these all with a Find->Replace, but it does not allow this bulk update.
I've searched extensively for how to use LabVIEW scripting to iterate these objects but they all just appear as the generic "Global" GObject so I cannot change that reference. Is there any way to do this?
I have read numerous threads mentioning how global variables are frowned upon and I understand this, but the program is sequential and will thus only ever have one read/write at a time.
Thanks for your time.
01-04-2021 03:23 PM
If you're trying to replace the global VI it references, you can do that in VI scripting:
1. Open VI reference to VI that needs global(s) replaced
2. Run "Traverse for GObjects" to find all globals on the block diagram
3. Filter based on the VI name property to confirm you've got a reference to a global you want to replace
4. For each global on the block diagram, use an invoke node and select the "Replace" method, wiring in the path of the Global VI you want to replace the existing global with
5. Cast the reference coming out of the Replace invoke node to a Global
6. Check that the "Control name" property of the new Global is correct, set it to the desired name if not
7. Run the Save.Instrument method on the VI reference, then close it
You'll need a VI to manage calling all of this for all of your VIs. Possibly just a VI that uses a recursive file list to do this to all VIs anywhere in a selected directory hierarchy, then doing the above in a big FOR loop.
01-05-2021 03:01 AM
It sounds like you're using the wrong tool (wrong in the sense that it's painful. I'm ignoring the race condition discussion and whether it's relevant in your case). Since it's not entirely clear how your setup works, I don't have a concrete suggestion, but that might be possible if you provide more details. For example, by showing an example of how this is supposed to work.
Off the top of my head, and without knowing the details of what you're doing, it sounds like you want a scalable tag-value repository. You could do this with a map (LV 2019+) or with variant attributes. You could have a single VI which will manage a DVR to your map/variant, so that you have a global copy of it and then read/write to it. The advantage with those is that they work by name, so they should provide the scalability.
NI also has the current value table (CVT) utility elsewhere on this site, which will probably also do what you want, but I haven't looked at its design in years.