LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Append only last 5 messages

Solved!
Go to solution

Raven,

 

I was using the Array Size function as you mentioned. I also realize the race condition now. However, when I probe my "size(s)" results from the Array Size function, it stays at a constant "7", even though different messages are still coming in. Otherwise I think your method would work. My previous post has my code in there, with a slight change, adding back in the "Array Size" instead of "String Length"...

 

And no, I haven't looked at those tutorials yet, but I will very soon when I have time.

 

Thanks,

SM

0 Kudos
Message 51 of 60
(983 Views)

PLEASE PLEASE PLEASE take the tutorials.

Try to understand what your code actually does.  Until you understand how it works now, you are not going to understand how to make it work the way you want.  And just throwing chunks of code in there from several sources at once is not going to magically make it work.

 

Put probes in.  Run it with execution highlighting turned on so you understand what data flows where down the wires.

 

The problem is you are taking the current row and indexing that out.  Then you check the array size of that which is always 7 because you probably have 7 columns in that original 2-D array of data.

 

 

 

Message 52 of 60
(980 Views)

@Sman29 wrote:

 

Unfortunately I cannot post my code for a couple reasons, mainly proprietary... Attached is a screen shot of kind of where I am at right now though. 

OK, let's look at your image:

 

 

This has very little resemblance with my code.

  • You need to keep the last five messages in a shift register anchored in the outer loop.
  • I am not sure why you are piping in the data from the "test plan table", makes no sense.
  • You should not create a new unique file with each iteration, then close it. Create the file once outside the loop and close it once the program is done.
  • You need to substitue your own current message.

 

Run my code, do some probing and execution highlighting, read the help for the various primitives. Understand how and why it works!

0 Kudos
Message 53 of 60
(975 Views)

Raven,


I will indeed take the tutorials when I have time. Right now I was just thrown to the wolves on a massive program, and they just spit code at me and tell me "to modify it by tomorrow" type deal... Leaving me no time to actually learn it. The guy that built this program has been doing LV for over 10 years (and is out of pocket), whereas I've had distracted few months towards LV... Yes, I know it's terrible coding practice to do it this method, but that's the situation I am in right now. It will get better soon, but for now, I just have to put stuff together and make it "magically" work... I only posted the question on here because I thought it would be a simple thing to add. Apparently it isn't. Or is if I know what I'm doing but I don't... Which is why I come to you guys for help 🙂

 

Regarding your comment: "The problem is you are taking the current row and indexing that out.  Then you check the array size of that which is always 7 because you probably have 7 columns in that original 2-D array of data."

 

I thought I did it as you had said? Please tell me what I need to change as far as the array size stuff goes...


Thank you guys for your help and patience with me!

SM

0 Kudos
Message 54 of 60
(973 Views)

Alten,

 

"This has very little resemblance with my code.

  • You need to keep the last five messages in a shift register anchored in the outer loop.
  • I am not sure why you are piping in the data from the "test plan table", makes no sense.
  • You should not create a new unique file with each iteration, then close it. Create the file once outside the loop and close it once the program is done.
  • You need to substitue your own current message."

By outer loop I am assuming you are talking about the outer WHILE loop? I am not sure how to do that since all the stuff I need is inside the case structure?

 

"Test Plan Table" is actually the messages being sent that I need to record. Basically it's just this giant csv that "executes" the elements row by row. Everytime it executes a row, I want to record that row. So if the program crashes, I know what row I was on.

 

I placed the close file outside the loop per your suggestion.

 

Where do I need to substitute my own message at? I thought I had done that by adding my string to the "Replace Array Subset"?


Thanks,

SM

 

0 Kudos
Message 55 of 60
(969 Views)
  • "The last five messages" is a 1D array of five strings that you initialize outside the outer while loop.The indicator is only for debugging, you don't even need it.
  • Your "message" is the string that is also ging to the "current step" indicator, so just branch from there.
  • It is not sufficient to place the close file outside. You also need to place the create file outside.
  • You need to keep the history even if other cases execute, thus you need to wire the various thing (file ref, last 5 messages, etc.) across unchanged in the other cases. "The stuff you need" is not isolated to a case, it is global.

0 Kudos
Message 56 of 60
(960 Views)

Alten,

 

I eleminated the "last 5 messages" per your statement that it was just for debugging.

I wired in the "current step" to the "Initialize Array". I am assuming that was where you meant my "message" to go?

I placed the "close file" inside the loop and the "create file" outside the loop.

I did not need to wire anything outside the loop since I brought everything inside or eleminated it.

It still is not working... Please see attached and tell me what I did wrong...

 

Is it not just easier to read the last 5 messages from my file that I am already writing to? I am currently writing every message received to a file. Raven attempted to help me read the last 5 messages from that file, but I couldn't get it to work either...

 

Thanks for the help and your patience!

SM

0 Kudos
Message 57 of 60
(933 Views)

New update:

 

So I got it to read the last 5 messages of the file that records all of the messages. I made a slight alteration to Raven's code. Attached is a screenshot of how my code is now.

 

The only problem with this is, the index for the array subset (circled in red in the screenshot) is based off of what row number has been executed. When the program crashes, I have it set up to stop execution and jump to the first row. This makes my index jump back to 0, making my "Read from File" read the first 5 messages...

 

Is there a way to get it to hold its value of row number until the "start" button is pressed again (starting execution at row 1 again)?

 

Thanks for all the help guys, almost there!

SM

0 Kudos
Message 58 of 60
(926 Views)

Moved my last question to a new thread since the subject has changed:

http://forums.ni.com/t5/LabVIEW/Retaining-Last-Value-without-a-While-loop/td-p/3359830

 

Thanks for all the help everybody!

SM

0 Kudos
Message 59 of 60
(915 Views)

@Sman29 wrote:

I eleminated the "last 5 messages" per your statement that it was just for debugging.


You need to keep most of it. The only thing you don't need is the indicator.

 


@Sman29 wrote:

 

I wired in the "current step" to the "Initialize Array". I am assuming that was where you meant my "message" to go? 


That makes no sense at all! you need to initiailize the array exactly once at the start of the program with five empty strings. Do you know what "initialize array" actually does? did you look at the help?

 


@Sman29 wrote:

I placed the "close file" inside the loop and the "create file" outside the loop.

Both belong outside the loop. One before and one after.

 


@Sman29 wrote:

 

Is it not just easier to read the last 5 messages from my file that I am already writing to? I am currently writing every message received to a file. ..

 


You never need to read from the file and it is not easier. storing five messages in memory and overwriting the entire file with the last five messages is significantly more efficient.

 


@Sman29 wrote:

Raven attempted to help me read the last 5 messages from that file, but I couldn't get it to work either...

 


I am not surprised. Your last reply shows a complete lack of understanding of any of the issues at hand. You are well advised to do some lessons and tutorials before continuing. You don't just dive into the deep end of the pool without first learning how to swim. Good luck.

 

 

Message 60 of 60
(909 Views)