LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read data from a txt file

I have a data txt.file. I want to read each data from this file. What should I do?? Thanks
0 Kudos
Message 1 of 10
(4,503 Views)
The attached vi shows one way to do this. There are other methods. You could open the file, read a line of data, then wire the data string to Spreadsheet String to Array. The main thing is to know what data is in the file so that you can use the correct format string (%f for floating point numbers, etc).
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 10
(4,493 Views)
thanks for your post. My problem is I need to read each data seperately and output each data to the front panel seperately. Not just read the line of all the data.
Any suggestion?? Thanks
0 Kudos
Message 3 of 10
(4,490 Views)
Why can't you just read the entire line and handle each piece of data separately? If you really want to just read one piece of data at a time, you will have to open the file, read from file and specify the number of bytes (a DBL is 4 bytes), convert string to number, then loop again but this time you have to set your file read position offset to the next element (byte #5). This is much more difficult than just reading in an entire line and separate the data into different indicators like I did in my example, then just handle the data as you want. You don't have to display it all at one time, just delete the indicators for data 2 through 6 and just leave the first indicator. When you want to look at the next piece of data, just wire the output from the second data to wherever you want. See attached vi.
- tbob

Inventor of the WORM Global
Message 4 of 10
(4,476 Views)
Isn't that what tbob's example does? Each value in the line is written to individual indicators. There are several other file read functions. If you don't like Scan From File, try Read Lines from File, Read Characters From File, Read From Spreadsheet File.
0 Kudos
Message 5 of 10
(4,473 Views)
Sorry, My labview is 7.0. I can not open the vi in 7.1
0 Kudos
Message 6 of 10
(4,469 Views)
I have similar question, so I ask here ( I hope jli don’t mind ?)

my file structure :
2005.02.17 17:01:09 0,5109 0,9977 0,4341

Date/Time data from sensors 1,2,3

What I would like to do is to read file and diplay data on chart with date/time on x axis ( So I have to covnert 2005.02.17 17:01:09 to timestamp format ?). Also I would like to select period of date/time ( for example from 2005.02.07 17.00.00 to 2005.02.08 17.00.00) and display only that period on chart. Also I need to save selected period of data to separate file.
Can I read a file while other part of VI is writing data to file ? ( data logging to file is running continiuosly and user sometimes want to see and save some part of data to separate file).
I am not limited to text file, but user must have ability to export selected period of data to Excel file for analysis outside VI.
0 Kudos
Message 7 of 10
(4,464 Views)
Do you have Labview 7.0, I only had that version so that I can not open your file .
0 Kudos
Message 8 of 10
(4,449 Views)
Same vi in 7.0
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 10
(4,435 Views)
I would not attempt to read from a file and write to it at the same time. You could run into big problems, file size changes, current file pointer changes, etc. You should use Notifiers or Semaphores or something to lock out one process while doing the other. Example: before you read, aquire a semaphore, read, then release the semaphore. Same thing with write: aquire, write, release. That way you won't have a clash of read/write processes. If the read process is in progress and the write wants to start, it will see that the semaphore is locked and it will have to wait until the read releases the semaphore before it can aquire then write. If you are not familiar with semaphores, search the examples folder for some examples.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 10
(4,429 Views)