03-28-2019 12:53 PM
I have a file that does this:
1. Reads Text file
2. formats text file into a 3xN array (each line of text is stored in each row).
Now I want a queue to process each of those elements (i separated each column of the array).
My problem: how can I stop the producer/consumer loops when the end of text file is reached (i.e. no more elements to be read) My queue loops simply bundle/unbundle/index arrays.
Solved! Go to Solution.
03-28-2019 01:08 PM
I've discussed this before in this Forum (so I almost "know it by heart"). Here are Bob's Rules for Producer/Consumer Control:
Bob Schor
03-28-2019 01:13 PM
My question is-- how does the producer know if the file it's getting the queue from in another subvi has reached the end or not?
03-28-2019 01:40 PM
@sam18 wrote:
My question is-- how does the producer know if the file it's getting the queue from in another subvi has reached the end or not?
I don't understand the question. The Producer puts data into the Queue -- when the Queue is Obtained, it is brought into the Producer and the Producer enqueues. You didn't attach your VI, so I don't know from where or how the Producer is getting its data (this is one reason we always ask that you attach your VI or VIs, as we can't advise you on details of your code that we can't see). I see you have an "End of Data?" indicator -- if we saw all your code, we could probably suggest a better way to inform the Producer that it was time to exit.
Please don't ignore the comments I took the time to write for you. You are closing the Producer/Consumer in the wrong (meaning "unsafe") way -- it might work, but you run the risk of losing data or having your program "hang".
Bob Schor
03-28-2019 01:51 PM - edited 03-28-2019 01:52 PM
I can't attach my VI because it will be used for something at my work.
To explain what I mean by "end of data"
Say I enter:
hi low 8
low hi 9
low low 10
into a text file.
The text file is then converted into an array and displayed on front panel.
The producer should stop queueing elements after it detects the last row in the array which can either be the 5th row or the 9348th row (depends on input text file).
**Also, I am not ignoring your comments, I appreciate the information.
03-28-2019 02:18 PM
The way you tell the Producer that it is time to quit is the same basic technique you use with the Producer/Consumer communication. Somewhere you have a routine "feeding" data to the Producer. Consider this a "Producer-Producer", and your Producer Loop a "Consumer-Producer". Your text-reading Loop reads a line, sees data, and sends it to the Producer Loop. I don't know how data gets there -- are you passing a String, or are you passing data? In either case, you need to pass data in such a way as to allow for a Sentinel.
Let's say you pass a String. The Text-reading Loop sees "hi low 8", and sends "hi low 8". The Producer parses this and adds it to the Queue. Now the Text-reading Loop reaches the end of the file, and is ready to stop. It sends the Producer an empty String. When the Producer sees this (it tests for an Empty String first, see the Comparison Palette), it exits and sends its Sentinel to the Consumer Loop.
On the other hand, lets say you pass "hi low 8" as a Cluster of two booleans and an I32. Change the Cluster to have three booleans and an I32 -- the third Boolean is "End of Data", Fault by default. Again, the Producer simply tests End of Data first and exits if it is true.
As a general rule, it is easier to suggest relevant Solutions when we see the relevant Problem.
Bob Schor