07-24-2018
04:04 AM
- last edited on
03-14-2019
02:18 PM
by
NIadmin
I have been using the tag history for some time and I would like to expand it now to include many more variables.
As of now, the code only uses 12 tags and the code already looks cluttered (Pictures below).
Doing the same for 150+ variables will make this code impossible to maintain.
Before I start doing this for every single variable I must ask:
Are there better ways of writing this code? As of now, each variable has its own tag creation and tag cluster. (followed the labview example "write multiple tags" and expanded on it).
07-25-2018 04:07 AM
Hi,
To help me understand the problem better, I have a few questions.
Any additional information would be great.
Joelle
07-25-2018 01:21 PM
You could bundle all of the tag references into an array and work on the array tag references instead. You can use the tag property node to get the name of the tag and use that with a case structure to program a case for each tag but then, you have a case structure with hundreds of tags which isn't ideal either.
I could also see a solution using either clusters or OOP where you store what were previously your global variables as a name-value pairs in an array. Then, you would add a keyword to each tag for the name of the name-value pair it's value is stored in. Then, in a loop that you would use for writing, you would get the name of the name-value pair from the tag using a tag property node, you would search through the array for the name-value pair for this tag, get its value, wire it to the generate tag cluster, and use a shift register to keep the tag cluster between each loop iteration. Then when your tag cluster is complete, you would use the Multi Write VI to push all the values to their tags. Alternatively, you could use a number as a property to indicate the index in the array that the value is stored at to prevent you from having to iterate through the array to find the appropriate name-value pair.
If you're writing to hundreds of tags, and each of the tags' value comes from a different place, then when it comes down to it, you're going to have to write that code somewhere.
07-25-2018 01:34 PM
In my simple cRIO data logging example that uses tags, I just used a class to clean things up and iterate over things in a loop when needed.
https://github.com/joshuaprewitt/skyline-crio-logger