LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to make VI wait until data is saved before it can open and read data

I have developed two VIs for continuous monitoring. First VI is for acquiring raw strain data and saving it into a folder, let's say, every 10 minutes or every 100 Mbyte of data (for example, after monitoring for an hour, the folder will have 6 files, each of which contains 10 minutes of data). Second VI is for opening/reading/processing data files collected by the first VI.   Right now, this second VI can handle only one file at a time. What I am trying to do is to have this second VI open the files one after another automatically. Also (here is what I think will be difficult part), I want the second VI recognize that a file is saved by the first VI before opening it (i.e., wait until the first 10 minutes of data file is saved by first VI, open and process this first data, wait until the second 10 minutes of data file is saved by first VI, open this second file and process it, wait until the third 10 minutes of data file is saved by first VI, open and process it........). Any help or comments would be appreciated.
 
Thanks in advance for your help.
 
Brdg.
 
 
0 Kudos
Message 1 of 7
(3,409 Views)
Not sure what exactly you need but here are some options for avoiding simultaneous access:

1... Use an occurrence. The DAQ thread triggers it AFTER it writes the file. The processing thread waits on occurrence, then opens the file and reads it.

2... Use a queue. The DAQ thread enqueues the file name (or path) it just wrote into a queue. The processing thread waits for names available - when it gets one, it does its thing.

3... Write the files with DENY READ permissions. The processing thread will then get an error if the file is still open from the DAQ thread.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 7
(3,395 Views)
As I am still trying to learn labview programming, I am not sure how to use occurrence/queue/permissions. I am attaching the second VI that I explained in previous message and some of sample data files. Could you show me how to use those functions? As I said previously, these samples are collected and saved by the first VI and I want the second VI (attached in this message) recognize if a file (saved by first VI) exists in a folder before it opens and processes the saved file, and I want to plot all the data on a XY graph (one after another and all together) as they are saved by the first VI.
 
Thanks.
0 Kudos
Message 3 of 7
(3,389 Views)
Basically, If your purpose is to keep one thread from opening the file until the DAQ thread has finished with it, then the queue is what I would use.

All functions are on the ADVANCED | SYNCHRONIZATION | QUEUE palette.

Use the OBTAIN QUEUE to create the queue. Set the DATA TYPE to a PATH constant. This creates a queue of paths. Pass the QUEUE REFNUM to both the DAQ VI, and the PROCESSING vi.

In the DAQ VI, when you write a file, take the PATH from the CLOSE FILE function and use ENQUEUE ELEMENT to put it into the queue (use the refnum you passed in).

In the processing thread, use DEQUEUE ELEMENT to fetch the path from the queue. You probably should use a timeout value of 1000 mSec or so. If you timed out, go check your PROGRAM RUNNING flag (so you can stop without waiting forever on the queue), and if you're not stopped, try again.

If the DEQUEUE ELEMENT returns WITHOUT a timeout, then open the path it gives you - the file is guaranteed to be closed, since you closed it before you enqueued it.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 7
(3,380 Views)
Can you show me with a simple example how those can be done?   I am pretty much new to Labview and your explanation sounds like it is a different language to me.
 
Thanks.
0 Kudos
Message 5 of 7
(3,368 Views)
There are examples of queue usage in the EXAMPLES folder.

Run your example finder and search for "queue".

You might also want to look for "occurrence" examples. The difference is that a queue can "pile up" things to process (more than one); an occurrence is simple a trigger notification thar something has happened, and cannot hold more than one.

Alternatively, when you NEW the file (to write to it in the DAQ thread), you could set the DENY MODE input to 0 (Deny R/W). This means that if your processing thread tries to open that same file WHILE YOU'RE STILL WRITING IT, it will get an error (sharing violation). You can react to that error, by waiting a while and trying again.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 7
(3,356 Views)
Thanks a million. I will look into that.
0 Kudos
Message 7 of 7
(3,337 Views)