From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Inconsistent newline using Write to Text function

Hello,

 

I have a subvi in my project that is used to log data to a text file according to a user specified recording interval. I use the Get Date/Time in seconds function and concatenate the output to my data using format into string. Then I use the Write to Text File function to write the string to the file. 99% of the time, Write to Text seem to appends a CRLF to the end of the line. 1% of the time it doesn't seem to append a CRLF and I end up with a line in my log file that looks like "Timestamp,Data,Next_Timestamp,Next_Data"

 

I suspect a race condition maybe causing my trouble due to the inconsistent nature of the problem, but I don't see where it could be coming from. I've attached a .png showing my logfile code. Please let me know if you need any additional information. Thanks!

0 Kudos
Message 1 of 13
(3,074 Views)

Your issue would have to be coming from the Current Data input.  So you need to look everywhere that you call this subVI and make sure the end of line constant is correct.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 13
(3,058 Views)

Thanks for the reply!

 

Unless I am somehow mistaken, I am not providing the end of line constant. Instead, the Write to Text function is appending it to the string I am passing. It's just sometimes, for whatever reason, Write to Text doesn't append the end of line.

0 Kudos
Message 3 of 13
(3,044 Views)

_Ben_ wrote:

Unless I am somehow mistaken, I am not providing the end of line constant. Instead, the Write to Text function is appending it to the string I am passing. It's just sometimes, for whatever reason, Write to Text doesn't append the end of line.


You are mistaken.  The Write To Text File does not append an End Of Line.  You have to write it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 13
(3,038 Views)

Why don't you post the actual code instead of a picture so we can see what is in the other cases not visible in the picture?  Seems kind of convoluted for simple log file.

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 5 of 13
(3,029 Views)

@_Ben_ wrote:

Hello,

 

I have a subvi in my project that is used to log data to a text file according to a user specified recording interval. I use the Get Date/Time in seconds function and concatenate the output to my data using format into string. Then I use the Write to Text File function to write the string to the file. 99% of the time, Write to Text seem to appends a CRLF to the end of the line. 1% of the time it doesn't seem to append a CRLF and I end up with a line in my log file that looks like "Timestamp,Data,Next_Timestamp,Next_Data"

 

I suspect a race condition maybe causing my trouble due to the inconsistent nature of the problem, but I don't see where it could be coming from. I've attached a .png showing my logfile code. Please let me know if you need any additional information. Thanks!


just slap a build array on the string in front of the write to text file.Smiley Wink

 

I know, that kind of sucks to have such a simple solution available but it works without having to go and dig through all the callers.  That EOL conversion can forgive a lot of string formating mistakes.


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 13
(3,020 Views)

@JÞB wrote:

@_Ben_ wrote:

Hello,

 

I have a subvi in my project that is used to log data to a text file according to a user specified recording interval. I use the Get Date/Time in seconds function and concatenate the output to my data using format into string. Then I use the Write to Text File function to write the string to the file. 99% of the time, Write to Text seem to appends a CRLF to the end of the line. 1% of the time it doesn't seem to append a CRLF and I end up with a line in my log file that looks like "Timestamp,Data,Next_Timestamp,Next_Data"

 

I suspect a race condition maybe causing my trouble due to the inconsistent nature of the problem, but I don't see where it could be coming from. I've attached a .png showing my logfile code. Please let me know if you need any additional information. Thanks!


just slap a build array on the string in front of the write to text file.Smiley Wink

 

I know, that kind of sucks to have such a simple solution available but it works without having to go and dig through all the callers.  That EOL conversion can forgive a lot of string formating mistakes.


So it won't add an extra EOL if one is already there?

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 7 of 13
(3,006 Views)

@ Not so lowly minion

Nope,  It'll convert any EOL it sees to the OS specific EOL and only add one if its missing one.

 

Open the example from the help and play with it to prove it to yourself.


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 13
(2,999 Views)

Sorry about that! Here is the code.

0 Kudos
Message 9 of 13
(2,985 Views)

This code looks very fragile.

 

  • How do expect a reasonable refnum out if the FALSE case executes?
  • Definitely don't convert EOL when writing (right-click...uncheck convert EOL)
  • What is the reason for the sequence structure? Makes no difference here.
  • ...
0 Kudos
Message 10 of 13
(2,976 Views)