LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble on getting transferred buffer from "clientTCPRead"

Solved!
Go to solution

 

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!

 

Download All
0 Kudos
Message 1 of 4
(3,604 Views)

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.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,568 Views)
Solution
Accepted by topic author syHan

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,).

 

 

Message 3 of 4
(3,527 Views)

 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. 🙂

0 Kudos
Message 4 of 4
(3,500 Views)