Jump to content

.txt file CR LF problem


Recommended Posts

Hey once again,

 

I got another problem and cant figure out why is this happening.

 

I want to write 30 values to a txt file in CSV format.

 

The values are being written but the carriage return does not work (or so I think atleast). It writes the stuff on the next line, but no in the beginning of the line.

 

I attached a txt file and part of the vlp file as a picture (original file was too large to be uploaded). 

 

Maybe someone can suggest me anything.

 

Thanks in advance,

 

T

 

Cant add more than 60kB, will add when the post gets reviewed.

LOG.TXT

post-49898-0-25215000-1463148575_thumb.png

Link to post
Share on other sites

Hello,

 

You do have the CR and LF characters after the last piece of data.  If you write a second line, you should see the line be written below the first line in the TXT file.  They will not show on the TXT file since they are "invisible" characters and there is no way for the TXT file to show these characters.

 

Please let me know if you do not find this to be the case.  Hope this helps.

Link to post
Share on other sites

Hello,

 

You do have the CR and LF characters after the last piece of data.  If you write a second line, you should see the line be written below the first line in the TXT file.  They will not show on the TXT file since they are "invisible" characters and there is no way for the TXT file to show these characters.

 

Please let me know if you do not find this to be the case.  Hope this helps.

 

You are totally right!

 

I just imported the txt file to excel and the structure is the way I wanted. Nice, thanks a bunch!

 

One more thing tho,

any suggestions how to add a header row to the txt file?

 

I tried to add a header row using SB2 in the beginning of the Main Routine, did not work. The header row got overwritten in the routine, where I write the values.

I thought it opens the file, writes the header, leaves the pointer there and when I later want to write more then it will start from the pointer.

 

So, append is the word im looking for.

 

Any suggestions?

Link to post
Share on other sites

Writing a header upon start-up may be too quick for the PLC to write to the SD card -  I don't think it ever receives that command.

 

We have an example of writing a header to the CSV file in the Examples of VisiLogic. (Help tab\Examples...\Version 900\Project Examples\SD\V570_buffered CSV.vlp)

 

In this example, when we request to write a CSV line, we first write the header to the file once, then we create the data lines and write them.  This should work for you.

 

Please let me know if I can explain anything further.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...