03-20-2018 08:55 AM
Hi,
In my project I need to store data once a second, but in the meantime there'll be other stuff going on.
I succeeded to make the data store once a second by adding a wait function, but that made the whole VI run once a second, which is obvious.
I tried putting the data storage section in a case function that gets triggered once the Elapsed Time function hits 1s. See the added screenshot. But that doesn't work either for some reason, what's the best way to get this sorted?
Solved! Go to Solution.
03-20-2018 09:07 AM - edited 03-20-2018 09:08 AM
You don't need to write to disk once per second. You need to acquire a data point from your input tests once per second. Use two loops. One for data acquisition, and one for data logging to disk. Make the acquisition loop a timed loop, or a while loop with timing controlled by timing functions. Use the loop timing to poll your input data at the desired rate, and write the data to a queue or other buffer within that loop. In the acquisition loop, which can run much slower (subject to the risk of losing data in the memory buffer if something goes wrong with the hardware), you read the data out of the queue and write it to disk. If you use a timed loop for acquisition, that will always take precedence so your data points remain equally spaced, while disk writes will execute at a lower priority.
03-20-2018 09:07 AM
Hi Rofid,
But that doesn't work either for some reason, what's the best way to get this sorted?
Well, you should start debugging to get this sorted!
What is the reason it doesn't work (as intended)?
Is this comparison result (greater 10) as expected?
- Cleaning up your VI and then uploading it instead fo a screenshot would be a good idea, too.
- Why are there controls without a label?
03-20-2018 09:24 AM
Hi Rofid,
What do you mean by "it doesn't work either" ? How is your Elapsed Time Express VI configured ?
I understand that you have another part of code running at the same time. What does it do ? Are both codes independant ?
Please provide us with as much info as possible so that we can work out the best solution (a VI is always better than a picture for example) 🙂
03-20-2018 10:34 AM
Sorry for any misunderstandings, I added the VI.
In the VI is the method I tried the first time, because it looked like the easiest way to do this.
The problem I got is that the timed loop would run once a second as intended, but the rest of the while loop would do so too!
That's why I tried the Elapsed Time method, because I hoped that'd trigger the case to execute the case once, but it would never run it.
The input tests is always on, all the code inside of the case loop works perfectly, I can time that easily if I'm just trying to log data, but implementing it with the rest of my code is the big problem.
03-20-2018 10:47 AM
Hi Rofid,
your VI after cleaning up a little bit:
This should run in parallel to the rest of your code.
Whenever something should run in parallel then there should be no data dependency between those code parts! (THINK DATAFLOW!)
03-20-2018 10:49 AM
Your timed loop should not be contained within another loop. Also, you have it set to stop execution on the second iteration. What is happening here is that the outer while loop is executing, the timed loop is entered and executes once, on the first iteration i=0, 1000 ms later, the timed loop executes a second time, and i=1 and the timed loop exits.
Your timed loop needs to stand alone, in parallel with your while loop - not nested within it. Share data between loops using queues, channel wires, functional global variables, etc.
The rate at which you need to acquire data, and the rate at which you need to log that data to disk are probably not identical, so don't constrain them to be. Granted, a 1000 ms period is not taxing at all, but combining these functions means that your code is not scaleable or easily modified to accommodate a different acquisition rate.
The exit condition on your loops should be to exit only when commanded, or on error. If you only need a predetermined number of iterations, use a FOR loop.