LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read from a text file line by line

Hi,

I am new to Labview and I am trying to output a text file line by line. For example if my text file is

 

START

SETRPM 1000

WAIT 10s

RAMP RPM linear,1000,2000,2 MAF linear,5,7,2

WAIT 5s

RAMP RPM sine,2000,1500,3 MAF sine,7,3,3

END

 

I want it to output

 

START

SETRPM 1000

SETMAF 5 ...and so on

 

I tried modifying this code provided by Altenbach but it is still not working as I want it to. Can anyone direct me toward how I can fix this?

Thank you!

 

0 Kudos
Message 1 of 11
(9,543 Views)

You can right-click on Read From Text File.vi and check read line. The output will be an array of strings (each string being a line of the text file). You can then just index the array to get the lines.

 

Ben64

0 Kudos
Message 2 of 11
(9,531 Views)

@ni359 wrote:

I tried modifying this code provided by Altenbach but it is still not working as I want it to. Can anyone direct me toward how I can fix this?

Thank you!



I would prefer if you don't associate my name with some random code, especially after you modify it.

 

If you refer to any code I have posted in the past, you need to always include a link to my old post to retain proper context. Thanks!

 

0 Kudos
Message 3 of 11
(9,525 Views)

Sounds good. Sorry about that, this was my first time posting in here. I did not mean to take credit for work I did not fully do, thats why.

Here is the link: http://forums.ni.com/t5/LabVIEW/How-to-read-from-a-file-line-by-line/m-p/479838/highlight/true#M2306...

0 Kudos
Message 4 of 11
(9,499 Views)

Yes, that very old post is for a very different task.

 

You want to read the entire file and then display it line-by-line with some delay between lines. As has been suggested, set the file read mode to "read lines" and then autoindex on a FOR loop, appending each new line to the existing string contained in a shift register. The string terminal needs to be inside the loop.

 

See how far you get.

0 Kudos
Message 5 of 11
(9,479 Views)

I think I am not incrememnting to the next line and I am not quite sure how to fix this.

 

0 Kudos
Message 6 of 11
(9,447 Views)

The File Read belongs IN the loop.

 

Then wire in a 1 so that it reads 1 line at a time.

0 Kudos
Message 7 of 11
(9,429 Views)

Your program does exactly what you asked it to do.  In particular, it will repeat 10 times, at one per second, reading (and storing in String) the (unchanging) data that you bring in on the Shift Register.  This data will consist of the first line of the (assumed-)multi-line file you specified.

 

I suppose your question is "Why is it only showing me one line?"  This is where it really pays to "Read the Directions Carefully" (or, in this case, carefully read the Help for Read from Text File).

 

Bob Schor

 

P.S. -- I pointed your code at a text file of 7 lines on my PC.  When I made a few small changes (including doing away with the silly For loop that shows the same thing over and over) , I got out an array, size 7, containing the lines of text.

0 Kudos
Message 8 of 11
(9,417 Views)

Wire a -1 to the number of lines to read all and then autoindex on the FOR loop, appending the new line (incl. linefeed) to the existing lines. No need to wire N.

 

 

Message 9 of 11
(9,403 Views)

Thank you Bob for the feedback.

I reviewed the help for the "Read from Text File" and yes, there were some info that I didnt catch before.

I followed the steps you gave, however I wanted the lines to display one after the other, so I probably still needed a loop.

Thanks for the help!

 

0 Kudos
Message 10 of 11
(9,304 Views)