09-14-2012 02:32 AM - edited 09-14-2012 02:38 AM
Hello!
I am using clientTCPRead callback function to get a response from the server(actually a motor) once I send a simple command.
When I send some command, I receive a string,"12345"(which is position), and display this on the TEXTBOX control. It works fine.
However, when I display it on STRING control, the control shows only "2345" or "345".
(By using strlen() to check the length of the RECEIVED_STRING, I get 5 when the control shows "2345" and 4 when "345".
I have no idea why the length of RECEIVED_STRING varies and I think it is too short to contain the string "12345".
Maybe strlen() gives the size of "2345" or "345" which makes sense. 😐
Please save me from this trouble 😞
I attached the uir and code in order to help you understand it better.
Thank you in advance!
Solved! Go to Solution.
09-17-2012 06:02 AM
Hi syHan,
What version of CVI are you using? What OS are you on? Is there a reason why you cannot use Text Boxes? According to the CVI help they were designed to hold more data than string controls.
Regards,
Perry S.
09-18-2012 02:01 AM - edited 09-18-2012 02:03 AM
hi,
ClientTCPRead returns number of bytes read from TCP and stored to buffer(so no need to call strlen).Also sometimes it is possible that not all data is read at one ClientTCPRead call so it is need to wait when all expected data is read. can be done by read in multiple TCP callback or in while loop . TCP is stream protokol, not paket protokol, so it is not guaranted that when anyone send data in one Send call, that other side read it in one call too.
Second problem may be if response data does not end with zero byte{this can cause random crash of program}, because SetCtrlVal for STRING/TEXTBOX need standard C Zero terminated string. You can simply add it with something like RECEIVED_STRING[datasize]=0; after suscefful ClientTCPRead call(beware of zero or negative return value). But be sure that there is enought space i.e. ClientTCPRead (,,dataSize-1,).
09-19-2012 12:52 AM - edited 09-19-2012 12:54 AM
Thank you, ovr_cz!
I found that "clientTCPRead" read only "1" instead of "12345" for the first call, so I read the rest of the string "2345" and added them together. 🙂