LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array to bundle by name/functional global variable

Solved!
Go to solution

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

"When I read about the horrors of drinking, I gave up reading"
0 Kudos
Message 1 of 10
(3,816 Views)
Solution
Accepted by topic author MancPablo

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.

0 Kudos
Message 2 of 10
(3,776 Views)

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.

0 Kudos
Message 3 of 10
(3,773 Views)
Solution
Accepted by topic author MancPablo

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 10
(3,764 Views)

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.

"When I read about the horrors of drinking, I gave up reading"
Message 5 of 10
(3,752 Views)

@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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 10
(3,750 Views)

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?).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 10
(3,744 Views)

That reminds me!

 

 

Spoiler

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 10
(3,740 Views)

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

"When I read about the horrors of drinking, I gave up reading"
0 Kudos
Message 9 of 10
(3,725 Views)

@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

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 10
(3,671 Views)