LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local and Global QMH in Pre-allocated Reetrant VIs

How to use QMH in a cloned pre-allocated/reetrant VI as local only queue (for that clone only) and have the same VIs also write to queue used by the main VI. It seems that the way I am using the QMH, the data is accessible through all VIs running - the main and other associated sub-vis. 

0 Kudos
Message 1 of 7
(461 Views)

Hi,

 

You should attach your VIs, or your whole project folder (max version LV2021, otherwise Save for Previous Version) so we can see what you are trying to do. Otherwise you can also post images of your code, but VIs and projects are better.

 

From your description, it seems you are trying to clone a QMH module, but the queue used to communicate with them is the same for all clones, so all clones are concurrently trying to read the same message.

 

You should ensure each clone has its own queue. For that, don't name your queues at creation, so that it will create a new one each time.

Do this:

raphschru_0-1701367820019.png

Not this:

raphschru_1-1701367840083.png

 

Regards,

Raphaël.

0 Kudos
Message 2 of 7
(448 Views)

Thanks for the reply, sorry for not posting the VI. It is quite large so I'll need to try and reduce to share. I have attached the initial queue creation (Send State Command is the top vi.). I basically am using the same queue vis in the sub-vis to initiate, send and receive (see how they are layered, this provides reuse value). The main and sub-vis are all structured with similar state machines. 

Snapshot Start Queue and State Machine.JPG

 

The queue is not named in any of the files, probably not my issue but will investigate more.  I will try to reduce my VI size and retry to replicate (or solve) the issue. If additional problems, then i will share that example. 

0 Kudos
Message 3 of 7
(418 Views)

I did exactly this in 2016 using LabVIEW 2016, but using Messenger Channel Wires instead of Queues, so I called my basic model a "Channel Message Handler" (or CMH).  The basic code called for 24 "Stations" that could (in principle) be run simultaneously.  In reality, we typically ran 6-12 Stations at a time, but possibly couldn't support all 24 at the same time without upgrading to Gigabit Ethernet (I think we were using 100 Base-T at the time).

 

A "Station" contained three other (cloned) CMHs, one to run a Mettler Balance, one to run a TCP/IP Camera (Axis, I think), and one to create AVIs of 5-10 second "events" that were detected by the Mettler balances.

 

At run time, we decided which subset of the 24 Stations we wanted to run.  We then spun up clones of the Station CMH (which included the Balance, Camera, and Video CMHs), all run as "Asynchronous Clones" (via "Start Asynchronous Call".  We communicated with each clone by a separate named Queue (we had an Array of Clones to communicate with an Array of CMHs).

 

So doing what you propose is possible, even with named queues for communication.  But it is tricky, took us quite some time, and required lots of testing, and a fair amount of experience with LabVIEW.  And Messenger Channel Wires made it much easier to "see what we were doing".

 

Bob Schor

 

 

0 Kudos
Message 4 of 7
(394 Views)

You still did not state clearly what you are trying to do and what is the problem that you are encountering.

 


@notsocool wrote:

How to use QMH in a cloned pre-allocated/reetrant VI as local only queue (for that clone only) and have the same VIs also write to queue used by the main VI. It seems that the way I am using the QMH, the data is accessible through all VIs running - the main and other associated sub-vis. 


What do you mean by "use QMH in a cloned pre-allocated/reentrant VI", what do you mean by "local only queue", what are those "VIs" that write to the queue, what is the "main VI"...

0 Kudos
Message 5 of 7
(364 Views)

Pre-allocated, reentrant - just meaning many duplicate vis running independently (independent memory space)

 

Local queue - i want the data in one queue for this asynchronous vi (and/or sub-vi) to stay in that vi and not mix with the queue that is being used for global collection.

 

Main vi is the vi that is the main program, the main code. This code is what all the asynchronous and sub-vis original from, send all data to. 

 

There is a large main vi - has a consumer loop with state machine, many parallel loops. This vi has many synchronous sub-vis (run within the loop when called) and asynchronous vis (independent and operate in parallel to main vi). The code has been successfully running for sometime (years) using the queue vis i shared. All of the loops and hundreds of sub-vis share data with a single queue - works great. Recently i attempted to add a new asynchronous vi (a full program on its own with consumer loop, parallel loops etc) that also contains a global but i added a local queue (a copy of the queue vis that i shared), the local was intended to be the only queue with data local for that single vi. Instead, the data from all the local queues (all the clones) were available in the in each clone and the main vi.

Using the shared queue vis for new vis that share all data to the main program queue works as expected. When the orignal program was developed parallel queues were not needed. For this new asynchronous vis (opened by the main program), i copied the queue vis (initialize, send, receives..) with new names and sub-vi names. I used these queue vi copies in the new vis for local data only (has similar structure as the main vi) and the original queue vis for the data that i want to be available globally (main vi). The data from all is combining to the single original queue. Since the clones all have the same identifiers, each is writing data that cannot be differentiated. Duplicating the vis did not make unique queues as i thought it would, so either i missed a step in the duplication or i am not fully understanding how they are staying linked (the copied queue vis to the original queue). 

 

Hope this is better! 

0 Kudos
Message 6 of 7
(346 Views)

So what I understood in that you want to reuse your Queue management VIs across multiple clones of a QMH module, but your clones access to the same queue instead of each clone having its own queue. Is that it ?

 

Your VI "Create State Machine Q.vi" acts like an FGV (Functional Global Variable), which explains why you only create the queue once, then always get the same ref:

raphschru_0-1701443622964.png

My advice would be: remove the case structure, the first call and the shift register so that it creates a new queue each time it is called. Then pass the queue ref to the loops that needs it. You should not call "Create State Machine Q.vi" to get the reference later on, only at the initialization of the QMH module.

 

You can get inspiration from project template "Queued Message Handler" to see how they manage the queue.

 

Regards,

Raphaël.

0 Kudos
Message 7 of 7
(335 Views)