Hello Zaldor,
you should not send “256” char to RIOS if you only need to send 21,
else RIOS will have to deal with 235 unwanted char, and maybe some of them are “<” and RIOS is waiting the according “>” till the timeout.
you can’t use socket so simply as using “send” / “recv”, a socket is more complex,
to send it’s ok, just use “send” but only send the correct number of char needed, not a full 256 bytes buffer filled with char that RIOS don’t need.
Adding to this you should always clear the outgoing AND the incoming buffer (not your buffer but the socket one) before sending new fresh data
To read it’s more complex, a socket will not send to you the full bytes you need in a row in many cases (not RIOS fault).
To correctly read a socket :
-
You should use a read event, this way the main code is able to run, and it will be interrupted only if incoming datas are coming and will execute the “read event” part of the code.
if you don’t use an event it will work but the code will be more difficult to build and your program will hang while waiting full data from the socket.
-
you’ll have to check for incoming “" char meaning RIOS is answering something, then you need to find in the buffer (not in the full 256 bytes buffer you’re using but only in the fresh new bytes) the other "” finishing the “word” that RIOS sent
use the “int” returned by the recv function to know how many bytes received from RIOS thru the socket and use this value in a "for " loop to scan your buffer.
if no second “" was found, store the current fresh bytes in another buffer and read again to have more bytes till you get the second "” this way you will always get full word from RIOS.
it’s not a RIOS issue, RIOS is sending all datas at a time but the socket is working in a different way, cutting some data in blocks…or not.
That’s why RIOS is sending how many lines will be send when you ask “xxx:list” this way, extracting the number in the "Count:xxx) text line you know how many lines you need to read after the “count” one.
you should take a look at the small demo program code (*.cpp files)
it’s C++ but it’s the way you should read a socket that you may inspire yourself from the code, not really the code itself as it’s different.
Basically when i send an order to RIOS i’m initializing an “int” variable for the Read event to know what kind of answer it will receive ( a list, a message to display, a simple word etc…) then when datas are incoming from RIOS it interrupts the program and it goes to the read event that build complete “word” checking for “" couples in the flow, checking if a “count” word is in (if waiting a list) and then read “count” line and store them…then it really do something according to RIOS answer only when all data are read, cut in words using the "” couples and stored in a clean “lines” (AnsiStringList) buffer (not the read buffer)
if i need to lock the program buttons while waiting an answer from RIOS (to avoid sending too much information and generate data colision) i’m setting the buttons “activated” property to “false” then to “true” when ready again.
The main problem i had to deal with when building the socket demo program was the “read algorithm”, you will see what i mean if you look in the code (the tips to understand the code is to know the “read” event code is running automatically when incoming data occurs)
then you need to use a timeout (see my code) to stop waiting after 1 or 2 seconds.
i hope it help.