LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I open the file only once?

Hello everyone,

I am using a while loop timed 50 mecs to access sensor data. I would like to use this loop to write data every 1000 msecs to a file. However I have 2 problems in the VI I have attached :

 

1)I want the user to be able to start writing to the file when ever he wants. That is to say , I don’t want the saving to start when the program starts ( like the attached program does ). So I tried to put the "open file" in the while loop and use structure events so that it doesn’t "open the file" every 50 ms but just writes in it. But I couldn’t make it work correctly. Would u have any idea how to do this?

2)My second problem is that it seems that the writing timed to occur every 1000ms does one more 50 ms turn. That’s why I sometimes record every 2 secs instead of 1 sec. I have made many changes ( changing the initialisation, ….) without any success.

Any help would be really great

Regards,

David

0 Kudos
Message 1 of 3
(2,661 Views)

Hi Mark,

I can't look at your posted vi because I don't use LV at work (at the moment).  However, you should use the Open File vi and pass the file reference into the while loop. At the exit of the while loop, you can use the Cloe File vi.

Please note that there is a time delay for each iteration of the while loop, including the time delay for the write to file process.  What you can do is have a "delta" counter that keeps track of the time spent in the while loop and subtract the delay to the time to write value.

Ex:  TimeToWrite = 1000 ms

       whileDelayTime = 10 ms

       TimeToWrite = TimeToWrite - whileDelayTime

It may not be 100% accurate, but it's an easy way to correct the next write cycle and should average out to give you reasonable accurate samples... Unless you need something more accurate.

Regards,

JLV

😄

Message 2 of 3
(2,651 Views)
About additional 50 ms.
 
"Left" shift register initializes by 0. "Rigth" initializes by 1. The time-to write comparison is "number greater then 20". So the first writing will be after 21 iteration, and the others writing will be each 20-th iteration.
 
 
I am sorry, my English is poor.  . I hope somebody can understand me Smiley Sad. .

Jack
Win XP
LabVIEW 6.1, 7.0, 7.1, LabWindows/ CVI 7.1
Let us speek Russian 🙂
Message 3 of 3
(2,642 Views)