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)