LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from text file by line

Solved!
Go to solution

I am attempting to automate my power supply. I found a VI online for my make/model and I am currently trying to adjust it to my needs. I did not attach a VI due to it being currently irrelevant. 

 

I would like to read just one line of text at a time using "read from text file function". After the passing of this line I would like to move on to the next line after the rest of the program iterates once.

 

When I change the "read from text file function" to "read lines", I can no longer put a constant on the front panel for text. How can I iterate one line at a time? How can I put a constant on the front panel to display which line of text was read?

0 Kudos
Message 1 of 12
(4,845 Views)

Constants don't go on the front panel, they go on the block diagram.

Do you mean you are having trouble creating a string indicator?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 12
(4,838 Views)

@paul_cardinale wrote:

Constants don't go on the front panel, they go on the block diagram.

Do you mean you are having trouble creating a string indicator?


...and THIS is why code is always relevant.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 12
(4,836 Views)
Solution
Accepted by Josh_Music

Just a guess, but you are probably missing the "count" input.

Frozen_0-1637189606432.png

 

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 4 of 12
(4,817 Views)

Hello,

 

Thank you for any help given. If you look at the snipit I attached, the top part where I added my own code is what im struggling with. I have a text file that I want to read as one line at a time, then for the for loop to iterate, then read the next line, etc, so naturally, I see use shift registers. Why does the "Not equal?" function dislike my input? Does my "read from text file" node need to be outside the current for loop? (I am still very new to labVIEW and I am trying to add to a complicated VI that is made by the creator of my power supply in order to automate the power supply) 

 

I will attach the full vi zip file... to access the file I am referring to, go to examples->Eurotherm 35xx Series Temperature Controller

 

Thank you!

Download All
0 Kudos
Message 5 of 12
(4,755 Views)

This could have been continued in the previous thread as well - https://forums.ni.com/t5/LabVIEW/Read-from-text-file-by-line/m-p/4192511

 

Anyway, let this be a new topic.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 6 of 12
(4,752 Views)

Where in the menu tree is that read file by lines.  I have a copy of one that reads lines starting a number of characters in that I have been carrying around since LV2012 or earlier.

 

I am using LV2019 so maybe it is something that they added back 2020 or later.

 

I need the starting at character number as I am reading really big files.  What I would really like is read N lines starting at line M.

0 Kudos
Message 7 of 12
(4,757 Views)

Unless the file is gigantic, I would recommend to read all lines, then process them line by line. A text file is just a long string of bytes and unless all lines have exactly the same number of characters, you cannot tell at what file position one line ends and the next begins, so no matter what, you should read as much as you possible can and do the rest of the parsing in memory.

 

As others have said, once you switch to lines, you get an array of strings instead of a plain string, so right-click your indicator and "change to array". You probably also need to adjust the code accordingly.

 

And yes, as you can now see, attaching code (possibly simplified to show the problem only) is always relevant. Your problem would have been solved in the first few responses. 😄

0 Kudos
Message 8 of 12
(4,751 Views)

@Tom_Powers wrote:

Where in the menu tree is that read file by lines.  I have a copy of one that reads lines starting a number of characters in that I have been carrying around since LV2012 or earlier.

 

I am using LV2019 so maybe it is something that they added back 2020 or later.

 

I need the starting at character number as I am reading really big files.  What I would really like is read N lines starting at line M.


Right-click and select Read Lines option.
santo_13_0-1637280860168.png

santo_13_1-1637280932957.png

 

If you think about it, reading from line M for N lines, you first need to find the offset of line M which is not possible unless you read the entire file and look for new line characters because a text file is composed for a sequence of characters and not lines.

 

So, in any case, you need to read first N lines (simple as stop reading at N+1 occurrence of new line character)

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 9 of 12
(4,737 Views)

Thanks.  Although it does not have a start reading at byte input so you have to precede it by open file set position to N bytes after start.

0 Kudos
Message 10 of 12
(4,719 Views)