Assuming the data from external device is "3.1,232.4,-232.123,ok#", which is a string contains 3 sets of number and term ok seperated by comma, then end with the # sign.
The user need to analysis the data, by check the data ends with ok or not to decide post work flow.
The following is a example to convert the 3 numbers to float if the data ends with ok.
socket_open("192.168.230.1",60000,"socket_1")
# Open socket, the IP address 192.168.230.1 and port number 60000 are belong to the external device.
global recv # Data received, will remove the # sign
global data # Store the effective data
# Global variable can be monitored in the monitor window on the teach pendant
while True:
socket_send_string("Hello world#","socket_1")
# Send string to server
recv = socket_read_string(socket_name="socket_1",suffix="#",timeout=120)
# Assume the data received is '3.1,232.4,-232.123,ok#', use suffix="#" can remove the # at the end
# So recv stores '3.1,232.4,-232.123,ok'
b = str.split(recv,',')
# Split data in recv by comma and store in the list b
data = [float(b[0]),float(b[1]),float(b[2])]
# Since the elements in b are float numbers, so float function can convert string to float directly
sleep(0.1)