LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Images over UDP transmission

Solved!
Go to solution

Hi

 

I need to grab images from a webcam, convert them to pixel values of 2d arrays and finally transmit them through UDP to a c-code. I have made a test vi, which is based on UDP transmission in the same vi. The 2d array in the receiving part doesn't show anything when I run the code. What's the problem actually ?.

Best regards

Oesen
0 Kudos
Message 1 of 7
(4,696 Views)

In your sending loop, you are first sending the string length as 4 bytes (I32 typecast to a string.)  Then sending the string after flattening from a 2-D array of U32.

 

On the receiving end, you are ignoring those first 4 bytes, then trying to unflatten it to a string array.  Why?  It was originally a U32!  Then you try to convert this string data to a number, which won't make anysense becuase what you have now is a bunch of binary data, and won't look like a number formatted as a string.

 

Read the 4 length bytes then typecast to an I32.  Then read that many bytes.  Then unflatten the string into a U32 2-d array.

Message 2 of 7
(4,689 Views)

Thanks for the reply RavensFan

 

I have tried to change the receiving part like that, but it still doesn't work. What's actually wrong here ?.

 

Untitled.png

Best regards

Oesen
0 Kudos
Message 3 of 7
(4,646 Views)
Solution
Accepted by topic author Oesen

You should be using TCP, not UDP. The technique you're attempting will not work, or at least will not work reliably, with UDP. Quoting from the help, about the max size parameter: "The default is 548. (Windows) If you wire a value other than 548 to this input, Windows might return an error because the function cannot read fewer bytes than are in a packet." Have you checked for an error? Do you know if you receive all the bytes that you expect? UDP is not designed for sending large streams of data in which every packet must arrive.

 

Also, this doesn't solve your problem, but move IMAQ Create outside the while loop. IMAQ Create creates a reference to a memory location, and you only want to do that once, then reuse the same image memory over and over again.

Message 4 of 7
(4,638 Views)

The speed is absolutely the most important factor for me. I don't care of the transmission quality and the flow control, but the speed. That's the reason why I have chosen to transmit through UDP. It is quite difficult to find any examples with 2d array data transmission through UDP in LabVIEW. Do you know, whether it is possible to complete the transmission through UDP?.

Best regards

Oesen
0 Kudos
Message 5 of 7
(4,630 Views)

But you don't understand how the networking works. UDP packets have a fixed, maximum size. That size is much less than the size of one of your images. If you lose even a single packet, you won't know, and all the data after it will be incorrect. The reason that there are no such examples is because it's a bad idea and likely to be unreliable. Switch to TCP. While it's certainly possible to make it work, especially if you're transmitting over a loopback connection (sending and receiving are on the same machine) where there is almost no possibility for packet loss, you would still need to deal with limiting the size of your reads and writes to the maximum packet size.

 

If you really, really need maximum transmission speed, then the way you do it is through a sophisticated algorithm that sends only the differences between successive images, in a way that each set of changes fits into a single UDP packet. Then, if you lose one packet, you haven't lost too much, and you're not sending redundant data.

Message 6 of 7
(4,623 Views)

Thank you very much nathand

Best regards

Oesen
0 Kudos
Message 7 of 7
(4,594 Views)