04-18-2017 12:25 PM
Gurus,
I have a for loop generating an array of numbers (in attached labelled Errors). I want to write this to a FGV I have created, which I have defined a control of double precision numbers, all nicely name. The array generated by the for loop has the same number of points as the control in the FGV. Is there a simple way to map array into this FGV? I have tried the array to cluster, but that produces a wire mis-match. Is there a way to index the FGV?
Attached is a PNG of the for loop and the front panel/block diagram of the FGV.
Many thanks,
Paul
Solved! Go to Solution.
04-18-2017 01:38 PM
You should use Array to Cluster, but you need to right-click on it and set the number of elements to the actual number of elements in the cluster. Once you fix that, you won't have a wire mismatch.
04-18-2017 01:44 PM
If you double click Array to cluster, it will allow to set cluster size.
But it is hard to scale this...
I would store in FGV names (strings, enums array) and values (doubles array) separately and address by name to get/set value.
04-18-2017 01:52 PM
1. Your FGV should just be a Global Variable. It will have the exact same functionality but be faster and easier to maintain. A Look At Race Conditions
2. As the others have said, you need to right-click on the Array To Cluster function to set the cluster size. The default is 9 items. Looks like you have 19 in your cluster.
04-18-2017 02:29 PM
Thanks to all. Worked fine.
I am sure there was reasons why I switched over to FGV from globals. It was some advice from the forums, but I cannot remember what! Not used globals for years and my code is crammed full of FGV.
04-18-2017 02:31 PM
@MancPablo wrote:
Thanks to all. Worked fine.
I am sure there was reasons why I switched over to FGV from globals. It was some advice from the forums, but I cannot remember what! Not used globals for years and my code is crammed full of FGV.
And I thank you for that!
Ben
04-18-2017 02:44 PM
MancPablo wrote:
I am sure there was reasons why I switched over to FGV from globals. It was some advice from the forums, but I cannot remember what! Not used globals for years and my code is crammed full of FGV.
The main reason not to use Global Variables is race conditions. And the problem with FGVs is that they do not solve that problem. And my benchmarks have shown FGVs to be slower (link given earlier). Now if you are actually making Action Engines, then you are doing the right thing. (Yes, I make a distinction between a FGV and Action Engine, with a FGV being a Get/Set AE). You can also see my NI Week presentation for a lot more on this subject (Are Global Variables Truly Evil?).
04-18-2017 02:57 PM
That reminds me!
Say I have a FGV that was written to be subject to the same race condition that a global would.
So as I am troubleshooting I want to find out which call stack of the FGV is writing a bad value to it.
I can go to the block diagram and set a break point. When the breakpoint fires I can use the drop-down (usually used for setting the font at development time) To see what instance of the FGV is writing bad data.
So if I was using a global how would your track down the offending caller?
.....
So then I figure out that the "read-modify-write" construct is bad and I decided I will fix it and turn the FGV into an AE with proper actions. Modifying the FGV to be come an AE is simplified. Not so if I had coded using a global.
If you can guarantee the developer that will follow you will always know the issues with globals they are fine. If one can not be sure...
Ben
04-18-2017 03:27 PM
Interesting stuff. I am going to have to look what AE are!
I have now added another dimension. Literally. I have a for loop generating19 arrays, each 10,000 points long. So the tunnel on the edge is a 2D, (19 x10,000) array. Writing that to my FGV (with 19 arrays in the control cluster) is proving challenging!
Paul
04-19-2017 08:04 AM
@MancPablo wrote:
Interesting stuff. I am going to have to look what AE are!
...
Paul
I wrote a Nugget a long time ago about Action Engines that you can find here.
I offer that link to help you understand what makes an Action Engine useful, and how it works. I would also encourage a review of the follow-up conversation to learn how the AEs can be used inside of wrappers and near the end how new features of LV have given the AE different forms and performance bumps.
While I am not ready to go public with it, I am working on another Nugget talking about making use of Libraries to improve the organization and support effort for LabVIEW code.
Enjoy!
Ben