LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer/consumer with subvi

Hi all,

 

I searched this question and didn't really find a good answer. 

 

I've borrowed and modified some code that runs a countdown timer with some other features.  I've made it into a subVI called by the main program because it's too big to put on the screen repeatedly and it's just better programming practice.  Of course, the timer while not count down in the main VI because it only updates after the subVI ends.  What I need to do is enqueue the time strings output by the subVI and de-queue the strings in the main VI and then display them. The input terminals on the subVI are the 'start' boolean switch and the 'time in seconds' double.  The output terminal is "Time Remaining (s)."  How should I add the "enqueue" to the subVI so that the "Time Remaining" string output can be properly displayed by the main VI?  How should I add the "de-queue" to the main VI?

 

Thanks in advance.  

Download All
0 Kudos
Message 1 of 4
(2,925 Views)
I would ask you to navigate to File -> New... and look for Producer/Consumer Design Pattern in the From Template -> Frameworks directory. Have a look at how it's designed and if you have any questions, post back.
Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 2 of 4
(2,918 Views)

First, are you using a double monitor setup?  If so, please move your VI's to the left hand monitor before saving as a courtesy.  When I opened your VI's they were almost completely off the right edge of my monitor.

 

Second, you are still doing some things that I and others recommended against in this thread where you had some parallel write statements going on to your serial port.  You have several things that appear like you want them to operate in sequence, and they just might, but you have things branching off in odd directions and sort of happening in parallel.

 

Third, some things like the Formula Node express VI are overkill.  There is no reason to do an Express VI to take the integer of an integer value divided by 0.25.  Just take the blue wire and multiply by 4!

 

You can't have a while loop in your subVI and have the subVI be a part of your main loop.  The reason your main program doesn't update is that the while loop essentially pauses while it is waiting for the embedded subVI to finish.  And basically parallel to that you have a time delay of 60 seconds which will cause that loop to take at least 60 seconds even if the subVI happens to end early.  (Do you have the SubVI set to open up its front panel when called?)

 

I don't think that you need to use a producer/consumer architecture using queues for what you are trying to do here.  In fact, your architecture should be more of a state machine since you have basically 4 states, turn on, wait while on, turn off, wait while off.  The amount of time that has passed in an Elasped Timer Express VI (probably one of the few truly useful Express VI's) will help for transitioning from a waiting state to the next state.

 

I feel like you don't really understand the concept of dataflow yet.  Basically, a structure (SubVI, case statement, loop, sequence frame) can't run until all the inputs have been made available to it.  And no outputs come out of a structure until all the code inside has completely finished.  I would recommend you take some tutorials to learn more about LabVIEW from here. How to Learn LV

Message 3 of 4
(2,912 Views)

Ravens,

 

Yeah, I'm using a double monitor set up.  Sorry about that. 

 

I think the data flow works ok, at this point.  I've checked the 'write' commands on NI spy and looked at the execution while it's highlighted.  The dataflow appears to be fine from my end.  No doubt there are some bad programming practices in there.  I've been using LV for about a month and am still getting up to speed.

 

I got rid of the formula node.  That was dumb. LOL.

 

[quote]The reason your main program doesn't update is that the while loop essentially pauses while it is waiting for the embedded subVI to finish.[/quote]

 

That's why I wanted to try a more advanced design pattern.

 

[QUOTE] (Do you have the SubVI set to open up its front panel when called?)[/QUOTE]

 

No.  How do I do that?  Ideally, I'd want the subVI's front panel to be incorporated into the main VI's front panel.   

 

I'll try the state machine approach and see what I can come up with on my own.  Is there a way of making the Express VIs not even appear on the function panel?  I don't really use them either and find it annoying that the rest do not pop up automatically. 

 

[QUOTE]I feel like you don't really understand the concept of dataflow yet.  Basically, a structure (SubVI, case statement, loop, sequence frame) can't run until all the inputs have been made available to it.[/QUOTE]

 

I'd be the first to agree with you.  I'm making my way through Kring's book right now, but no way am I shelling out $1100 for a basic course.  

0 Kudos
Message 4 of 4
(2,877 Views)