LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Facing some problem while writing txt file with start stop button

Solved!
Go to solution

Hi

 

I am trying to use this start stop program i found while surfing around this great discussion forum. actually i want 

to write data in a text file when i press start button and it should stop writing when stop button pressed and 

after that when ever i press start button again it should prompt me for new file name. right now even if i change the

file name in the path dialog box it gives me error when i try to stop the program by pressing stop button. 

need help to fix this problem. VI is attached with this post.

thanks

looking forward..... Hussn

Download All
0 Kudos
Message 1 of 9
(2,943 Views)

Hi Hussain01.

 

I'm Oli from National Instruments UK.

 

I understand your having some problems with File I/O in your LabVIEW program.  Just to check, you want your program to prompt the user to enter a file name and location whenever the start button is pressed, then to carry out your code and write the data to the file when the stop button is pressed.

 

I've had a look at your code and there a few things you can do to change the behaviour of the file handling.

 

I have a couple of questions.

 

1. Do you want your VI to continue to execute after the stop button has been pressed so that you can immediately press the start button again to write a new file?

2. Do you want the program to automatically assign a name to the file each time the start button is pressed or do you want the user to enter a name?

 

I look forward to your reply.

 

Regards,

Oli
LabVIEW Student Ambassador
National Instruments UK
0 Kudos
Message 2 of 9
(2,915 Views)

Hi Oli thanks for reply 

 

i want that when the user press start button it will ask user to give a new file name. and continue writing data until user press stop. i dont mind if the program stops completley, and whenver user press start button again it will ask for new file.

 

hussain

0 Kudos
Message 3 of 9
(2,910 Views)

Hi Hussain,

 

Another couple of quick questions.  What is your LabVIEW experience like and what version of LabVIEW are you using?  Thanks.

 

Ok, so working from your existing code, let's first implement the file opening problem.

 

If you first remove the File Path Control from the Open_Create_Replace File VI, then that will make a dialog appear for the user to choose where the file is to be saved.  If you want a specific message to appear in the dialogue, you can add a string constant to the 'prompt' terminal of the Open_Create_Replace File VI.

 

Assuming you don't want to overwrite existing files by mistake, it would be a good idea to change the function constant from 'create or replace' to 'open or create'.

 

Hope that helps.

 

If you want to implement that and post back when you're done, I'll get started on the next part for you.  I can post snippits if that helps you too.

 

Regards,

Oli
LabVIEW Student Ambassador
National Instruments UK
0 Kudos
Message 4 of 9
(2,899 Views)

HI Oli

 

i am using LABVIEW2010 and operating system is WIn7 64 bit. thanks for suggestion now i am thinking that rather than asking for new file name from user i will creat a new file every time with a time stamp. i did that so here is my 

new code. 

 

Download All
0 Kudos
Message 5 of 9
(2,894 Views)

Hi Hussain,

 

Great idea with that file name code.

 

The next step I would suggest is to simplify the program a little.  You are currently using global variables, which seem a bit unnecessary for what you are doing.

 

These are the steps I've performed so far:

 

1. Take the stop button control out of the Timed Loop and move it into the main While Loop.

2. You can delete the Timed Loop and the While Loop that it is in now.

3. In the remaining While Loop, replace the Global Variable 'STOP_VI' attached to the loops conditional terminal.  You can also remove the Not and the two other Global Variables from outside the loop.

4. Create a Compound Arithmetic.  Change it's function to OR (Right Click > Change Mode).

5. Attach the Stop button control to the Compound Arithmetic input.

6. Connect the Compound Arithmetic output to the While Loop conditional terminal.

7. Switch to the Front Panel and rename the stop button to 'STOP VI'

 

It is good practice to stop the execution of your program when an error occurs.  To do this:

 

7. Switch back to the Block Diagram. Create an 'Unbundle By Name' and place it near the Stop button control.

8. Connect the error wire to the input terminal of the Unbundle By Name from the Tunnel on the right of the Case Structure.  You will see the contents of the Unbundle by Name change to 'status'.

9. Connect the 'status' output to the Compound Arithmetic.

 

Now your program will stop itself if there is a problem with the file I/O (as well as any other errors).

 

Now we need to replace the functionality that we removed when we deleted the Global Variables.

 

10. Change to the 'Wait_for_Start' case in the Case Structure.

11. Replace the Start Global Variable with the OK Button (Start Button) Control.

12. Change the True terminal constant of the Select function to 'Acquisition'.

13. Switch to the 'Acquisition' case in the Case Structure.

14. Switch to the Front Panel and create a new Stop Button.

15. Switch back to the Block Diagram. Replace the Start Global Variable with the new Stop Button Control.

 

So now your program will automatically name and open a file, write to it when the Start Button is pressed, stop writing to it when the Stop Button is pressed and will only stop execution when the STOP VI button is pressed or there is an error.

 

I've attached a copy of your VI with any edits I have made for reference.  If you post back when you've got that working, then we can make a start on allowing the program to initialise a new file each time the start button is pressed if you want to.

 

Regards,

Oli
LabVIEW Student Ambassador
National Instruments UK
0 Kudos
Message 6 of 9
(2,878 Views)

Hi Oli 

thanks for the reply. can you post it again with my compatible version because i have Version 10.0.1?

 

thanks

 

 

0 Kudos
Message 7 of 9
(2,873 Views)
Solution
Accepted by topic author Hussain01

Hi Hussain,

 

Sorry about that!  Attached the wrong one.

 

Here you go.

 

Regards,

 

Oli
LabVIEW Student Ambassador
National Instruments UK
Download All
Message 8 of 9
(2,849 Views)

Thanks i will try and get back to you soon 

 

 

0 Kudos
Message 9 of 9
(2,847 Views)