LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer/consumer loops with notification

HI, 

im using producer and consumer loop for my VI its working for continuous measuring of visa read and write. I have init program in producer loop which needs to send once, and consumer is for actual measurement its continuous measurement  and this is working fine. now i want to make a change as i shown in the vi. I want to use start program and stop program button instead of only start. it should work like when i stop it should be idle no measurement should be done and when i start it i should start again from producer loop with init commands(loop). The program which i designed its terminating whole program when i stop it. can someone give some idea? If you have any question i will explain you more

 

thank you

0 Kudos
Message 1 of 27
(2,129 Views)

Hi new,

 


@newmemeber123 wrote:

I have init program in producer loop which needs to send once, and consumer is for actual measurement its continuous measurement  and this is working fine.


Why do you use a notifier for a producer-consumer scheme?

What's the reason not to use a queue?

 


@newmemeber123 wrote:

I want to use start program and stop program button instead of only start. it should work like when i stop it should be idle no measurement should be done and when i start it i should start again from producer loop with init commands(loop).


Using your notifier:

  • Send a TRUE upon "Run".
  • Send a FALSE upon "Stop".
  • Handle the state change in your consumer…

Using a queue:

  • Design a message containing a cluster of [enum, variant].
  • Send a "start" enum item upon "Run".
  • Send a "stop" enum item upon "Stop".
  • Handle the enum item commands in your consumer.
  • You may use the variant to send even more information for each command…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 27
(2,098 Views)

hi,

thanks for reply. initially i tried with it and it was working so i continued with notifier one.

how to handle state change in consumer? 

Can you show me example or link of example?  so i can understand it better since im beginner in labview 

 

thanks in advance 

0 Kudos
Message 3 of 27
(2,088 Views)

Hi new,

 


@newmemeber123 wrote:

how to handle state change in consumer? 


When the consumer receives a TRUE then it will start the acquisition. And when it receives a FALSE then it will stop the acquisition…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 27
(2,062 Views)

sorry but can you explain more because im still not getting you. Im new to this producer and consumer loop structures 

0 Kudos
Message 5 of 27
(2,037 Views)

@newmemeber123 wrote:

sorry but can you explain more because im still not getting you. Im new to this producer and consumer loop structures 


Open LabVIEW.  On the menu bar, go to File, New ... (the dots are important), expand VI, From Template, Frameworks, Design Patterns, and choose Producer/Consumer Design Pattern (Events).

 

This is a standard 2-loop parallel LabVIEW Design, used for State Machines, Message Handlers, Producer/Consumer, etc.  The Top Loop "waits for Instructions" and delivers them to the bottom loop which "Does What Needs To Be Done".  The Top Loop "Produces", the Bottom Loop "Consumes".

 

Bob Schor

Message 6 of 27
(2,028 Views)

as i explained before its working for start event but im not getting how to send notification true and false to consumer loop if start and stop buttons pressed.  i added new event for stop how can i procced to make it true and false. 

can someone tell me?

thank you

0 Kudos
Message 7 of 27
(1,964 Views)

i got the idea but i can't able to implement it in the vi. If someone has related example with notifier so i can go through it and understand it. it will be helpful. 

Thank you 

0 Kudos
Message 8 of 27
(1,958 Views)

Producer/Consumer loops do not use notifiers to send the data from the Producer to Consumer, they use Queues (or Stream or Messenger Asynchronous Channel Wires) to send appropriate Data from the Producer to the Consumer.

 

The Consumer, in an Event P/C system, is often a Queued State Machine or a Message Handler, where you put "What" you want to do (the "name of the State", either as a String, as the Template example does, but without showing you the Case Statement inside the "No Error" case in the Consumer -- I apologize for not checking out this Template before recommending it to you, or as an Enum, which is what I use).  

 

Note that if you have a "Start Measurement" Boolean switch, if it is one of the "Rectangular" Boolean controls, its Mechanical Action will be set to "Latch until Released", and if you put the Terminal inside the Event structure, it will only ever read "True".  So you don't put the (always True) value on the Queue, you put the name (as a String, or as an Enum) on the Queue, the Producer telling the Consumer "This is what I want you to do now".  The Consumer takes this off the Queue, passes it in to the Case Structure (inside the No Error Case) and (if you pushed "Start Measurement") goes and executes the (Start Measurement) State you specified.

 

One final note -- do not destroy the Queue in the Producer!  One of the Producer states should be "Quit when I push the Quit button".  When the Producer gets to this State (because you pushed the Quit button), it wires a "T" to the Producer's Stop terminal, otherwise it uses the default, "F".  So pushing "Quit" stops the Producer.

 

How do you stop the Consumer?  Well, the Producer tells the Consumer to execute its "Quit" State.  At this time, the Producer has already exited, so there will be no more data coming in on the Queue, so the Consumer can safely Release the Queue, and can wire "T" to its Stop terminal.  Forcing an Error to stop code seems very foolish to me ...

 

Bob Schor

0 Kudos
Message 9 of 27
(1,924 Views)

@Bob_Schor wrote:

Producer/Consumer loops do not use notifiers to send the data from the Producer to Consumer, they use Queues (or Stream or Messenger Asynchronous Channel Wires) to send appropriate Data from the Producer to the Consumer.

 

The Consumer, in an Event P/C system, is often a Queued State Machine or a Message Handler, where you put "What" you want to do (the "name of the State", either as a String, as the Template example does, but without showing you the Case Statement inside the "No Error" case in the Consumer -- I apologize for not checking out this Template before recommending it to you, or as an Enum, which is what I use).  

 

Note that if you have a "Start Measurement" Boolean switch, if it is one of the "Rectangular" Boolean controls, its Mechanical Action will be set to "Latch until Released", and if you put the Terminal inside the Event structure, it will only ever read "True".  So you don't put the (always True) value on the Queue, you put the name (as a String, or as an Enum) on the Queue, the Producer telling the Consumer "This is what I want you to do now".  The Consumer takes this off the Queue, passes it in to the Case Structure (inside the No Error Case) and (if you pushed "Start Measurement") goes and executes the (Start Measurement) State you specified.

 

One final note -- do not destroy the Queue in the Producer!  One of the Producer states should be "Quit when I push the Quit button".  When the Producer gets to this State (because you pushed the Quit button), it wires a "T" to the Producer's Stop terminal, otherwise it uses the default, "F".  So pushing "Quit" stops the Producer.

 

How do you stop the Consumer?  Well, the Producer tells the Consumer to execute its "Quit" State.  At this time, the Producer has already exited, so there will be no more data coming in on the Queue, so the Consumer can safely Release the Queue, and can wire "T" to its Stop terminal.  Forcing an Error to stop code seems very foolish to me ...

 

Bob Schor


Foolish as it may be, I believe the producer/consumer example stops it exactly like that...

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 27
(1,913 Views)