LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comment on design selection

Hi,

 

Please comment and advise on design selection.  I have a producer and consumer design.  The producer contains a state machine that would be the work horse of the program.  The consumer loop will get a queue with a 2D array element.  Each row in the array represents one type of energy (out of six types).  The consumer will poll the energy type (enum) and determine which row of energy to display.  

 

Questions:

1. I used preview queue instead of dequeue at the consumer loop, because I want the consumer loop to update the GUI even without new data.  For example, the queue is a one element queue, but the element is a 2D array with six rows for six types of energies.  I want the user to select which type of energy (which row) to display during run time, so I am polling in the consumer loop, which I don't want to.  

 

I want to use dequeue element, so the loop will only run when there is a new element, but I want the loop to poll the user input for display energy and update accordingly.  Can I somehow use a even struture in there?  I want to update when there is a new element or when there is an value change event (enum) from the boolean.

 

2. For example, let's say I set a queue to a one element queue, and I don't dequeue that element.  After the queue has obtained one element, if I want to queue another element on it, I believe I would get an error, since the queue is full.  However, is there a way overwrite the one element with another element?  Lossy Enqueue should work, but is this a good way?  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 8
(3,295 Views)

Can you attach the actual VI instead of an image?

0 Kudos
Message 2 of 8
(3,287 Views)

Here is the Main VI.  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 8
(3,276 Views)

Hi jyang72211,

 

I think you may be a little confused about how queues work.  When you add an element to the queue, using an Enqueue function, it will enter a line.  Elements wait in that line to be taken out of the queue (Dequeue).  You will not run into errors with more than one element in the queue.  That's the whole point of a queue, that you can have multiple elements all waiting to be handled.  They will be handled in the same order that they entered the queue.

 

As far as have the consumer execute based on events, how about a parallel Event Structure.  You can pass your queque reference to an Event Structure and then add elements to the queue when certain events occur.  That way the code you are executing in your consumer loop is not being replicated in two places.  In other words, set up an Event Structure as a second producer loop.

 

If you would like queue-like behavior, but have only one element allowed and be able to overwrite it, you are looking for a Notifier.

 

Have a great day,

 

Chris

Applications Engineer
National Instruments
0 Kudos
Message 4 of 8
(3,248 Views)

I know that the way that I am using the queue is not proper.  I wanted to use a producer and consumer design at the beginning, and later I modified it to fit my application, and now it doesn't look like anything.  I just want the producer loop to run my progarm, and have the consumer loop to poll the a control and update the GUI accordingly.  I don't want to poll, so my design is not as I desired. 

 

Can you elaborate on your parallel Event Structure idea?  I am not completely sure what you meant.  Yes, my queue is only a one element queue, so I guess i can look into a notifier.  Right now, I am trying to explore all options.  Thanks!

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 8
(3,234 Views)

Hi jyang72211,

 

Here's a snippet of what I'm talking about:

 

2 Producers.png

 

Basically, we can pass the reference for the queue to two different Enqueue blocks.  Then both loops can feed in information that wil be read by the consumer loop.

 

The structure would be very similar with notifiers.

 

Have a great day,

 

Chrsi

Applications Engineer
National Instruments
0 Kudos
Message 6 of 8
(3,213 Views)

I am not sure why this design can be applied to my problem.  Maybe I am just missing something.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 7 of 8
(3,204 Views)

jyang72211,

 

It could be very possible that I'm missing something about what you're trying to do too 🙂

 

From what I understand, you need to update your UI based on data generated by a producer loop OR UI events.  Correct?

 

What the structure I posted does, is process queued data generated by a producer loop and by an event structure in one consumer loop.  This would allow you to send updates from the loop you are processing data in (what I understand to be your producer loop) and also send updates based on UI events (the lower loop with the event structure).

 

Does this make more sense and answer your question?  Or am I thoroughly confused (my gut says this is more likely!).

 

Have a great day,

 

Chris

Applications Engineer
National Instruments
0 Kudos
Message 8 of 8
(3,179 Views)