LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Receive UDP packets and display on waveform chart has problem

Solved!
Go to solution

My vi (UdpRevLV.vi) receive data form MFC , and decompose the datas. After I added  the code to quit the program(exit button),  the displayed waveform is distorted,  is that the reason I got  wrong data?  

correct wave is like thiscorrect wave is like thisnow wave seem distortednow wave seem distorted

Attach the code,please help me  .

Download All
0 Kudos
Message 1 of 7
(4,383 Views)

You do a single UDP read, then go into lengthy processing, filtering, loops, file writing, UDP writing, etc. until you do the next UDP read. During that time other packets might arrive and get lost. Why are your shift registers initialized with arrays containing one element instead of empty arrays?

 

Can you attach an example of the received string from a single UDP read? How long is the string?

 

Overall, most of your code is 10x too convoluted. Why do you have so many local variables, e.g. the length. You cannot guarantee that the local variable reads only occur after the indicator has been written. I see a few other race conditions: You read and write from locals in parallel (array 2, fstrings), but the result depends on what happens first.

 

Even the U8 array to single conversion could be done with much less code (also, index array is resizeable).:

 

CastSingle.png

 

0 Kudos
Message 2 of 7
(4,349 Views)

Hi,  thanks very much for your reply!!

   Actually, each time I received 100 float numbers from MFC, below is the example of received data(I make it displayed in Hex format, it's length  is 400):

recv_data.png

I'm really a novice. I really don't know how to simplified code.Thank you for the solution of U8 array to float number, it is really amazing.

 

I want read from UDP port and change them to float numbers, display on a Waveform Chart, and filter these data, finally send back these filtered datas. Only after filtered these datas will be send back. I use a Flat Sequence Structure between the three sections. As you mentioned the local variables.  I do not know how much datas are received each time in real terms, so I use local variables.But when testing, I send 100 data at a time.

0 Kudos
Message 3 of 7
(4,339 Views)

Please attach the data as a VI (e.g. right-click the indicator containing the data...create constant, copy that constant to a new VI and attach it here). I cannot copy/paste strings from an image.

0 Kudos
Message 4 of 7
(4,330 Views)

Sorry,  here is the data.

0 Kudos
Message 5 of 7
(4,326 Views)
Solution
Accepted by Tinafan

(Thanks. Sorry it was a little late last night)

 

I cannot analyze your code because it is just way too convoluted, but here is my suggestions. Use multiple loops. One tight loop that just reads from UDP and places the unfiltered data in a queue. This way the VI is virtually always ready to receive data. (Remember that UDP is connectionless and if packets arrive when you are not listening, it gets discarded).

 

You are still doing all this with 100x too much code. To convert the 400 bytes of data to a SGL array, all you need to do unflatten it using little endian byte order. (except for the filtering, this replaces your entire gigantic while loop!! :o). I haven't looked in detail at the rest of you code, but I am sure that similar simplifications can be done in many places.

 

So, in summary, you need to have a simple receive loop that places the data in a queue to be processed asynchronously.

 

UnflattenFromUDP.png

0 Kudos
Message 6 of 7
(4,289 Views)

Thanks very much. I will remember your suggestions .Though, I have not use the queue yet, I would have a try, hoping to make my program simpler in some way. 

Last, really thank you for your advice and efforts again!

0 Kudos
Message 7 of 7
(4,275 Views)