LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Append only last 5 messages

Solved!
Go to solution

Hello,

 

I am using LabVIEW 2013. So write now I am using the "Write to Spreadsheet File" function to write a series of 1D array messages to a text file. The messages are being sent every few seconds or so. I am appending these messages so that the text file stores all the messages sent. However, I am wanting to store only like the last 5 messages, and if a new message comes in, it deletes out the oldest one and stores the new one. Is there a way to do that with the "append" option? And I also want to display the last message sent.

 

Thanks for any help,

SM

0 Kudos
Message 1 of 60
(3,617 Views)

I would read in the 5 previous messages, add the latest, remove the oldest, and then overwrite the old data in the file. 



-Matt
Message 2 of 60
(3,598 Views)

I can't think of an easy way to do this other than reading the file back into Labview, delete/add data and write it back to file.  What is the purpose for doing this?  It doesn't make much sense to me but I don't know the whole picture. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 3 of 60
(3,597 Views)

Putman,

 

The bigger picture is that the text file will eventually be containing thousands of lines due to the number of messages being sent/written. I don't want to store thousands of lines, only the last few.

0 Kudos
Message 4 of 60
(3,593 Views)

Wollee,

 

That is my general idea for doing that, but I am not really sure how to go about doing that. Do you have any examples of this?

 

Thanks,

SM

0 Kudos
Message 5 of 60
(3,591 Views)

Another option is to just store the last 4 messages in a shift register.  4 since we only care about writing the last 5 including the new one.  Get the new message, append the new message, write to the file (overwriting it), then delete the oldest message from the array and save that in the shift register.


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
Message 6 of 60
(3,589 Views)

Too bad you didn't post your code, which could indicate to us how familiar you are with file I/O.  Is there a reason you want to be continually writing to the file?  The simplest solution is to simply wait until the end of the program and then do any file I/O that you want (it would be up to you how many messages you save -- you could even save them all and simply write out the last 5, or use a circular buffer of length 5).

 

Bob Schor

0 Kudos
Message 7 of 60
(3,569 Views)

I agree with Bob and Cross its going to be more effecient to retain those values and update at the end of the application.  Is there a reason you want to update the text file while the application is running?



-Matt
0 Kudos
Message 8 of 60
(3,567 Views)

I am not very good at LV so that is why I am asking for examples and help lol... The reason why I am wanting to continue writing and while LV is running is because I am receiving these messages from an external source. And if that source was to go down, I need to know what the last few messages were so I can diagnose as to why the source crashed.


Thanks,

SM

0 Kudos
Message 9 of 60
(3,563 Views)

Here try this example.

 

Please ask if you have questions.



-Matt
Download All
Message 10 of 60
(3,553 Views)