LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing UDP reception

I have a UDP multicast happening from a remote datalogger. And once every 12ms, it pumps out 30 bytes of logged data.

 

My notebook runs a UDP receiver (LV2009) to collect the data. This read happens inside of a 25ms Timed Loop. While the data collection happens, its quite bothersome to see the "Finished Late" error of the Timed Loop always lit. Jacking up the Timed Loop iteration to about 500ms kind of solves  the issue , but this is way too slow for my plotting.

 

Question is : How does one ensure that all the transmitted data is collected and without generating an error in the Timed Loop ? Ideally if there were a function that just listens to the UDP port and triggers a read, once  there is fresh data , my problem is over !  

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 7
(3,447 Views)

Question is : How does one ensure that all the transmitted data is collected

 

With UDP there is no garantee that a transmitted data is received.

 

Moreover if you don't care about the "Finished Late" of the timed loop I would suggest to use a normal loop,

or at least to place the communication part outside the timed loop....

 

0 Kudos
Message 2 of 7
(3,403 Views)

Raghunathan wrote: 
Question is : How does one ensure that all the transmitted data is collected and without generating an error in the Timed Loop ? Ideally if there were a function that just listens to the UDP port and triggers a read, once  there is fresh data , my problem is over !  

Unless I'm misunderstanding, the function you want does exist.  Set the timeout input of UDP Read to -1 and it will wait until there's new data available. 

 

Why are you using a timed loop, rather than a standard while loop?

 

 

0 Kudos
Message 3 of 7
(3,396 Views)

Agreed. I gain nothing much by the timed loop and already have changed over to the less CPU intensive while loop with a 10mS delay put in.

 


MarcoMauri wrote:

Moreover if you don't care about the "Finished Late" of the timed loop I would suggest to use a normal loop,

or at least to place the communication part outside the timed loop....

 


I dont think I m clear about placing the "comm part outside  the timed loop ..." If I do that, then how do i collect data continuously. Of course I have the Open and Close UDP link functions outside the loop now. Please clarify. Thanks

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 7
(3,379 Views)

nathand wrote:

Unless I'm misunderstanding, the function you want does exist.  Set the timeout input of UDP Read to -1 and it will wait until there's new data available. 

 

Why are you using a timed loop, rather than a standard while loop?


Hmm .. possibly you have a point there.

 

I had already changed to a while loop and set the UDP read timeout to -1 right from begining. But I then also had put in a 10ms wait function inside the while loop, just so that it does not consume too much CPU resources. Maybe this "wait delay" is not needed ? Since the UDP read is waiting for data, the while loop will only fire when a set of data is in ??

 

By adding the 10ms wait delay am I constraining the process unneccessarily ?? 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 5 of 7
(3,378 Views)

Hi!

I would avoid using -1 as timeout as a general rule.

In fact if you stop receiving data your code will be blocked in the  UDP Read function forever.

 

Morover, to clarify my first post: maybe this time could be useful to use a producer/consumer model.

In the "producer" loop data could be collected via UDP (with handlig of timeout, network errors, etc.) and put in a queue, whereas a consumer loop can poll the queue

and process the data.

 

I wrote "maybe" because I don't know much about your application....

 

Cheers,

Marco

0 Kudos
Message 6 of 7
(3,330 Views)

MarcoMauri wrote:

Hi!

I would avoid using -1 as timeout as a general rule.

In fact if you stop receiving data your code will be blocked in the  UDP Read function forever.

...


Hi Marco,

i think you should use the -1. I think it's the best method, also for Queues and Notifiers and ... . You can stop all those processes with closing the reference assigned to it. In most cases the function will then stop with an error.

 

Mike

0 Kudos
Message 7 of 7
(3,321 Views)