LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't auto index from a for loop out through a case structure

Solved!
Go to solution

I have a for loop nested in a case structure, and outside the case structure is a write to measurement Vi. at each iteration of the for loop I try to send data to the write to measurement Vi using a tunnel with auto indexing enabled. But the write to measurement Vi only sees the output from the final iteration of the loop. Is this happening becuase I'm trying to auto index out through a case structure? How do you configure case structures to alow auto indexing?

0 Kudos
Message 1 of 8
(3,477 Views)

It might help if you post your VI, but it sounds like you're expecting the "write to measurement" VI to see each iteration of the for loop, but it won't execute until the for loop, and the case structure it resides within, have completed. If you have auto-indexing enabled then you should be getting an arrayed output from the for loop, not just the final iteration of the for loop.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 2 of 8
(3,470 Views)

Thanks for your reply. I'm trying to pass data out at each iteration of the for loop. I've attached a copy of the VI to this reply. maybe you can help me figure out what I'm doing wrong.

 

Thanks again.

0 Kudos
Message 3 of 8
(3,464 Views)

I'm afraid I have to leave the office, so I don't have time to scrutinize your code, but the for loop appears to generate a 2D array of data ok. The data is then converted to the Dynamic Datatype, which I'm not very familiar with, before using the Express Write Measurement to File. I would have thought that express function would handle the data correctly, but I'm not sure at the moment (I tend not to use the dynamic waveform type, nor express VIs).

 

If no-one else has looked at this for you in the next 16 hours, I'll be back in the office to take another peek by then Smiley Happy

Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 4 of 8
(3,456 Views)
Solution
Accepted by edCubed

The loop will pass out all data as a 2D array (one row/iteration) and append it to the file. However, your "SM average output" scalar indicator will only show the value of the last inner iteration. If you want to see all values in sequnce, place the indicator in the innermost loop.

 

You also clear previous errors with each iteration, so you might not see all errors.

 

As a general rule, you have way too much duplicate code. For example your inner loops share a huge amount of code. All that needs to be in the case structure is the code that is different, right. Here's how you could simplify it. (this is just a draft and probably has errors).

 

There is also "ramp pattern" that you could use to simplify things much more.

Message 5 of 8
(3,439 Views)

Thanks for cleaning up my code. It's working just fine now.

 

I'm curious if there is a good way to auto index through a case statement or is that something I should avoid doing in the future?

0 Kudos
Message 6 of 8
(3,423 Views)

Case structures execute only once, therefore you cannot 'auto-index' your wires at their borders. Any wire passing through the border of a case statement is unaffected by that border. The point of a case structure is to allow different code segments to execute dependent on the assessment of the conditional terminal input, but in all scenarios only one case will execute. If you wrap the case structure in a for loop, it is at the for loop border than auto-indexing can be enabled.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 7 of 8
(3,407 Views)

edCubed wrote:

I'm curious if there is a good way to auto index through a case statement or is that something I should avoid doing in the future?


I don't know what you mean by that terminology. You never "autoindexed throught a case structure". You autoindexed at a FOR loop boundary and the FOR loop contained a case wired to the iteration terminal. There is nothing wrong with that.

0 Kudos
Message 8 of 8
(3,396 Views)