Left ArrowBack to discussions page
PrasannaPrasanna Posts: 18 Apprentice

i want to send the variable value through socket. but i cannot.
For example, a=10

instead of receiving move(10), i received move(a).

correct me if am wrong.
Note: UR3 e series controller

Best Answers

  • matthewd92matthewd92 Posts: 791 Handy
    edited April 11 Accepted Answer
    The reason is you are sending the string of “move(a)”, this doesn’t automatically equate to “move(“ + a + “)”. The program does not know that you want to concatenate a variable inside that, you will need to tell it this using script functions from UR. 

    Msg= str_cat(str_cat(“move(“,a),”)”) #Msg would be “move(10)” now
    socket_send_string(Msg) #No quotes, we are sending the value of the variable Msg

    Make sense?
  • matthewd92matthewd92 Posts: 791 Handy
    Accepted Answer
    So the UR function str_cat, takes two arguments, so you would just continue to nest the functions together to get enough arguments.

    Also, UR does not allow the use of `+` with strings like other languages do, string manipulation is actually a fairly recent addition to the script language, I think 3.8 but it may have been 3.7.

    So for example:
    a = 10
    b = 20
    c = 30
    msg = str_cat(str_cat(str_cat(str_cat(str_cat(str_cat("move(",a),","),b),","),c),")")
    #Result of msg is move(10,20,30)


Sign In or Register to comment.
Left ArrowBack to discussions page