01-12-2014 01:31 PM
Hi.
I am sending an array of 8-bit unsigned integer with the size 19203 from a TCP server in a c-program to a TCP client in LabVIEW. I have managed to receive the data as shown in the picture below. The first byte, that is sent by the c-program is the header. The second and the third byte represent the size of the array, which is actually 160x120. Then the rest 19200 bytes are the actual values for the array.
My TCP client code looks like this:
The issue occurs when I'm replacing the Type Cast with the Unflatten to string function, and adding a dimension to both arrays. The first two values in the array (120 and 160) should inform the Unflatten to string function about the size of the array, but I don't get any data in the array indicator. Is there any way to create a 160x120 sized 2d array from 8-bit uint data ?.
Solved! Go to Solution.
01-12-2014 01:55 PM
Oesen,
Your client code with the 1D array gets the data, just not in the 2D format, right? If so, use Reshape Array. This also can adapt automatically to any size of 2D array where the first two elements of the 1D array contain the dimensions of the 2D array. I put the code outside the loop just because there was space on the BD there. It can be moved inside if you get multiple messages.
Lynn
01-12-2014 04:14 PM
Can this one be used for at color image btw ?
01-12-2014 04:22 PM
I do not have the Vison stuff, so I cannot say.
Lynn
01-12-2014 04:28 PM
@Oesen wrote:
Can this one be used for at color image btw ?
Yes. That is "IMAQ ArrayToColorImage" which writes a 2D array of U32 to an image.
01-12-2014 05:14 PM - edited 01-12-2014 05:14 PM
The problem is that I'm always getting blue images as a result
And I have chosen a 32-bit RGB image in the image create. I'm generating random numbers from a c-program from 0-4,294,967,295 and sending them directly to this LabVIEW Vi. I don't really understand, why it always creates an image with the same color, everytime I'm generating new pixel values.
The Vi is like this:
01-12-2014 05:49 PM
Please stop posting variations on the same code in so many places. I already explained here that it will not work to read a single byte and type cast it to a 4-byte value; you'll get the wrong result, and will then read the wrong number of bytes following. If your C code generates a continuous stream of numbers, and doesn't send a length first, then you should do a single TCP Read for the correct number of bytes. It doesn't help to copy examples blindly if you don't take the time to understand what they do. Also, your code reads and discards data until the stop button is pressed, at which point it tries to convert whatever random data was read most recently into an image. Does your C code send the array dimensions? If not, then your array manipulation won't work. In what format does your C program send data?
01-12-2014 06:04 PM - edited 01-12-2014 06:05 PM
I'm sending an array of 76812 bytes from my c-program.
The first four bytes is the header, I defined it to be "1"
The second four bytes is the array dimension "160"
The third four bytes is the array dimension "120"
The last 76800 bytes is the randomly generated uint32 pixel values from 0 to 0-4,294,967,295.
01-12-2014 06:48 PM
Now you are giving completely different specifications. You now have everything coming in four-byte chunks rather than the single bytes mentioned earlier.
This code will handle conversion of a string to U32.
Lynn