01-18-2023 04:20 AM
Hi!
I am using the Consumer/Producer architecture to realize following Project: I have a sensor that continoiusly aquires data and a setup that moves an objects that needs to be measured in x,y,z. For the movment I have a consumer loop with a state machine (UI loop) which is getting a specified postion or stepsize from the producer loop. Now everytime I update the position I update the measured data and display it in the UI. My next step is to continously update and visualize the data while the User still can move the setup. For that added a second Consumer Loop (data aquiring loop) which is doing just that. My question is how do I establish communication between the two consumer loops. There are cases in the UI Loop where it needs the latest data, but only the latest. So my first thought was to give both queues to the data aquiring loop and let it que the latest data into the UI queue when told so by the producer. But that makes the acquiring loop a producer aswell. So far I cannot thing about any problems with this approach but since the project is just at it's beginning and there is a lot more to come, I want to make sure to have a clean base.
Regards,
Erik
Solved! Go to Solution.
01-18-2023 07:32 AM
The situation you describe is quite common (at least, in my code). Suppose I have an Acquisition loop that takes 16 channels of data at 1 kHz, and I want to both stream it to disk (so I don't lose any data) and also display it on a chart, perhaps showing a "decimated" (or "binned") plot that updates at 50 points/second. I run a conventional "Producer/Consumer" loop that takes my 16 x 1000 (I collect 1000 points continuously) and sends them to the Consumer (I use a Stream Channel for this now, where I formerly would use a Queue). In the Consumer, I not only write the data to disk, but I decimate (possibly by decimating, possibly by averaging) the data and send the 16 x 20 points (again, via a Stream Channel) to the "Charting" Consumer. [Note I could also send the full data set, 16 x 1000 to the Charter, but it seems more "time-efficient" to decimate first, rather than later].
Sounds like that's what you are doing. Nothing wrong (to my knowledge) with that!
Bob Schor
01-19-2023 02:29 AM
Hi Bob!
Thank you for looking into my problem. It sounds like you are doing what I am trying to do but the right way. I added a simplified version of my code two better visulize what I've done. It looks like I have troubles to understand how to acquire data and catch user inputs at the same time in the producer loop. This is my understandment of what you are doing, please correct me if I am wrong.
01-19-2023 04:57 AM
I've been further looking into the Producer/Consumer Structure and you can ignore the last post. If I understand correctly my User-Event Loop is not the Producer but my Data acquiring Loop is.
01-19-2023 08:25 AM
Have you checked out the template project?
01-20-2023 01:10 AM
No I haven't! It looks just like what I am trying to do. Thank you for that!
01-20-2023 11:19 AM
My problem with the Project Templates that ship with LabVIEW is that they are (to my mind) overly complex, trying to "do everything all at once" rather than demonstrating an example of a Simple Concept.
Try the following:
Bob Schor
01-24-2023 05:27 AM
@Bob_Schor wrote:
My problem with the Project Templates that ship with LabVIEW is that they are (to my mind) overly complex, trying to "do everything all at once" rather than demonstrating an example of a Simple Concept.
- Go to the File menu, choose "New ..." (the second option), and in the DropDown, choose "From Templates\Frameworks\Design Patterns\Producer/Consumer Design Pattern (Events)". You should get something "simple" that looks like your Event State Machine. Look in the Consumer Loop -- this is where your "Do Something" code lives. Suppose you put code in here that starts up DAQmx to acquire 1000 points at 1 kHz inside a While Loop.
- Go back to the File Menu, choose "New ..." again, but this time choose "Producer/Consumer Design Pattern (Data)". The top While Loop (where it says "Generate the Data Here"), which is the Producer in this VI, is pretty much what you called the "Consumer" in the previous P/C (Event) code, i.e. it is the While Loop (which needs its own, independent Queue) of the DAQmx Read function, with the Data-to-be-Enqueued the result of the Read function.
I agree! Those examples are cleaner and i also prefer to start from those.
01-25-2023 09:41 AM
Thank you very much. I think this will solve my problem very nicely!