LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write data to .txt file with formatting

Hi,

 

I am trying to read data from serial port and write it on to a .txt file. I am able to write onto the file but it has got no formatting. What I would ideally like to do is, read the data from serial port, take only some parts of it and write on to the text file with proper formatting. Also, I would like to use the same file to append data each time. I am also having issues setting the pointer to EOF. I would like to append to end of file.

 

This is my sample data

18:33:23 02/10/10 28.32             0 LAC     0.378 mg/dL    0000\
18:33:23 02/10/10 28.32             0 GLU       102 mg/dL    0000
that is being read from the serial port. From this I would like to take only columns 1,2,3,5,6 and write onto the .txt file.

 

Can someone provide some pointers? I'm using Labview 6.1

 

Thanks,

Sukanya

0 Kudos
Message 1 of 5
(4,083 Views)

I found out the reason for the loss of formatting in the .txt file. The actual data has some spaces and other things appended at the beginning. It's something like this "\s\s\s\02\n\s\s\s\88" but it appears as space and some random characters. Is there a way to remove these things before writing onto file?

 

 

0 Kudos
Message 2 of 5
(4,072 Views)
If you know what "charecters" you don't want it is pretty easy. A little more difficult when they are unwanted only in certain places in the string. There is a remove whitespace function in the string functions palette. There is also a search and replace function in the "additional string functions" subpalette, that can be set up to find all instances of a char and replace it with something else, an empty string if you want to just delete it/them from your string.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 3 of 5
(4,061 Views)

You can read in the string, and break it into individual elements by either whitespace or tabs.

Then when you get to a carriage return, you know the line is done.

 

By breaking the string up into elements, you can build an array with only the columns you want.

Then you can write the columns to a text file using "write array to spreadsheet file"

Cory K
0 Kudos
Message 4 of 5
(4,055 Views)
Oops, I don't think the trim whitespace function was added until LabVIEW 8.something (8.2 maybe?).
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 5 of 5
(4,041 Views)