TCP/IP Communication with C - read_ascii_float () issue

Hi - Newbie mistake that I posted this initially in a closed thread. Here it is as a new thread.

Hello - I have been following this (TCP/IP Communication with C++) thread and have a question. I got this to work but I only get the updated data[] after I stop the robot program and then restart.

I have my socket open connection in a thread. After the connection is made, I then send the ready message to my connected pc, then the pc sends the 4 values in Data[]. but if I view at the Data[] in the variables on the pendant, while running the program, they don’t update until I stop the program.

Am I not allowed to run the socket in a thread? Do I need to continually open and then close the socket for each data exchange or can I keep it open until the program ends?

Here is the program If you don’t mind taking a look. I initialize the Data[] and other variables. Connection is working and I am receiving the other data from the UR as expected.

Thank you!!

Perhaps you’ve missed my answer in that thread to your question, so here’s a re-post of my answer:

When a socket closes, any pending data is flushed to the receiving application. The reason why you won’t get is sooner is because you didn’t complete the data packet from the PC side. Missing ) perhaps?

  • I used Winsocket on the server to send data:
    string sendBuf = “(00110001, 00110001, 00110001)”;
    send(sClient, (const char *)&sendBuf, strlen((const char *)&sendBuf), 0);
    Socket_read_ascii_float () used on UR side could not receive data , Do you know the reason?
    Do you know which format to send data in winsocket and socket_read_ASCIi_float () on UR to receive data correctly.
    Looking forward to your reply.
    Thanks

I believe the “float” values should be a string literal, eg “56.3” So as a “human readable” format. SendBuf = “53.4”; would be decoded by Socket_read_ascii_float() correctly. Since your version has 3 fields seperated by comma’s, the robot will decode it as an array of data, but invalid since the first number should be the number of items in that array.