LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Producer Consumer design pattern incorrectly?


@rkmadse wrote:

Do you know of any examples of using "user-events" to update the gui with data? Or using "user-events" when errors are encountered so that the producer can determine how to handle the error?

 


There is a framework called the Delacor Queued Message Handler (DQMH) that is available as a free download on the LabVIEW Tools Network here.

 

This framework builds on the NI QMH project template, but makes extensive use of user events for inter-loop communication. There are DQMH tutorial documents and videos here.  

 

 

0 Kudos
Message 11 of 20
(1,348 Views)

@rkmadse wrote:

Ok, I like the direction you are heading, but I'm still missing a piece I think to fully understand the logic/how-to. Do you know of any examples of using "user-events" to update the gui with data? Or using "user-events" when errors are encountered so that the producer can determine how to handle the error?

 

I'm using a c-DAQ-9178 with a 9205 module to sample the pressure transducers. I believe the sampling rate on those is 250 kS/s.

 

 


 

I have attached the error handler VIs I used in my last project. The "generate error event" would be dropped in line with each one of the loops that would send the error on.  The error handler fgv (more an action engine in this case but whatever) then checks to see if the error is the same as the last one. If not it logs and prompts, as well as stores a screenshot of what the caller looked like for troubleshooting purposes.

Download All
0 Kudos
Message 12 of 20
(1,312 Views)

Nice idea about taking a screenshot and saving that as well.

 

Question:

Should your error handler FGV be set for re-entrant preallocate clones on its execution page?

 

You said you'd drop that in several locations in your code, which makes sense.  But if called from multiple places, the idea of using the shift register to determine if the error is the same as before or not falls apart because the different instances will be battling being no errors and/or different errors each time the FGV is called.

0 Kudos
Message 13 of 20
(1,303 Views)
I use the generate error event in line with loops, and the actual fgv in the main producer loop. The only time they "battle it out" is when multiple loops are simultaneously throwing errors constantly. In that case, I likely have a bigger problem anyway 🙂
0 Kudos
Message 14 of 20
(1,294 Views)

Got you.  I understand better now.  That makes sense.

0 Kudos
Message 15 of 20
(1,280 Views)

So I'm have been studying QMHs and how to use them, and using user events (I still don't know how to send data within a user event). However I think my architecture isn't correct for what I am trying to do. Let me explain a little better:

 

  • I have a pressure manifold with 8 valves, and 8 pressure transducers. 
  • I want to have a GUI that displays continually the pressure from the transducers (whether you are running a test or not). 
  • I want to have a state machine that is called by the main producer loop to go through the exact sequence necessary to open and shut valves based upon the pressure readings from the pressure transducers to pressurize and depressurize the vessels we are using. 
  • And I want to log the data from the pressure transducers. 

My main confusion is this... If I want to always display the pressure transducer values continuously, how do I then grab data occasionally from the state machine loop when I need to check pressures for opening and closing valves? Is that the power of the action engine? That I can initialize the cDAQ AE in Loop 3 and always take measurements within Loop 3, but when I need to access a transducer value I can call get data from Loop 2?

 

Loop 1 (Main Producer, Event Handler Structure) - Handle events selected by the user from the GUI (start the test, load a sequence, grab inputs from user for testing, etc)

  • According to people's help in this discussion I need to figure out how to get data into this loop from Loop 3 to update the GUI, somehow using a user event?

Loop 2 (Consumer, State Machine for Testing) - Recieve the start command from the user along with parameters to run the test)

  • In some states it will need to access the pressure transducer readings quickly so that it knows when to shut the valves and open others.

Loop 3 (Secondary Producer, Read Data from Pressure Transducers Continually) - Reads the data from the analog inputs and passes the data to Loop 4 to be logged. If readings go out of range for certain transducers, throw an error or enter a safety case. 

 

Loop 4 (Secondary Consumer, Data Logger) - Logs the data to a TDMS file. 

 

I think I'm just missing a few minor details that will really take me into the next level of development and I don't have anyone to work with that I can simply ask to explain these things so I appreciate any help I can get. 

 

Thanks so much.

 

Kellen

 

 

 

 

 

0 Kudos
Message 16 of 20
(1,231 Views)

Take a look at the Continuous Measurement and Logging sample project that ships with LabVIEW 2012 and later. I think it will give you some insight into how you can use the Queued Message Handler architecture to address some of the issues you're having. Go to File > Create Project and choose 'Continuous Measurement and Logging' and browse the project and included documentation.

0 Kudos
Message 17 of 20
(1,227 Views)

I don't have answer but I would like to compliment your UI design.

 

Mine always look like crap because I use the default Silver or Modern (or a combination of the two) elements.

 

I am not an artist and even the old "classic" UI elements look better than anything I can make. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 18 of 20
(1,220 Views)

Darren,

 

I am trying to implement the Continuous Measurement template, and it has the following.

 

1) Producer Event Case for GUI

2) Consumer for GUI to handle work.

3) A loop for data acquisition.

4) A loop for data logging

5) A look for Updating the GUI with data.

 

I need to implement a state machine that handles the opening and closing of valves after the person tells the test to run, should I try and combine Loop 1&2 and then have a new loop 2 handle all of the state machine work needed to run the test?

 

My main confusion comes from wanting to consinuously sample with one loop while only wanting to check the values that are being sampled periodically to determine whether or not valves need to open and close.

0 Kudos
Message 19 of 20
(1,169 Views)

@rkmadse wrote:

 

I need to implement a state machine that handles the opening and closing of valves after the person tells the test to run, should I try and combine Loop 1&2 and then have a new loop 2 handle all of the state machine work needed to run the test?


I would make a new loop for the valve state machine. You can have it initialize in the 'Wait for Event' state, and use a User Event to tell the Helper Loop to start doing the valve stuff whenever the person tells the test to run. Once the state machine is done with valve stuff, have it go back to Wait for Event so it can wait to be messaged via the user event to go again.

0 Kudos
Message 20 of 20
(1,164 Views)