05-26-2025 02:53 AM
Hello everyone,
I’m using the TCP READ block to read packets with 3 columns and 1000 rows, but I can’t manage to store them in an array. A line is writen like this: "CH0: %f,CH1: %f,CH2: %f".
I’m trying to use a for
loop, but I’m not sure if I’m on the right track.
Thanks in advance to anyone who takes the time to look into my question.
05-26-2025 04:16 AM
You're on the right track. Just a couple of changes. Your TCP response has multiple lines I assume, separated by some delimiter (usually new line (\n)), so convert those lines to an array of strings. Then loop over each element of that array. Move the indicator outside the loop:
Also, on the front panel, set the index of your array to 0, 0. Not 1000, 3. It doesn't set the size, but which index to display on the top left.
05-26-2025 04:46 AM
Thanks for your help.
Now that I have all 1000 strings collected, I'm facing a problem with the format I'm using: Error 85 occurred at the "Scan From String" function in LabVIEW.
Maybe I need to define the format inside its own for
loop?
05-26-2025 05:54 AM
Do you really get 1000 items in the array? Your TCP read should stop after 512 characters, that does not line up with your format string. You already have 1000*18 bytes in your table without accounting for the actual numbers. So TCP Read will stop somewhere in the middle of a row, leading to a mismatch with the format string.
Drop an indicator on the front panel or use probes to see what was actually transmitted.
You could use another loop that builds the string and only when the end matches CRLF convert the collected data.
TCP Read until CRLF
Could you just sent the rows individually or does it have to be 1000 rows at once? I find it confusing to use CRLF as the transmission termination character and an LF for row termination.
Even if you get 1000 items, the last array item is probably an empty string, which does not match your format string. You can drop the last array item or filter out empty strings.