For anyone who may face the same issue as mine, I would like to summarize my mistakes for your information:
Regarding the error "Signal flow (running): Object ETHERNET 1 returns error RSITimeout" there are two causes, one is the Ethernet communication isn't set up correctly, the other is the IPOC tag.
1. Port number: I used the same port number for server and message sent to client (robot) by the server, which is wrong. The port number of client can be defined, but in this case it is automatically allocated by robot itself, and it is not 59152. A naive mistake.
2. IPOC: I guess this IPOC tag in xml file is used as timestamp. In the packets back and forward between example Testserver.exe and robot, they have the same IPOC number. (I guess) With some level of tolerance, a same IPOC number should be sent back to robot within 100 cycles, otherwise this RSI timeout error happens.
3. xml.etree.ElementTree: the functions from this library needs some time to execute, be caution of timing.
and the following is my UDP server code:
import socket
import os
import time
import xml.etree.ElementTree as ET
count = 0
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_addr = ('192.168.1.1',59152)
s.bind(server_addr)
print('Bind UDP on 59152...')
cnt=0
timestamp=0
output='<Sen Type="ImFree"><EStr>Message from RSI TestServer</EStr><Tech T21="1.09" T22="2.08" T23="3.07" T24="4.06" T25="5.05" T26="6.04" T27="7.03" T28="8.02" T29="9.01" T210="10.00" /><RKorr X="0.000" Y="1.0000" Z="0.0000" A="0.0000" B="0.0000" C="0.0000" /><DiO>125</DiO><IPOC>'+str(timestamp)+'</IPOC></Sen>'
while True:
data, client_addr = s.recvfrom(1024)
if cnt==0:
f = open("input1.xml", 'wb')
f.write(data)
f.close()
input = ET.parse("input1.xml")
in_root = input.getroot()
for ipoc in in_root.iter('IPOC'):
timestamp=ipoc.text
else:
timestamp=str(int(timestamp)+4)
output='<Sen Type="ImFree"><EStr>Message from RSI TestServer</EStr><Tech T21="1.09" T22="2.08" T23="3.07" T24="4.06" T25="5.05" T26="6.04" T27="7.03" T28="8.02" T29="9.01" T210="10.00" /><RKorr X="0.000" Y="0.0000" Z="0.0000" A="0.0000" B="0.0100" C="0.0000" /><DiO>125</DiO><IPOC>'+str(timestamp)+'</IPOC></Sen>'
cnt=cnt+1
print(client_addr)
s.sendto(output.encode(),client_addr)
Display More