LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Channel writers between loops, both ways?

I have 2 loops in the same VI. Lets say I want to keep them separate. But I want to send information from both loops to each other. Is this the way to do it? I know backwards wires are frowned upon. Maybe this is just stupid in general and if I'm doing this, I just need to use 1 loop 🤔

 

messaging betwee loops.PNG

0 Kudos
Message 1 of 5
(404 Views)

Firstly i am not fan of using Channel Writer, But  tried this long back to understand on the communication flow. It supports only one way communication if you want to have a two way communication then you need to go with Multiple Channel wire (At least 2)

Pazhanivel Thiruvenkadam,
CertifiedLabVIEWArchitect|| CertifiedTestStandDeveloper,
Currently able to Access LV2015&LV2017
Message 2 of 5
(366 Views)

In short, yes that is how it is done. 

 

Lets compare it to some kind of reference based solution:

thols_0-1668683364855.png

 

Is this better? Can you see where the data is going? 

 

Channel wires are an improvement that at least lets you see the data flow by wires. What is not apparent is the direction of data. It is better than reference based solutions but I would like channel wires to show the direction of data.

 

But you will eventually find that each while loop will/should be a sub-VI. This sub-VI is a process that responds to "messages", an actor. Try to standardize the connections between the actors and perhaps do what I do, put some arrows near the wires to show the direction:

thols_2-1668684303891.png

These directions will never change or only change if you change the design, so it doesn't matter that much that they aren't a part of the channel wire.

 

 

Certified LabVIEW Architect
Message 3 of 5
(348 Views)

 

Some more thoughts:

Your example could look something like this with just some layout standardization. Readable enough in my opinion:

thols_0-1668692859321.png

 

As you can see, I did not use a channel Tag but a stream. I think you will find that in most cases it is better to send and act on new data in the channel rather than read it regardless of if it changed or not. (this code is not complete but needs some UI events or loop waits, loop stop and so on.)

 

In fact, I almost always use a Messenger channel instead. Then you can send messages and data in the same channel and the loops becomes actors.

 

I recommend viewing the LabVIEW examples. In Find examples, search for ”channels” and also ”measure and log”. The latter has a good step-by step procedure for an idea how to design a measure and log application. It has its flaws but will get you going.

 

Another thing to consider: Will you really need the data back in the first loop? If its only for display, then consider creating another loop for that. The “measure and log” example shows that.

Certified LabVIEW Architect
Message 4 of 5
(325 Views)

A few (minor) comments on Channel Wires and how to better understand them:

  • I recommend always (well, almost always) bringing them in/out on the vertical sides of a structure.  This makes "incoming" and "outgoing" easier to see, and makes the "loop-back" easier to recognize.
  • Loop-backs are not that uncommon.  Think about a State Machine, where you are inside a State and needs to send "Next State" after you have dequeued the current State.  So when you enqueue the next State, the "next state" information flows backwards from the Enqueue Function's Queue In terminal to the earlier Dequeue Function's "Queue Out" Indicator (or so it seems!), which is really weird (unless you mumble something about "it's just a reference, I mean, "magic").
  • The moral of the previous point is where you have a Dequeue followed by a later (as measured by the Error line) Enqueue "next", you want the data to flow in the output (to the right) direction, loop back, and reenter the Structure on the left and come in on the input side of the (next) Dequeue.  Channel Wires show this explicitly.
  • There are different kinds of Channel Wires.  Your example shows a Tag Channel, which is much more similar to a Notifier than to a Queue.  The Channel used for State Machines and similar Loop-backs is often the Messenger Channel.  And the Channel used for one-way Producer/Consumer designs is usually the Stream Channel.  Each Channel Wire has its own set of uses (and often some extra very-useful inputs and outputs).

Bob "Channel Enthusiast since 2015" Schor

Message 5 of 5
(279 Views)