How to send data from Python to the Doosan in your own custom format

:bangbang:Because the Doosan has an old python version from 2011 (Python 3.2) that you can’t update, there are limitation about the core librarys that you can use.:bangbang:

Socket server

  1. First you need a socket server connection between de Doosan and your pyhton script. Follow this How-to: How to establish a socket connection to a doosan robot & a laptop

Pyhton code
In this example, the socket server is run in a thread so that the rest of the python code can continue to run and the server’s queries cannot block the python code.

  1. The data that is going to be sent must always be in a string.
    In the code, you can see that the socket server is waiting for a response from the Doosan. If that answer matches [QUESTION], the server sends the data to the Doosan
import threading
from socket_server import TcpSocketServer

def socket_thread(tcp_server, data_lock, data_container):
    tcp_server.start_server()
    tcp_server.accept_client()
    
    while True:
        response = tcp_server.receive()
        if response:
            print(f"Received: {response}")
            if response == "[QUESTION]":
                with data_lock:
                    data_string = data_container.get("data")
                tcp_server.send(data_string)
        else:
            print("No response received.")

server_ip = "192.168.137.50"  # Localhost
port = 20002

tcp_server = TcpSocketServer(server_ip, port)

data_lock = threading.Lock()
data_container = {}

# Start the socket communication thread
threading.Thread(target=socket_thread, args=(tcp_server, data_lock, data_container), daemon=True).start()

while True:
  # data that needs to be send
  send_data = [10, 147, 382]
  
  # convert data to a string
  data_string = ','.join(map(str, send_data))
  
  # Update the data container with new data to send
  with data_lock:
      data_container["data"] = data_string

Doosan code
3. Run the following code on the Doosan.
The Doosan asks the socket server for a new value ([QUESTION]). Then it reads from what the server sends to it.

from DRCF import *

sock = client_socket_open("192.168.137.50" , 20002)

while sock:
    msg = "[QUESTION]"
    client_socket_write(sock, msg.encode())

    res, rx_data = client_socket_read(sock)
    rx_msg = rx_data.decode()
    tp_log("{0}".format(rx_msg))

@20129556 please add limitation about that you can only use core lib from a particular Python version on the Doosan