Hi, I am trying to establish communication between the robot and a Python script. I have purchased the EthernetKRL add-on package. When I execute the communication between the robot and Hercules, I can both receive and send data, and the variable Nmb is set. However, when I use my Python script, I can receive data from the robot, but I cannot set the variable; the robot shows the error: EKI00512. I have changed the encoding in Python, the libraries for TCP/IP communication, and tried using Java as well. Thank you in advance.
Python script:
Code
import socket
def start_server(server_ip, server_port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((server_ip, server_port))
s.listen()
print(f"Server listening on {server_ip}:{server_port}")
while True:
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
try:
request = "<Sensor><Nmb>10</Nmb></Sensor>"
bytesToSend = str.encode(request)
conn.sendall(bytesToSend)
print(f"Request sent to robot: {request}")
response = conn.recv(4096).decode('utf-8')
print(f"Received response from robot:\n{response}")
except Exception as e:
print(f"Error: {e}")
finally:
conn.close()
if __name__ == "__main__":
server_ip = '192.168.10.100'
server_port = 59152
start_server(server_ip, server_port)
Display More
Kuka program:
Code
&ACCESS RVP
&REL 16
&PARAM SensorITMASK = *
&PARAM TEMPLATE = C:\KRC\Roboter\Template\vorgabe
&PARAM DISKPATH = KRC:\R1\Program
DEF XmlTransmit( )
;FOLD Declaration
INT i
INT valueInt
DECL EKI_STATUS RET
CHAR valueChar[256]
REAL valueReal
BOOL valueBOOL
FRAME valueFrame
;ENDFOLD (Declaration)
;FOLD Communicated data
;FOLD receive from external program
; <Sensor>
; <Message>Example message</Message>
; <Positions>
; <Current X="4645.2" />
; <Before>
; <X>0.9842</X>
; </Before>
; </Positions>
; <Nmb>8</Nmb>
; <Status>
; <IsActive>1</IsActive>
; </Status>
; <Read>
; <xyzabc X="210.3" Y="825.3" Z="234.3" A="84.2" B="12.3" C="43.5" />
; </Read>
; <Show error="0" temp="9929">Taginfo in attributes</Show>
; <Free>2912</Free>
; </Sensor>
;ENDFOLD (Receive from external program)
;FOLD Send to external program
; <Robot>
; <Data>
; <ActPos X="1000.12">
; </ActPos>
; <LastPos A="..." B="..." C="..." X="..." Y="..." Z="...">
; </LastPos>
; </Data>
; <Mode>ConnectSensor</Mode>
; <RobotLamp>
; <GrenLamp>
; <LightOn>1</LightOn>
; </GrenLamp>
; </RobotLamp>
; <Status>12345678</Status>
; </Robot>
;ENDFOLD (Send to external program)
;ENDFOLD (Communicated data)
;FOLD INI
;FOLD BASISTECH INI
BAS (#INITMOV,0 )
;ENDFOLD (BASISTECH INI)
;FOLD USER INI
;Make your modifications here
;ENDFOLD (USER INI)
;ENDFOLD (INI)
;FOLD Initialize sample data
FOR i=(1) TO (256)
valueChar[i]=0
ENDFOR
valueInt=0
valueReal=0.0
valueFrame={X 0.0,Y 0.0,Z 0.0,A 0.0,B 0.0,C 0.0}
valueBOOL=FALSE
;ENDFOLD (Initialize sample data)
RET=EKI_Init("XmlTransmit")
RET=EKI_Open("XmlTransmit")
;FOLD Write data to connection
; Write frame to <LastPos X="" Y="" Z="" A="" B="" C="" />
;RET=EKI_SetFrame("XmlTransmit","Robot/Data/LastPos", TOOL_DATA[1])
; Write real to <ActPos X="" />
;RET=EKI_SetReal("XmlTransmit","Robot/Data/ActPos/@X", 1000.12)
; Write int to <Status></Status>
;RET=EKI_SetInt("XmlTransmit","Robot/Status", 12345678)
; Write string to <Mode></Mode>
;RET=EKI_SetString("XmlTransmit","Robot/Mode","ConnectSensor")
; Write bool to <LightOn></LightOn>
;RET=EKI_SetBool("XmlTransmit","Robot/RobotLamp/GrenLamp/LightOn",true)
;ENDFOLD (Write data to connection)
;FOLD Send data to external program
;RET = EKI_Send("XmlTransmit","Robot")
WAIT SEC 1
;ENDFOLD (Send data to external program)
;FOLD Get received sensor data
; Get string in <Message>Example message</Message>
;RET=EKI_GetString("XmlTransmit","Sensor/Message",valueChar[])
; Get real value in <Current X="4645.2" />
;RET=EKI_GetReal("XmlTransmit","Sensor/Positions/Current/@X",valueReal)
; Get int value in <Nmb>8</Nmb>
RET=EKI_GetInt("XmlTransmit","Sensor/Nmb",valueInt)
; Get bool value in textnode <IsActive>1</IsActive>
;RET=EKI_GetBool("XmlTransmit","Sensor/Status/IsActive" ,valueBOOL)
; Get bool value in attribute <Show error="0" />
;RET=EKI_GetBool("XmlTransmit","Sensor/Show/@error" ,valueBOOL)
; Get frame in <xyzabc X="210.3" Y="825.3" Z="234.3" A="84.2" B="12.3" C="43.5" />
;RET=EKI_GetFrame("XmlTransmit","Sensor/Read/xyzabc",valueFrame)
;ENDFOLD (Get received sensor data)
CPosition=valueInt
RET=EKI_Close("XmlTransmit")
RET=EKI_Clear("XmlTransmit")
END
Display More
Kuka xml file:
Code
<ETHERNETKRL>
<CONFIGURATION>
<EXTERNAL>
<IP>192.168.10.100</IP>
<PORT>59152</PORT>
</EXTERNAL>
</CONFIGURATION>
<RECEIVE>
<XML>
<ELEMENT Tag="Sensor/Nmb" Type="INT" EOS="13"/>
</XML>
</RECEIVE>
<SEND>
<XML>
<ELEMENT Tag="Robot/Data/LastPos/@X"/>
<ELEMENT Tag="Robot/Data/LastPos/@Y"/>
<ELEMENT Tag="Robot/Data/LastPos/@Z"/>
<ELEMENT Tag="Robot/Data/LastPos/@A"/>
<ELEMENT Tag="Robot/Data/LastPos/@B"/>
<ELEMENT Tag="Robot/Data/LastPos/@C"/>
<ELEMENT Tag="Robot/Data/ActPos/@X"/>
<ELEMENT Tag="Robot/Status"/>
<ELEMENT Tag="Robot/Mode"/>
<ELEMENT Tag="Robot/RobotLamp/GrenLamp/LightOn"/>
</XML>
</SEND>
</ETHERNETKRL>
Display More