LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Last row of data in a 2d array isn't writing but is written when VI is run next time

Solved!
Go to solution

Hello everyone,

 

I am having problems with writing data. I am taking some statistics from a bunch of .tdm files and recording them to a master file. I have all of that down, but the last part of the data is not written when the program is first run. When I run the program immediately afterwards, the last row of data from the first run is the first row of data recorded. I assume that the buffer that holds the array is not being emptied at the end of the program, but I do not know how to 'flush' an array or if such a method exists(I know it does for queues, but arrays are supposed to be more simple). I have tried including a priming read before the main for loop because I thought this issue was an off by one issue. This didn't fix the issue. For example here's what the data would look like:

1st run :

A

B

C

D

 

2nd run :

E

A

B

C

D

 

I have included my code and if you all see something that I can do to fix this, please let me know.

 

Thank you for your time,

Seth

0 Kudos
Message 1 of 4
(2,488 Views)
Solution
Accepted by topic author sethmurphy

My guess is the race condition you have created by using local variables.

 

You have local variables of min array, mean array, max array, cycle count, and channel names that you are using to write to a file.  However the terminals are readily available that you could branch wires directly from

 

The problem is the race condition.  Your local variables will be read very early in the iteration of the For Loop, before any valid data has been written to the terminals that those locals refer to.

 

Don't use local variables, just use wires.

0 Kudos
Message 2 of 4
(2,484 Views)

Thanks!

That fixed it. So when is it appropriate to use local variables? I looked at some of the tutorials on them, but they didn't really specify. Are these just things that should be avoided?

0 Kudos
Message 3 of 4
(2,460 Views)

If you can use a wire, use that instead of a local variable.

 

If you don't care about the order that value is written or read, then a local variable is okay.  For example.  If you are using a boolean to pass a stop condition that is determined in one loop (and written to a local variable), then you can read from that local variable in other loops to stop them.

 

As long as you completely understand how they work and the read vs. write, and how that can affect your program, then it can be okay to use them.  If you don't understand and use them in the wrong circumstances, then they'll bite you as they did in this situation.

0 Kudos
Message 4 of 4
(2,456 Views)