1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
Everywhere
  • Everywhere
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Members
  3. Andrea

Posts by Andrea

  • Communication EthernetKRL-Python

    • Andrea
    • July 4, 2024 at 7:37 AM

    Hi, I did some tests and it's as you said, the server was being closed too soon. I made some changes to my Python script and now it works. Here is my code:

    Code
    import socket
    import time
    import threading
    
    def handle_client(conn, addr):
        try:
            while True:
                request = '<Sensor><Nmb>11</Nmb></Sensor>'
                time.sleep(0.5)
                conn.sendall(request.encode('ascii'))
                print(f"Request sent to robot {request}")
        except Exception as e:
            print(f"Error: {e}")
        finally:
            conn.close()
            print(f"Connection with {addr} closed")
    
    def start_server(server_ip, server_port):
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            s.bind((server_ip, server_port))
            s.listen()
            print(f"Server listening on {server_ip}:{server_port}")
    
            while True:
                conn, addr = s.accept()
                print(f"Connected by {addr}")
                client_thread = threading.Thread(target=handle_client, args=(conn, addr))
                client_thread.daemon = True
                client_thread.start()
    
    if __name__ == "__main__":
        server_ip = '192.168.10.100'
        server_port = 59152
        start_server(server_ip, server_port)
    Display More

    Thank you so much!!!

  • Communication EthernetKRL-Python

    • Andrea
    • July 3, 2024 at 6:21 PM

    Yes, I have also seen the documentation but it is not specific. The peculiar thing is that it works with Hercules (https://www.hw-group.com/software/hercules-setup-utility). I tried with Wireshark, but it's not very clear. You can find the Wireshark screenshots at this link: https://imgur.com/a/HaDcjU6. The Wireshark files are available for download for 7 days from today at this link: https://we.tl/t-yWUcP8hBv8

  • Communication EthernetKRL-Python

    • Andrea
    • July 3, 2024 at 3:42 PM

    Thank you for the response. Disregarding EOS was just a test; I have removed it, but the problem remains. I am using EthernetKRL V3.2.3 on KSS 8.7.7 and am using the KUKA XmlTransmit example with some modifications.

  • Communication EthernetKRL-Python

    • Andrea
    • July 3, 2024 at 10:23 AM

    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

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download