03-26-2013 10:29 AM
In the vi I attached earlier, I assigned the text file where I needed to save and selected 'end' in the set file position option. It still saves just a single value. Do I need to do any change in the vi back/front panel ?
Thank you,
vzv
03-26-2013 10:38 AM
You problem is you are setting the file position AFTER write to the file. You need to open, set position to end, write, and close.
03-26-2013 10:53 AM - edited 03-26-2013 10:54 AM
And don't use Run Continuously. Use a while loop around the code that needs to continue to run, with a stop button control to stop the while loop. Right now you are forced to use the abort button which is not a good idea. It will leave your com port hanging open.
1. Open the com port and the file before the loop.
2. Read the com port and write to the file in the loop..
3. Close the com port and the file after the loop.
03-26-2013 11:31 AM
I have modified my VI as per your suggestion. I still have only one data on my file. Can you have a look at the attached VI and let me know where I might have gone wrong.
Thank you,
vzv
03-26-2013 11:46 AM - edited 03-26-2013 11:48 AM
1. You aren't saving the data. Your Write to Text File should be inside of your loop where you read that data. What you currently have for the Write to Text File should really be Create/Open/Replace File with the operation set to Open.
2. When you set the file position, set the enum to "End" (and change it to a constant).
03-26-2013 11:49 AM
@RavensFan wrote:
And don't use Run Continuously. Use a while loop around the code that needs to continue to run, with a stop button control to stop the while loop. Right now you are forced to use the abort button which is not a good idea. It will leave your com port hanging open.
1. Open the com port and the file before the loop.
2. Read the com port and write to the file in the loop..
3. Close the com port and the file after the loop.
Nothing more embarrassing than leaving your com port open.
03-26-2013 11:51 AM
I worked a little bit since I attached my last vi file on the grounds you suggested and I think its working like I intended it to. It is able to store multiple values in the text file. Can you have a look at this newly attached VI and the output file. Also how could I attach a time value to this data. The one in the text file shows a reading for every 5 sec. Is there a way I can incorporate this info with the data I obtain?
Thank you,
vzv
03-26-2013 11:56 AM
Let me say this again. SET THE FILE POSITION AFTER OPENING IT BUT BEFORE WRITING. In other words, put the Set File Position outside of the while loop immediately after opening the file. And be sure to wire your file reference through in the false case of the read case structure.
03-26-2013 12:09 PM
Hi Crossrulz
Thanks for your input. I have attached the VI modifying on your suggestion. It doesn't show any error. Can you see and tell me whether I did it right?
I am a novice with programming and this is my first. Kindly ignore any stupidity I do.
vzv
03-26-2013 12:42 PM
vzv,
I see only one mistake, one which crossrulz already mentioned in an earlier post: You need to wire the file reference through the False case of the Read case structure. If you run the program and set the Read button to False before hitting the Stop button, the file will not be closed. The reason is that the output tunnle has a small white dot at the center. This indicates that the tunnel is set to Use Default if Unwired. The Default value is no path or at least not the correct path for the file you have opened. Generally the use of Use Default if Unwired is not a good idea unless you have a specific reason for doing so.
The other issue is cosmetic only. It is much easier to read, understand, and troubleshoot a program if the wires are as straight as is practical and definitely not hidden behind other objects. See below for a nicer way to wire the file reference.
Lynn