Hi!
I am working on a project with several Atlas Copco controllers and I control all those Atlases with socket communication in Ignition..
I send and receive several messages from those Atlas (communication enable, program send and receive, socket bit selector, result message, keep alive message, ETC).
Everything works fine, but sometimes when I receive the result message, I receive it in parts.
It is a large message (386 characters), all other messages are less than 100 characters. I think my problem is in the way I decode the data. Any idea how to improve this?
This is the code to get the message, I think the "If data:" is the problem, because I decode the message without ensuring that it is complete.
But I repeat, I only have problems when I receive message 061 (386 characters).
get_message(client_socket, controller_id):
try:
while True:
data = client_socket.recv(1024) #MAYBE HERE IS THE PROBLEM????
if data:
returndata = data.decode('utf-8')
if returndata [4:8] != "9999": #dont print keep alive (9999)
print("Mensaje recibido del {}: N° Caracteres {} - {}".format(controller_id, len(returndata), returndata))
process_data(returndata, controller_id)
except Exception as e:
print("Error de E/S: {}".format(e))
This is an example of the problem, I first receive 256 characters and then the rest.
This is another example, first I receive 64 characters, then 128, then 192, and then 2.
In the second result I first receive 320 and then 66 (in my programming I have that if I receive more than 220 characters I proceed with the script because the atlas result is within the first 220 characters).
And this is a good example, here I get the 386 characters on the first try.
If I dont send an acknowledgement (message 062) to the Atlas controller, the controller sends the message again, so I do not lose the result, but the problem is that it takes several seconds to send the result again and a lot of cycle time is lost.
I know it's a lot of text but I hope I can find the solution here, thank you very much!