【CSEN039】Robot as socket client to communicate with external devices

The robot can be used as a socket client to communicate with external devices. The relevant commands can be found in the CS Robot Scripting Manual (https://www.eliterobots.com/downloads/)

For example, the following script can be created in the robot

socket_open("192.168.126.19",60000,"socket_1")
# Open the socket, here the IP address is the IP address and port of the server on the PC.
global recv
# Create a global variable with the keyword global, the value of which can be viewed in real time in the monitor window of the teach pendant.
while True:
  socket_send_string("Hello world","socket_1")
  #Send a string to the server
  recv = socket_read_string(socket_name="socket_1",timeout=120)
  # Receive a string from the external, if timeout is 120s, the robot runs directly the following instruction
  sleep(0.1)

Open the PC server side, monitor port 60000, and then run the script in the robot, we can get the following effect:

The socket_read_ascii_float(3) instruction can be used in the robot script to split the received data directly.

Requirements: The received string starts with "(", ends with ")", and the intermediate data is separated by ",".

                        The parameter in the command indicates the maximum number of data sets to be read.

                        If the robot receives "(1,2,3)", the function returns data as [3,1,2,3], the 0th element of the array indicates the number of data received, followed by the contents of the data split automatically.

socket_open("192.168.126.19",60000,"socket_1")
# Open the socket, here the IP address is the IP address and port of the server on the PC.global recv
# Create a global variable with the keyword global, the value of which can be viewed in real time in the monitor window of the teach pendant.
recv = [0,0,0,0]
while True:
  socket_send_string("Hello world","socket_1")
  recv = socket_read_ascii_float(3,socket_name="socket_1",timeout=120)
  # Receive a string from the external of the form (1,2,3), if timeout is 120s, the robot runs directly the following instruction
  sleep(0.1)

点击显示全文
赞同0
发表评论
分享

手机扫码分享
0
438
收藏
举报
收起
登录
  • 密码登录
  • 验证码登录
还没有账号,立即注册
还没有账号,立即注册
注册
已有账号,立即登录
选择发帖板块
上传文件
举报
请选择举报理由
举报
举报说明