LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

The NEW look of Producer Consumer design pattern

I really like the look of code using the new Chanel wires.

 

Producer_Consumer.png

 

I attached a zip of this slightly complicated demo to this post. It also doubles as a demo showing how use some of the features of a Waveform data type chart to plot data with arbitrary timestamps.

 

What do YOU think of the new look?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 1 of 22
(7,960 Views)

Is it Chanel No. 5?

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.
Message 2 of 22
(7,897 Views)

This is invaluable to my understanding of channels.  THANKS!!!

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.
Message 3 of 22
(7,888 Views)

Turns out there is an option to option to replicate a  channel so I did not have to use the "Always Copy" and the second sender.

 

Learning as I go!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 22
(7,885 Views)

I guess I'll have to post the CMH, which is like the QMH, but uses ... CHANNELS.  I've been incorporating this design into many of the Top-Level designs I've done lately -- I'll look for a suitable one to post this evening ...

 

Bob Schor

Message 5 of 22
(7,830 Views)

My brain still tells me that things connected horizontally execute in sequence and things stacked vertically operate in parallel. I might just have to get used to that but I also may try putting channelsome on the top and bottom of the connector pane.

 

@Bob I don't think many people use channels more than you so I would be interested in you sharing anything channel related.

Matt J | National Instruments | CLA
Message 6 of 22
(7,822 Views)

OK, you asked for it!  This is a "browser" for some data files, all of which have the same Filename with a numeric extension (e.g. "MyData.001" "MyData.002").  I wrote this just as I learned about the Event Messenger, and realized it solved a problem I had.  Never mind the details of the "missing VIs", I'll describe what's going on (so never mind that all the miscellaneous VIs aren't here ...).

View ToF Data 2.png

The functions Send State and Receive State are similar to the Read Message and Write Message VIs for QMH's -- the "Message" is a Cluster consisting of the State Enum and a Variant Data.  This particular picture shows what happens when the User specifies a File Number, triggering the Event Case shown above.  We wire the desired CMH State to handle the new ToF # (called "ToF" -- no imagination, so sue me), and we also pass in the number as the Data element.  This goes down to the Receive State function, which has the Channel Reader and the Unbundle function to allow us to bring out State and optional Data.  [Obviously, Send State has the analogous Bundle function].

 

I also like "vertical" layouts for parallel loops.  I also like putting Outputs on the right of While loops, and Inputs on the left.  Because these are Messengers, which can be joined, we can form logical "outside-the-While-loop" Feedbacks which (to my jaundiced eye) are easy to grasp and understand (after you look at it for a minute).  [And it is very colorful and pretty ...]

 

Notice the little purple loop below the CMH labeled "Plot ToF Data"?  Yup, another CMH.  The VI I use to send its Messages is called "Send Triax" -- you can see an example in the ToF Case shown here that starts it off by sending its Initialize State that starts it running.  It actually runs as a Sub-Panel of the illustrated VI (notice the Sub-Panel Insert VI node).

 

Some other features are the Error Handler that "sits" on the Error Line near the end of the While Loop.  If it detects an Error,  it (a) clears the Error, and (b) creates a Send State to the Error State, with the (former) Error Line as the Data).  Now the Error has been "turned into Data", and you can handle it however you want in the Error State.  Note this is just another input to the Message Handler -- if there is no Error, it doesn't put anything onto the Message Channel.  Notice that if the Plot ToF Data exits because of an Error, it also feeds into the same Error Handler for the main Loop.

 

So one last detail.  Normally, the Program stops because the User pushes the Stop Button which causes the Event Loop to put Exit on the Send State line while stopping the Event Loop.  The Exit State then stops the Message Handler and Plot ToF  Data loops.  But what if there's an Error, and you decide to Exit?  You can stop the Message Handler and Plot Loops, but how do you stop the Event Loop?  Enter the Event Messenger (the Blue Channel), which does nothing other than stop the Event Loop.

 

Whew.  Enjoy!

 

Bob Schor

Message 7 of 22
(7,800 Views)

Thank you for that out of breathe explanation Bob.

 

I suspect you can not share that project (so that we can poke at it and learn). Being the anal-retentive type, my first reaction is that I would like to move stuff around to minimize the length of the channel wires and try and reduce the number of bends.

 

But then again...

 

If that is really the channel form of a QSM (does the handler loop feed itself?) then the shape accurately conveys that structure.

 

I am still poking at and getting my model adjusted to read and write code with Channels.

 

Thank you,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 22
(7,741 Views)

Since you can not share your code Bob, I found an example that ships with LV 2016 that is similar. I saved it off separate from the NI folder and a zip of it is attached to this post.

 

So instead of being a QMH it now a CMH but it still looks like a Worm Oroboros to me.

 

Code.png

 

Use it at your own risk!,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 22
(7,702 Views)

@Jacobson-ni wrote:

My brain still tells me that things connected horizontally execute in sequence and things stacked vertically operate in parallel. I might just have to get used to that but I also may try putting channelsome on the top and bottom of the connector pane.

 


That is my common practice. JeffK prefers to run them horizontal and just separate them with more-than-average whitespace to create distinct regions. I think the difference is that he tends to work on more pipeline designs and I tend to work on more parallel-actor designs. For pipeline data, channels are essentially still dataflow, just in a different time domain.

Message 10 of 22
(7,697 Views)