LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to a file in RT

Hello LabVIEW users,

 

I am writing a normal config file(ini) in the RT environment. After writing, when I copy the file to PC, all the text what had been written are in straight lines. (i.e) All the line feeds in the file have been removed. This affects the readability of the file. Any solution to this issue?

Thanks in advance.

0 Kudos
Message 1 of 9
(3,293 Views)

Hi Prasanna,

 

Any solution to this issue?

Use a better editor on your computer! I suggest Notepad++…

 

Background: different OS use different "end of line" chars. Linux (as is used on recent RT systems) uses LF, while Windows insists on CR+LF. (Well, the latest or the next update for Win10 claimed to handle that better with allowing just LF…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(3,291 Views)

Hello GerdW,

I have a file in PC. I copy it to cRIO and then edit it programmatically in RT environment. Now when I copy that file back to PC, I have this issue of Line feeds getting deleted. When I open that file with notepad++ as you said, it looks correct with all line feeds. This means there is an issue with notepad. But the original file which I had it in PC can be viewed without any changes with notepad. When I just read the modified file through LabVIEW by using read text file node, the contents are perfect with linefeeds. I still don't know why notepad couldn't recognize line feeds when a file is copied from cRIO. 

 

Thanks,

Prasanna.

0 Kudos
Message 3 of 9
(3,262 Views)

Hi Prasanna,

 

that old "notepad" (aka Editor) of Windows ONLY likes the Windows-style end-of-line char (CR-LF). Better software likes all kind of end-of-line chars (Unix-LF)…

 

Get rid of notepad and use better editors like Notepad++ (or UltraEdit or many other)!

 

When you want to avoid such problems you have to save the files in your RT system using the Windows-style EOL chars…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 9
(3,260 Views)

If you do the file writing yourself you can play with the Convert EOL option of the Read and  Write Text to File function. If this is enabled the read function will attempt to convert any occurrence of <CR> (\r), <LF> (\n), and <CR><LF> (\r\n) into the LabVIEW default <LF>. On write the Write function will convert any occurrence of <CR>, <LF>, and <CR><LF> into the platform specific EOL sequence (<LF> for Unix and MacOS X, <CR> for Classic Mac and <CR><LF> for Windows).

If you use the INI File VIs you are in a bit of bad luck as the file writing is embedded deep down in the library and can't be changed to not convert. The only feasable option would be to read the entire ini file after you closed the INI file using the Convert EOL option on the Read File VI and replace all the occurrences of \n with the \r\n you so badly want, then write it back with the Convert EOL option disabled on the Write File node.

Convert EOL in File.png

Another option, as already mentioned by others, is to use a decent text editor like Notepad++ or Ultraedit, which don't get messed up about different platform specific line endings like the awful Windows Notepad application. Once you start using either of those two you never ever will want to go back to the Windows Notepad application. It's awfully inadequate.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 9
(3,253 Views)

Hello Rolf,

I tried to read the contents of the modified file(without any line feeds) through read text file node and tried to display it in string indicator. I changed the display style to Codes View. There was no \r present in the file. There was only \n. This is why I got confused. The codes view of the original file before copying to cRIO and the file copied from cRIO were exactly same. 

 

Thanks,

Prasanna.

0 Kudos
Message 6 of 9
(3,234 Views)

When you created that VI to read the file, did you right click on the File Read node and deselect the Convert EOL option? (The two arrows in the lower right corner MUST NOT be visible anymore!)

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 9
(3,226 Views)

Yeah. I did that too. Still, in the Codes Display, there were no \r found. All the line feeds were found in the string indicator.

0 Kudos
Message 8 of 9
(3,214 Views)

Something in your various posts seems not quite as you say it is. But without seeing the code in question it ends here. And considering that the main problem is mostly caused by the use of a crappy Notepad application, I think we can rest the case now.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 9
(3,209 Views)