09-24-2013 11:34 AM - edited 09-24-2013 11:36 AM
It seems like you have created 3 messages, one on reply to each of the earlier messages. But we don't know which reply is in response to whom. You would need to quote the original reply so we would know. All you need to do is create 1 message reply and address each person as needed. You can copy and paste some of the original message if needed.
Queues and notifiers are related, but not that similar. Queues are a list of all the things going to them. So if you send 3 items in a row before dequeueing anything thing, 3 items are in the queue and can be dequeued at any time (thus reducing the number of elements remaining in the queue.) Notifiers are kind of like a 1 element queue. If you send 3 items in a row before reading the notifier, only the last item is read, the first two are lost.
When you were talking about concatenating, I thought you were going to do that in the consumer loop where I thought you were processing the data and trying to combine the like messages. But I see you are doing in the producer loop, and I don't know why. Your code doesn't show anything of what you are trying to do in the consumer loop since it is just a notifier and nothing else.
The STOP function in your code is bad LabVIEW form also. It is the equivalent to hitting the Abort button on the tool bar and essentially crashing your LabVIEW code right then and there without doing anything to clean up the code like Closing the UDP connection and ending the other loops gracefully.
09-25-2013 02:07 AM
OK let me answer your questions from the last to the first.
The Stop function in the producer loop is necessary while in the consumer loop I
just put it like a stop condition, since I wrote before this is not my original code, just
to make an example.
For concatenating messages I need to do it in the producer loop, to make my notifier sends one
element every time to the consumer loop because the cycles of the consumer loop should corrispond
perfectly to the generation of the message in producer loop, and now it's necessary that when producer
loop generates 2 $ES messages one after another, one notifier is sent to the consumer loop. For queue
function, could you explain how could I reach this goal?
For your first question I don't queit understand. Through port 5123 my device generates tens of UDP messages
with different titles, and the case loop shows that I only want '$ES' ones. And now I have 2 devices and they
generate '$ES' messages together!
Thank you.
09-25-2013 02:09 AM
Thanks for the suggestion! But since this code I put here is a very simplified one of my real code.
The stop function here is not an issue. Anyway thanks.
09-25-2013 07:03 AM
jcraffael wrote:For queue function, could you explain how could I reach this goal?
Just enqueue each message you want the consumer to process. Since a queue is a FIFO, you can just let the consumer process as fast as it can and it will process every message. It should be able to catch up easily enough assuming your consumer runs faster than your producer. If you don't have a timeout for the Dequeue Element, the consumer will just sit there waiting for data to come in if there is nothing in the queue.
09-25-2013 07:11 AM
thanks for the explanation! After some study I got the idea of enqueue and dequeue function.
However, it seems impossible to solve my problem, which is every time enqueue 2 elements
together (they arrive almost at the same time) and in the consumer loop dequeue these 2
elements together, which makes the consumer loop run one cycle instead of 2!
If you have any idea about this please let me know, thank you!
09-25-2013 07:17 AM
Why do you care? Do you have to process the messages differently if two of the same messages come in a row? I don't see why you should. Just let the consumer process each message separately.
09-25-2013 07:26 AM
Because that is the idea of my program! OK if it's impossible to implement, for sure I can change the way of thinking.
My second idea is to concatenate every 2 UDP messages with '$ES' title together, which arrive almost at the same time
but in 2 cycles in the producer loop! I have to process these 2 messages from 2 devices exactly at the same time.
if for the concatenate way you got any idea, please let me know as well!
09-25-2013 09:48 AM
@jcraffael wrote:
Because that is the idea of my program! OK if it's impossible to implement, for sure I can change the way of thinking.
My second idea is to concatenate every 2 UDP messages with '$ES' title together, which arrive almost at the same time
but in 2 cycles in the producer loop! I have to process these 2 messages from 2 devices exactly at the same time.
if for the concatenate way you got any idea, please let me know as well!
The two while loops are independent of each other, so you don't try to sync them. That defeats the whole idea of the producer-consumer architecture. Instead, for each spin of the consumer loop, decide what to do depending on where the message came from. Realistically, you have to account for a condition where the two devices get out of sync and you have to deal with two messages in a row from one device anyway...