LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Indexing for loop while grabbing single values from array

Solved!
Go to solution

Hello everyone,

 

I have another question. Overall I have an array and I want to grab every single element of that array. My thoughts of how I do it are the following:

 

I use a for loop for indexing my array. Then I create a local variable outside the for loop in order to get the single elements of the array. But this doesn't work I think because the local variable doesn't update every iteration.

Also it feels like there is a more elegant way to do what I want to do.


Can anyone give me some hints in order to solve my problem?

 

Thank you very much.

 

Best regards,

Tresdin

0 Kudos
Message 1 of 10
(3,471 Views)

What do you want to do with each element after you index it?  If you enable auto indexing on the for loop, the loop will index every value for you.

 

Capture.JPG

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 10
(3,459 Views)

The problem is not auto-indexing an array, but the use of a local variable.

 

So the real questions should be "what are you trying to do with a local variable" and "what are you doing outside of the loop"?

0 Kudos
Message 3 of 10
(3,444 Views)

Thanks for your replies.

 

Sorry it's my fault I wasn't accurate enough with my explanation:

 

The array which enters the for loop already consists of strings, like for example:

 

1. abc

2. def

3. ghi

.

.

.

 

 

abc is my first string element, def my 2nd and so on. The strings are commands which I want to send one after another to VISA write function. My attempt in order to get every single array element was to use the generated string array and send it into a for loop where I wanted to grab every element with the local variable.

I hope it's clearer now what I mean.

 

Best regards,

Tresdin

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

Post your VI.

 

You've shown auto-indexing which is how you get each element of an array one by one into a For Loop.

 

You have shown what the local variable has to do with any of this.

 

Since you are a new user and you say you are using local variables, that tells me you aren't using them in a way that they are meant to be.  Search the forums for the phrase "race condition" as I'm sure that is probably your  problem.

Message 5 of 10
(3,432 Views)

I think I'm using it wrong. But I have troubles implementing my ideas how I should realize things properly.

 

I didn't have a "finished" VI because I'm still trying to figure out how to do this, that's why I posted here. So I wrote this short VI, so you see the principle of what I want to do. I hope this is enough.

 

I will take a look into race conditions. Thanks

0 Kudos
Message 6 of 10
(3,420 Views)

Your For Loop will run N times (once for each element).

 

Your code outside the loop will run 1 time in parallel to that For Loop.  It will show whatever value happens to have just been written to the String terminal at the time the local variable of string is read.

 

Let's assume that the lower part of the code is in its own loop and can run multiple times.  It will run as fast as it can, or the code within the same loop will allow it.  It is a race between when data gets written to the terminal in the first loop and when it gets read in the new loop.  You may completely miss elements if the top loop is running faster.  You may get the same element twice if the bottom loop is running faster.

 

If you need to get all data out of a loop to another, you need to look at queues and the producer/consumer archtiecture.  Whether you need any of that now we can't tell since your not showing any practical use of the data outside the loop.

 

But you do need to learn more about LabVIEW and dataflow.  O would recommend you learn more about LabVIEW from here. How to Learn LV

Message 7 of 10
(3,411 Views)

@Tresdin wrote:

 

abc is my first string element, def my 2nd and so on. The strings are commands which I want to send one after another to VISA write function. My attempt in order to get every single array element was to use the generated string array and send it into a for loop where I wanted to grab every element with the local variable.

I hope it's clearer now what I mean.

 

Best regards,

Tresdin


Put the VISA write inside the For loop.

Message 8 of 10
(3,396 Views)
Solution
Accepted by topic author Tresdin

I am not sure why you are so hung up on using a local variable to send sequential VISA commands.

 

Here is what I do:

VisaCapture.PNG

That sends 7 SCPI commands to my AC source with a 100mS delay between each command sent.

========================
=== Engineer Ambiguously ===
========================
Message 9 of 10
(3,371 Views)

Hi RTSLVU,

 

I will try this later. I'm new to LabView and this was the first thing which came to my mind. I was certain that there are better ways of doing it. Thanks for your help

0 Kudos
Message 10 of 10
(3,334 Views)