10-12-2022 11:10 AM
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
10-12-2022 12:53 PM
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:
Using a queue:
10-12-2022 01:07 PM - edited 10-12-2022 01:08 PM
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
10-12-2022 01:36 PM
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…
10-12-2022 02:19 PM
sorry but can you explain more because im still not getting you. Im new to this producer and consumer loop structures
10-12-2022 02:41 PM
@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
10-17-2022 02:32 AM - edited 10-17-2022 02:33 AM
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
10-17-2022 02:43 AM
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
10-17-2022 09:11 AM
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
10-17-2022 10:08 AM
@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...