11-07-2013 12:58 PM
Hi,
We are using producer/consumer pattern to design a NI spirometer with myDAQ.
And hae probblem on how to enter analysis step.
Steps
1. "Start button" -> 2. while loop aquire data -> 3. click "Stop button" -> 4. show cursors on xy graph, and user.
5. user could click "start button" again to start next cycle.
How to problem so it could run from step 3 to step 4, and keep the window is still running.
I attached our code here, DiagnosticRevB.vi is the main VI.
Thanks
Tonghua Li
Solved! Go to Solution.
11-08-2013 05:05 PM
Hello,
The problem you are having is that you have a race condition for your "stop" variable. You are writing to it in both the producer and the consumer. When the stop button is pressed, it will enqueue a stop command and then set stop to true. In your stop state in the producer, you set stop to false.
The race condition happens because you do not know in what sequence the stop variable will be set to true or false! Your stop state could run before labview sets stop to true, the stop state will then set stop to false, and then the case structure could set top to true. This is actually what is happening and the reason why your code is not able to be started again.
You will need to correct this race condition to make your code robust and work correctly. One way to do this is to only write to stop in the producer loop (your loop with the event structure). Take a look at my attached solution.
11-11-2013 07:55 AM
Work, Thanks for helping. 🙂
11-11-2013 08:50 AM
I have another question, In the "start" consumer loop, I want to show a messagebox after stop, how to do it?
Attached is the file.
Thanks
11-11-2013 11:53 AM
11-11-2013 12:19 PM
Just put a messagebox in the "Stop" case. That is where you should be handling all events that are related to stopping the event.
If you want your application to make more "sense" and make it easier to wrap your head around where and how to add content, create another case in your consumer loop called "Run" so that you have three cases: "Run, default", "Start", and "Stop". Your "Run" case will be the same as your current "Start" case, however instead of tying the stop variable to the "stop" of the loop, put a case around that loop and have the case be controlled by the stop variable. This way you will only aquire data when you are not stopped. Your start case will set the stop variable to false, and your stop case will set the stop variable to true (and you can put your messagebox in there too). You will no longer control the stop variable in the producer loop, so you will not have the race condition again.
You should also consider having an "Initialize" case where you set all of your indicators and controls and registers to known values. I wired in a property node to set the value of "Stop Indicator", but this isn't the ideal way to do it. It will be up to you to add a more robust "Initialize" case.
I also noticed that you have two front panel objects with the name "Stop". You should always give your front panel objects different names so that you do not confuse them. Even if they are different types (one indicator, one control). I have changed the names in the zip.
You also need to keep the controls that are associated with an event structure in that event case. E.g. your stop button needs to be placed in the "Stop":Value Changed event case. You also should change your button's mechanical action to Latch when released so that you are not creating two events with "Value Change".
Please see the attached zip.
I would suggest taking a look at the LabVIEW tutorials to get a stronger knowledge of the LabVIEW environment and try and get around some of these common mistakes. I feel like you have a good understanding of how you want your application to work, but these common mistakes are getting in the way of implementing them.
11-11-2013 03:11 PM - edited 11-11-2013 03:28 PM
BFeigum, Thanks for your kindly help.
Now I have modified the program base on your suggestions. runs wonderful.
But I still don't know
1. How to pass collected data from run case to stop case for evaluation?
Use a indicator and hide it from the front panel?
I can read data from graph.
2. how to add a "Initial" case to consumer loop? or right after error in?
Thanks
Tonghua Li
11-11-2013 04:16 PM
3. I have problem on clear xy grap, (Flowrate vs volume), I think the problem is coming from "FVGraphBuilder", because it use an array to store every input. Need a way to clear it in "start" case.
11-11-2013 07:33 PM - edited 11-11-2013 07:34 PM
Found the solution for question 3
http://digital.ni.com/public.nsf/allkb/5B0B282E31E65E42862577A7005BC9AA