LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array as input and output, pointers?

Hi,

I'm passing an array of clusters to a sub vi. The sub vi will then make some changes to each element and return the array to the calling vi.

In the sub vi do I have to have two arrays, one set up as a control (input) and one set up as an indicator (output)? It makes the front panel look a bit cluttered.

Is it not possible to use the same array as an input and return it as an ouput?

Does LabView allow the use of pointers to variables like C? If so can they be passed to sub vi's rather than the data itself?

Thanks,
Dave.
0 Kudos
Message 1 of 10
(3,910 Views)
If I understand your question correctly you can just use a local variable to the control and after your data manipulation that local varb can be written to. See this attached simple VI.
Hope this helps,
-Dave
0 Kudos
Message 2 of 10
(3,902 Views)
***EDIT*** Duplicate

Message Edited by NIDave on 04-15-2005 07:09 AM

0 Kudos
Message 3 of 10
(3,903 Views)
If I understand your question correctly you can just use a local variable to the control and after your data manipulation that local varb can be written to. See this attached simple VI.
Hope this helps,
-Dave

Sorry forgot to attach it the first time and that post in the middle is some sorta glitch because I tried to stop it mid-post when I realized I hit the wrong button

Message Edited by NIDave on 04-15-2005 07:10 AM

0 Kudos
Message 4 of 10
(3,903 Views)


@Dave123 wrote:
Hi,

I'm passing an array of clusters to a sub vi. The sub vi will then make some changes to each element and return the array to the calling vi.

In the sub vi do I have to have two arrays, one set up as a control (input) and one set up as an indicator (output)? It makes the front panel look a bit cluttered.

Is it not possible to use the same array as an input and return it as an ouput?

Does LabView allow the use of pointers to variables like C? If so can they be passed to sub vi's rather than the data itself?

Thanks,
Dave.




Salutations,

Yes, you can use the same array as an input and then return it as an output. Just directly wire your control and indicator to the pattern diagram of your sub vi. Right mouse click on the VI and "Show Connector" you can change the pattern if necessary. Then attach each of them where you please. That way, you're using the same array as both an input and output.
Note: I don't believe you can wire the exact same indicator or control to the Show Connector Pattern Diagram to multiple locations. You'll need to have two seperate defined locations.

If your front panel is getting cluttered, you don't have to show all the indicators and controls etc... Right mouse click on them and go to "Advanced" then "Hide ...." for the front panel or if you're on the block diagram just "Hide ..." after right mouse clicking on it. To bring it back, it's best to work from the block diagram and just "Show ..."

Does Labview allow the use of pointers to variables like C..... Well, I've never used this animal you're calling "C". However, LabView allows for local and global variables. Also, take a moment to look over the use of nodes, that might prove useful.

Sincerely,
ElSmitho
0 Kudos
Message 5 of 10
(3,896 Views)
Hello Dave123,

your subvi needs an input (array control) and an output (array indicator). So you will need both on your your front panel.
But:
- Your subvi doesn't need to show the front panel to the user. He will not see the "cluttered" panel.
Or:
- If you pass a reference to the subvi, then the subvi can manipulate the array in the main vi - without other inputs/outputs.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(3,896 Views)
Hello Dave123,

I forgot to mention, that passing a reference is like passing a pointer to a variable in C...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(3,895 Views)


@NIDave wrote:
If I understand your question correctly you can just use a local variable to the control and after your data manipulation that local varb can be written to. See this attached simple VI.
Hope this helps,
-Dave

Sorry forgot to attach it the first time and that post in the middle is some sorta glitch because I tried to stop it mid-post when I realized I hit the wrong button

Message Edited by NIDave on 04-15-2005 07:10 AM



Hi NiDave,

I could'nt get your attached vi to download preoperly. Can you send it again.

Thanks.
Dave.
0 Kudos
Message 8 of 10
(3,883 Views)
I would use the two arrays and not worry about the cluttered front panel for the subvi. References with property nodes works but is really of most use when you want to see updates on the main front panel while the subvi is running. Local and global variables are generally frowned upon by experienced LV programmers.

With regard to your question about "pointers" to the data I think that it is worth noting that in LV the data is reprented in the wire, not the control. If you wire an input to a subvi this is not necessarily making a new copy of the data. Data copies are only made when needed in LV (local and global variables always make copies). So while I've never programmed in C I think that LV is already giving you the functionality that you desire.
0 Kudos
Message 9 of 10
(3,872 Views)


@GerdW wrote:
Hello Dave123,

I forgot to mention, that passing a reference is like passing a pointer to a variable in C...




And using a reference in this particular case is a sure way to create a badly performing VI. Reference access is ALWAYS done in the UI thread. This means the subVI will have to switch from its default thread to the UI thread to get the data, switch back and do something on the data then again switch to the UI thread to write the data back and then return to its default thread to return to the caller. All in all this is likely to end up even slower than using a global which is already bad. Just pass in the data thourh one control into the subVI and do whatever you need on that data and then pass it back out through an indicator. LabVIEW gets in each version somewhat smarter about reusing array data and inplace operations are part of the LabVIEW compiler since its inception with LabVIEW 2. In the case of arrays passed into and out of subVIs it optimizes those operations since at least LabVIEW 5 and did an even better job on this in LabVIEW 6. As long as the subVI front panel is not shown, LabVIEW 6.0 and later will almost never make a copy of that array as long as you don't do operations on the array in the subVI diagram which require a copy for correct operation (this means mostly branching of the array wire to multiple functions, although LabVIEW attempts to optimize even that).

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 10 of 10
(3,862 Views)