String split to an array


I use a Sensopart camera with my Universal Robot and I would like to get the information that the camera sends to the robot.
I can receive the data from the camera in the form:
“[1,2,3,4]” or “(1,2,3,4)”. As you can see these are strings.
So I wanted to know, if there is a way to get this data in the form of an array ?

Thank you in advance !

Not sure about URScript but in vbscript or python it would be something like:

my_string = 'A,B,C,D,E'
my_list = my_string.split(",")
print my_list
['A', 'B', 'C', 'D', 'E']

Yes I know, but it doesn’t work with URScript unfortunately

@sam67500du not sure your specific mode of communication between camera and UR but if you are using socket communication try:

socket_open(IPv4camera,Port camera)
Loop (Receieved_data[0]≠30)

if the camera can send the values in the format below you might be golden

“ ( val_1, val_2 , … , val_30 )\n  “

The UR will receive the data as

Received_data:=[len.array.sent, val_1 , val_2 , … , val_30]

As you can see the first value in the ARRAY is the length of the data that was received, this is useful for the LOOP above to ensure (act as a checking mechanism) until ALL points in the array are received from the camera before kicking out and closing the socket. The only hiccup here is that you are limited to 30 values, you can change this to a smaller number if you don’t need all 30 and for instance are only going to send/receive 6 values. To use the data in Received_data start with


Use [1] instead of [0] and index up from there otherwise you’ll end up using the length of the array received rather than the first data point in the ACTUAL array.

See URscript manual, there are other useful socket commands for sending/receiving data.

Another way would be to pre-allocate an array of zeros (not sure the limitation on UR for size of arrays) and have a for-loop that reads a data point from camera and drops in in the array and then indexes to the next position and rinse and repeat, but again you would need to see the other socket commands in URscript manual.

The UR community might have a better suggestion, but hope that helps and best of luck!

**edit - re-read your question and you have an interesting problem, might need to use the URscript string functions to interpret your data and do some manipulation to store it in an array.
A) ugly brute force, if values are INTEGERS & 0-9 only (highly doubt this is the case) you might be able to get away with using str_len() and a for-loop to grab values of every other (skipping commas + parentheses) until str_len() is met and put those into a new variable
B) using URscript commands like str_at() and str_len() create a .script file to dump string into and search for special characters that separate data like “ ( ” or “ , “ or “ ) “ and then put the data into an array. Someone in this community has probably done something like this

These are both not ideal so I apologize if this doesn’t help.

Hello Sami,

I only saw this message right now. Sorry. Did you solve the problem or is it still open?

Are you using the SensoPart URCap or the Script functions we provide on our website?
Maybe you can contact our support team They might be able to help, too.

Thank you and best regard