LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Architecture to post and send messages to queues

Hi Folks,

I'm creating a VI that has multiple "threads," each of which must respond to messages either sent internally, or from a parallel thread. To do this, I have parallel loops (they're actually in separate VIs now, but initially they were all in the same) each of which has a message queue: just a standard queue of my own message datatype. Per typical LabVIEW design, the messages are removed, a case of a case structure is selected, and the appropriate code executed. A skeleton of this is attached for reference.

This is all working fine and dandy, but I have discovered that I need to not only post messages (enqueue the message and forget about it), but some of the message need to be sent (post the message and wait for a response from the receiving thread).

I'm obviously trying to duplicate the PostMessage and SendMessage behavior found in Windows, but it's a bit easier in C because the WindowProc can be called from any thread. With PostMessage it's called from the message pump thread, with SendMessage, it's called from the calling thread. Since I don't really have the equivalent to a WindowProc, I don't have that option. (As I'm typing this, I realize that perhaps I should create a VI for each loop that is the equivalent to WindowProc. I'll have to think about that.)

I've toyed with the idea of using a notifier associated with each queue for the responses, or even a second queue, but I haven't quite come up with a really robust way to enable this.

So, the questions are: Have any of you done this? How did you do it?

Thanks,
Jason


0 Kudos
Message 1 of 8
(4,240 Views)
Hi Jason
 
I haven't done something similar to your problem yet, but it sounds interesting.
What about the following idea:
 
Create your own queue-library, which contains a simple queue and a locked-queue? The simple queue is as usual (posting) and the locked-queue is accessed with special functions. These functions need a special locking-mechanism - maybe notifiers.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 8
(4,235 Views)

I suggest you first look at the design pattern posted by Jim Kring (LabVIEW Champion and founder of OpenG) that can be found here.

http://sine.ni.com/apps/we/niepd_web_display.DISPLAY_EPD4?p_guid=B45EACE3D9CD56A4E034080020E74861&p_...

I have used a structure that was inspired by that approach that may serve your needs.

In my case I had a controller that accepted commands via a queue and processed them in order. The controller then returned the result to the requesting entity vai another queue.

This was implemented by first creating a queue by which the controller accepted requests. The "clients" submitted there requests via that queue. Nothing fancy about this yet. Included in the data element transfered to this queue was a reference to a queue. This reference was filled in by the client when the request was submited. When the server completed the task requested, the response was returned the the client via the queue it provided.

It worked like a "self addressed stamped envelope". The server never knew who it was doing the work for. It just did the work, and passed the results back to whoever it was that asked for it.

Meanwhile, back in the client...

The Client would monitor its response queue waiting for its request to be completed.

I hope this helps,

Ben

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

hi, i 'm going to discover your vi, and i have a few questions to ask . First of all , i would like to know what type of data can you use with this commands, because in my case , i must send dats in long type for example. Secondly i must build a multithread communication , so i don't know if i must use this construction each time i have a thread, because my controler must communicate with many threads in a same time.

TheGame 

0 Kudos
Message 4 of 8
(4,171 Views)
It sounds like the "Use a notifier" scheme is the prevailing idea. I had considered that as well, but didn't like the idea of creating a new notifier for every message, or at least every sent message. However, I see that is exactly what Jim did in his code. I don't have any idea what sort of overhead is involved in creating a notifier for each message, but it seems like it would be more than the purist in me would like. On the other hand, do I really care about performance? No, not really.

Sadly, I haven't been able to get back to that project since I first posted. Perhaps in another day or two. I may go try the "WindowProc" solution I originally discussed just to see how that works out.

Thanks for your responses,
Jason
0 Kudos
Message 5 of 8
(4,163 Views)
TheGame,

By "what data type?" I assume you mean what data can be passed through the messages. I use a variant for the datatype, which can hold anything. The trick is to cast in back to the correct datatype with the "Variant to Data" (or maybe it's "Data from Variant," I can't quite remember) in the loop that is reading the message.

And, yes, you need to create a loop for each "thread."

Jason
Message 6 of 8
(4,161 Views)
hi ben,
 
I have been successful with the can communication with single messages, now i hav to transmitt and receive multiple messages.
Since i am new to this, i am not able to find a sollution from a week. So pls guid me, how to go about it...
 
thanx in advance,
 
Yogesh YS
0 Kudos
Message 7 of 8
(3,776 Views)
Hi Yogesh,
 
I would recommend you start a new thread with this issue so that we can keep track of the responses. In the new thread, please answer me the following questions:
 
1. Are you using queues to send and receive multiple messages?
2. What data form are these messages in?
 
Thanks.
 
Ipshita C.
National Instruments
Applications Engineer
0 Kudos
Message 8 of 8
(3,753 Views)