From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open/close file in while loop

VI reads 3 temperature sensors connected to RS232 port ( external rs232/RS485 converter , sensors have different addresses). When VI starts , user is asked to chose location and filename of data log file for each sensor ( write to the same file or to new file).
3 START/STOP buttons controls data logging from sensors. Right now it just starts or stops data reading from sensor and writing to file. What I would like to have is that user is asked to enter file name and location not when wole VI starts, but when he START/STOP button is pressed. ( When user press button 1, he is asked to enter file name and location. When data logging from that sensor is stopped, file is closed. When data logging is started again, user again must select data log file). The same for START/STOP buttons 2 and 3.
0 Kudos
Message 1 of 7
(3,622 Views)
Hello.

The short answer is that you have to put the "Open/Create/Replace File.vi" inside the case stucture, so that that executes each time a button is pressed. You should also be closing the files after you write to them, which I did not see you doing in your VI.

I am attaching a modified version of your VI which should perform what I understand you want. I am using the "Write Characters To File.vi" which is an easy top level VI for writing data to files, which opens, writes and closes the file each time it is executed.

I also removed the local variables and used the boolean buttons directly inside the sequence structure. In general, you should avoid the use of local variables unless it is absolutely necessary.

Hope this helps.

Alejandro
0 Kudos
Message 2 of 7
(3,606 Views)
Hi Alejandro,

you gave my some ideas, but in your code file dialog window pops every iteration.
0 Kudos
Message 3 of 7
(3,596 Views)
Hello.

I am sorry about that. I forgot to set the mechanical action of the boolean buttons to "Latch when released". In general, any boolean button that you have inside a loop should be set to this type of mechanical action to ensure that the action occurs only once when you click once.

The attached vi is the same as before, but with the buttons set to "latch when released" (by right-clicking on them and going to mechanical action).

Alejandro
0 Kudos
Message 4 of 7
(3,578 Views)
This VI also dont works. I need continuos data logging to file, when button is ON. When user after some time press button and button is in OFF state, data logging stops and file is closed. When user again press button , data loggings starts again.
0 Kudos
Message 5 of 7
(3,562 Views)
Hi.

OK, this time I think I did understand what you want the program to do. Here is another attached VI, which hopefully will work for you.

Let me know if it doesn't.

Good luck.

Alejandro
0 Kudos
Message 6 of 7
(3,555 Views)
It is working, thank you.
Now I need to think how to implement few more things:
User must be prompted for filename when he turns on data logging ( now if cycle delay is 5 seconds, you must wait for dialog window 5 seconds after you press button)
Default file name suggestion for each sensor file
Generate new file, when file size reaches some limit.
0 Kudos
Message 7 of 7
(3,538 Views)