[Solved] Appending parentheses in PLC to make floats UR-readable

We are trying to send floats from the PLC (REAL in the PLC) to the UR over TCP. The connection works, and we can send data between the two.

The trouble arises with socket_read_ascii_float() on the UR, because it expects (float,float,float) (including parenthesis and commas) whereas the PLC only sends the exact 32 bits for each float.

How would we go about appending parentheses and comma’s between the floats in the PLC?

Converting the floats to a string would bring with it the problem that the sequence of numbers in a string does not have the same bits as the floats, so the output on the UR side would be scrambled. We suspect therefore that we to send, in order:

“(” “float” “,” “float” “,” “float” “)”

Based on the fact that ascii is mentioned explictly in the command, this would probably mean sending:

“40” “32bitFloat” “44” “32bitFloat” “44” “32bitFloat” “41”

What would be the best way to go about that, given that the PLC does not allow arrays of mixed types (and does not seem to support a list-type structure that does and can be fed into the TSEND_C block’s DATA parameter.)

@4lloyd @Mathijs

We ran into a similar problem sending integers between the two, which we worked around by using socket_read_byte_list() on the UR, and only taking the 2nd byte received (this, of course, will run into problems when sending integers larger than one byte, but for now, we can work around this limitation).

Nevermind, the UR documentation just sucks. Just send an actual string (number,number,number) and it works.

“40” “32bitFloat” “44” “32bitFloat” “44” “32bitFloat” “41”

This seems indeed the format you need to send. But, as you already mentioned, it’s not possible in the PLC to have a mixed array.

A solution in this case would be using an array which only contains chars. The PLC will sends these characters literally, so wat you see is what is being send.

This can be created the following way:

  1. Create an array which is long enough to contain the values as numbers and the boilerplate (parentheses, commas, decimal point, etc).
  2. Fill the right positions with the boilerplate values.
  3. Use the function VAL_STRG (Instructions -> Extended instructions -> String + Char) to convert the real to string. Make sure that the string variable is limited, so it will fit between the parentheses and commas you added in step 2. For example, data type: string[10] wil only allow 10 characters.
  4. Use the function Strg_TO_Chars (Instructions -> Extended instructions -> String + Char) to convert the string to separate chars. The function can directly fill the array you created in step 1.

If you only want to send integers you can use the function “socket_read_binary_integer” on the UR.

In the PLC you send an array of DINT which matches the number of integers you configured in the UR.