LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

adding VI references to an array

I'm learning Labview as I go.  Starting with a simple concept and trying to figure out ways to make the code more efficient.
 
I started with a VI that has references to 15 different VIs.  So I duplicated the open reference...etc... 15 different times then used those references 15 other times in the code to invoke the VIs.
 
Now I'm trying to write a For loop in which I can add each VIs reference into an array and then use the array elsewhere in my code.
 
CAN.vi is the VI which contains the code explained above.  Main.vi is the VI which calls CAN.vi.
 
I'm having difficultly figuring out when to use an array constant, build array, etc.
 
If you could look at CAN.vi and offer some advice I'd appreciate it.
Download All
0 Kudos
Message 1 of 5
(3,323 Views)

I know you're still learning, but it looks like you are grossly overcomplicating things. I remember your other thread with the start of this program. Some ideas:

1. I really don't think you even need to call these subvis dynamically, I said this in the other thread and I'll reiterate here. They all perform a calculation and return two doubles, so you would be much better off creating one subvi that contains all of the calculations in a case structure where you can select which to perform. Wire the ring on your front panel to the selector of this case structure to pick which calculation. Then just place this in your vi, you do not need to call it dynamically.

2. The feedback node in main.vi should be replaced with a shift register. They're easier to use and from what I've read, perform a little faster.

3. Initialize array in main.vi should have a double wired to the element input. You're creating an array of integers to store doubles, you're losing data.

4. Read up a little more about local variables, it doesn't seem like you quite understand their functionality.

5. in CAN.vi, you're indexing an empty array, then replacing an element in this empty array. Therefore, you're not doing anything, you still have an empty array. However this operation is not necessary at all (see note 1)

You're using your imagination, and it looks like you want to jump into the more complicated aspects of LabVIEW right away, but I think you need to get a handle on the basics first. Keep at it though, and keep asking questions. Feel free to ask if you don't understand something I said in this post.

Message 2 of 5
(3,313 Views)

I appreciate your feedback.  You experienced Labview programmers monitoring this forum are priceless to a new LV programmer like myself. 

I am new to Labview but am an experienced programming in other languages.  I want to further explain my project to see if I'm still over-complicating things.  Maybe I am, but if so not sure how else to handle this.  The reason I've kept this approach is because each VI has a different front panel.  In each VI I'm byte packing several meaningful individual bytes into the two doubles.  That's why every VI returns 2 doubles, it's for consistency.  The receiver of this information will do byte unpacking to expand the data back out into meaningful data.

As far as the use of locals, you're right.  What I have here is junk.  It stems from as I've learned more, I haven't completely cleaned things up yet.

In response to your feedback #5,  even if I can write this code a different way I would still apprecieate more advice on arrays.  I'm assuming the array your referring to as empty is the array of VI References?  If so, how do I initialize this array?

Also, the Build Array function...  I'm confused on how this works.  I'm not getting much help from the user's manual.  I figured you could use the build array to build a dynamic array.  Is this not true?

Thanks!

0 Kudos
Message 3 of 5
(3,301 Views)

Then why not just put the case structure in your main program, and have each of those sub vis in a case that is selected by the ring control? This will allow you to show the front panels of each, and will be easier to implement. If you did want to keep the dynamic calls, I wouldn't make an array of them like you're trying to do. Just have the ring select the name of the sub vi you'd like to load and wire that to Open VI Reference. I'll whip up an example using yours sometime today.

Build array does build a dynamic array. It can concatenate 2 arrays (right clickit -> concatenate inputs), create a 2D array from 2 1D arrays, or add single elements to an array. It is not as efficient as initializing an empty array and replacing elements. Speaking of this, to initialize an array, there is an Initialize Array function. Wire something to the element input and a number to the dimension size input. It will create an array as big as you specified filled with whatever you wired to element. In your VI, this would be an empty VI reference.

I'll get back to this at some point today with a simple example of picking a dynamic VI by name.

0 Kudos
Message 4 of 5
(3,285 Views)
Ok, here's a couple examples. First is the way I would do it. Main.vi has the ring connector selecting a case which runs the VI associated with that case. Since they all output 2 doubles and you want the user to see the front panel, this is the best way to do it in my opinion. I also changed some other things in this VI such as some variable types and I made the feedback node into a shift register.
 
Secondly, CAN.vi is an example of how to dynamically load whichever VI you want. There is an error because you'll have to wire a VI reference of an actual VI with 2 double outputs as a type specifier. I have the path pointing to the same directory as CAN.vi, if these VIs are in another directory, you'll have to modify this accordingly.
 
Edit: Forgot to mention, I made EEC1 just to have a vi that passed back 2 doubles, that's why there is nothing in it.
 
Let me know if you have any more questions

Message Edited by Marc A on 02-02-2007 11:49 AM

Download All
0 Kudos
Message 5 of 5
(3,272 Views)