01-10-2014 10:31 AM
Hi
I'm receiving a string "Hello" from TCP from a C-program, where I have to display this string in a string indicator in LabVIEW.
I have the following block diagram I found among the examples:
The point here is that I can only read the last character "o" in the indicator when I change the "bytes to read" value to 4 bytes, but can read the characters "ello" when setting the bytes to read value to 1. How do I read the whole "Hello" string ?.
01-10-2014 12:44 PM
You need to understand what that code is doing. That code expects to receive a 4-byte value indicating the number of bytes of data, followed by the actual data. If you send the string "Hello" without that byte count, it won't work as expected. When you set bytes to read to 1, you read the "H" which then gets type cast to an integer. Since the ASCII value of "H" is more than 4, you read the following 4 bytes. When you set bytes to read to 4, it captures the first 4 characters (H e l l), leaving only the "o" when you do the second read. To read all of "Hello" you should either send the value "5" (NOT the text "5" - these are different concepts) in 4 bytes prior to the the actual string (and set Bytes to Read to 4), or you should do only a single TCP Read for 5 bytes since that's the length of Hello.
01-10-2014
02:35 PM
- last edited on
11-06-2024
06:52 PM
by
Content Cleaner
Since you are sending a string, I would try using "CLRN" mode on TCP Read. Then you can trigger it to read all the text until the "/r/n" characters in C.
Otherwise, you need to follow the instructions per protocol;
bytes to readis the number of bytes to read. Use one of the following techniques to handle messages that might vary in size:
|