LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read from a file line by line

Hi
 
I am new to using LabView and was wondering how I could read data from a text file one line at a time and display this data one line at a time as well. I tried looking through the Reading from Text File . vi example but that just seems to be reading and displaying everything together.
 
Thanks
-Karan
0 Kudos
Message 1 of 13
(31,095 Views)
Hi Karan,

I'd not done this before myself.  But I thought I'd have a quick crack at it to see what I could come up with.

This VI isn't complete.  But it should give you some ideas. 

My guess is that you wanted to split your existing text file into one line text files and maybe do something with them after.  The first screenshot should give you some ideas there. 

If all you want to do is display them, the second shot does that. 





Message Edited by pallen on 02-18-2007 07:14 PM

---------------------
Patrick Allen: FunctionalityUnlimited.ca
Download All
0 Kudos
Message 2 of 13
(31,080 Views)
1... Use FILE I/O - ADVANCED - OPEN FILE, with the path to your file as an input.

2... Use FILE I/O - ADVANCED - EOF to get the EOF of the file.

3... Enter a WHILE LOOP.

4... Within the loop, Use FILE I/O - READ FILE, with the refnum as an input, and wired LINE MODE to a TRUE constant.

5... Display the string out of READ FILE.

6... Wait a while, just for visual effect, if you want to.

7... Compare the OFFSET out of the READ FILE to the EOF from step 2.

8... If OFFSET is >= EOF, terminate the loop.

9... Close the file.

Message Edited by CoastalMaineBird on 02-18-2007 06:18 PM

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 13
(31,082 Views)

Hi

I was looking at the post above this one and was just wondering how to use and where to find the FILE I/O - ADVANCED- EOF function. Also, what would need to be to keep track of the offset to compare it with this EOF?

Thanks

-Karan

0 Kudos
Message 4 of 13
(31,024 Views)
where to find the FILE I/O - ADVANCED- EOF function.

Maybe they've moved it for later LabVIEW, but I was referring to the ADVANCED palette under the FILE I/O palette.

Message Edited by CoastalMaineBird on 03-01-2007 08:54 PM

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 13
(31,013 Views)
Hi
 
My aim is to read text line by line and to then go ahead and display the last 8 reaad lines of code to give the impression of text falling down a screen. I tested the first while loop and that seemed to work fine. However, when I encounter an EOF, I would like the text already read to keep making its way down the screen and keep inputting NULL characters into the array to simulate the effect of the text falling down the screen which is why I created the second while loop. I tried to input the NULL characters using a box for ENUM constants. However, I kept getting an error saying the data types do not match. What would I need to do? For the display I plan on putting indicators next to the 8 places where the text would be stored which I have not done so far.
 
I am also attaching a copy of the error.
 
Thanks
-Karan
Download All
0 Kudos
Message 6 of 13
(30,985 Views)
An enum is a U16 data type. That is why the icon is blue on the block diagram. Your shift register is a string data type. An enum with a label of 'NULL' is not the same thing as an ASCII Null character. An ASCII null is hex 00 which you can specify with a string constant set to Hex display.
0 Kudos
Message 7 of 13
(30,962 Views)
I think you have to rethink your code from the ground up.
 
Why do you have two loops at all?
 
Just read the entire file at once (not line by line) and use a single loop to first display it line by line and then prepend linefeed characters (I have no idea why you think a NULL character would scroll your text).
 
For some reason, you never close your file.
0 Kudos
Message 8 of 13
(30,956 Views)
Here's a quick draft (LabVIEW 8.0) for one possible solution. Makes sense?
 

Message Edited by altenbach on 03-04-2007 09:27 AM

Download All
Message 9 of 13
(30,951 Views)

Hi

Thanks a lot for your replies. I had 2 questions about the solution above. Do I have it right that the entire file is being read at one go? Also, intitially your 20 element array is initialized with 0A? Where exactly during the execution is the 0A lost so that it does not appear on the screen when text is being displayed? Also, where exactly in the flow is the whole file that has been read broken up into lines so that the text to be displayed can be identified in each line and then replace an element in the other array with the same size. What I mean is the how is the text file that you have read broken up into lines so that pattern matching ( regular expressions) can be done for each line now that you have introduced the fact that all the lines have been read from the text file as one big chunk?

Thanks

-Karan

0 Kudos
Message 10 of 13
(30,930 Views)