LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

writing a serial string to ascii file

I have a VI that polls two different devices and returns two different length strings. First it polls a device that returns a string with three parameters (temp, pressure, humidity). In the VI I switch channels and poll the other device which returns a string of two parameters (wind speed and direction). How in the world do I write this information to an ASCII file and have it know which information is which and keep them separate in the file?
0 Kudos
Message 1 of 20
(3,690 Views)
Set the Write File to append. Then each time you write, the data will be added at the end of the file. Since you are writing to text files, you can concatenate any string data with your instrument readings. For example, you could prepend "Temperature " to the temp reading.

You could make a spreadsheet compatible file by separating the data with tabs and rows with carriage rerturns. You would need to keep track of which instrument was feeding which columns and format appropriately. If you get different numbers of reads from each instrument, you would need to define what to dowith the unfilled cells.

For more professional and easier to decode approach look at XML tags to identify and delimit your data.

Lynn
0 Kudos
Message 2 of 20
(3,688 Views)
Thank you,
I have never done the "write file" before, so I'm not sure what the "append" is. My program is in case structures and there is a case where it switches from channel 0 to channel 1. Then it goes into a case where it is reading the string from channel one. Where do I put the write file function? Do I close it upon leaving this case? Then switch to channel 0 open the write file and start writing for this channel? I have no idea where to put the write file or how to set up the file for writing to.
0 Kudos
Message 3 of 20
(3,683 Views)
Perhaps you should post your VI. That will make it easier for us to see what you are trying to do.

I like to use an architecture which has separate, parallel loops for the user interface (UI), data acquisition, and other processing (such as writing to files). This allows each to run at different time scase as appropriate to the needs.

For your case the data acquisition loop would poll the two devices and read data when available. It would send the data via queues or functional globals to the processing loop along with an identifier telling which source generated the data. The processing loop would do any calculations, format conversions, etc., and write the data to the file. The Write Characters to File.vi has a boolean input called "append to file?" which controls wheter the data being written is placed at the end of an existing file or starts a new one. The processing loop also send any data to the screen for the user interface as well as receiving commands from the UI.

Lynn
0 Kudos
Message 4 of 20
(3,673 Views)
Append means to add data to the end of the file. Here is an example of a loop that generates a random number and appends a title string followed by the number to an open file. The file is opened before the loop, and closed after the loop. After running you can open the created file (C:\Temp.txt) and see the serial strings that were written to the file.
- tbob

Inventor of the WORM Global
Message 5 of 20
(3,663 Views)
Thanks TBob,

Can you convert your vi to version 7.0 or 6.1?

-JLV-
Message 6 of 20
(3,653 Views)
Lyn,
The VI is on a computer other than the one I use in my office. I am waiting for the laptop to return so I can copy the VI and post. Thanks.
0 Kudos
Message 7 of 20
(3,537 Views)
Thanks you! This is great but I am not quite sure where I would insert this into my VI in order to capture the data each time it reads. As I mentioned I also switch channels and the string is of different lengths or types so would I have to put this in twice? I'll post VI this afternoon.
0 Kudos
Message 8 of 20
(3,637 Views)
This VI was meant to serve as an example of how to write sequential strings to a file using the append mode. Study it and see how it works. Then write your vi to fit your needs. You cannot just simply insert this vi into anything. It is just a demo. Try writing your vi on your own, this is the best way to learn. If you need further help, post what you have written so far and someone here will help you.
Here is the same vi in version 7.0 for JLV.
- tbob

Inventor of the WORM Global
Message 9 of 20
(3,626 Views)
No offense but I've been trying to write my own VIs for quite sometime. The question I asked involved a somewhat more complicated task than I'm used to and I was (still) having problems figuring out how to capture a string when the program changes channels as well as string length. I wasn't asking you to write it for me but simply asking how it works or "suggest" where in the program and how it may fit.

Sometimes you hit a road block and the only way to learn a new route is to have someone help.
0 Kudos
Message 10 of 20
(3,603 Views)