How to send strings using Modbus

Is there a simple way to send a string to a PLC using Modbus, using URScript?

Here is what doesn’t work:
modbus_add_signal(PLC_IP_Address, 255, 20, 3, “PLC_PartNumber”, True)
modbus_set_signal_update_frequency(“PLC_PartNumber”, 0)
modbus_set_runstate_dependent_choice(“PLC_PartNumber”, 0)
modbus_set_output_register(“PLC_PartNumber”, “test”)

That gives me an error because it wants a word-length unsigned integer instead of a string. I guess I would need to do something like this:

modbus_add_signal(PLC_IP_Address, 255, 20, 3, “PLC_PartNumber0”, True)
modbus_set_signal_update_frequency(“PLC_PartNumber0”, 0)
modbus_set_runstate_dependent_choice(“PLC_PartNumber0”, 0)

modbus_add_signal(PLC_IP_Address, 255, 21, 3, “PLC_PartNumber1”, True)
modbus_set_signal_update_frequency(“PLC_PartNumber1”, 0)
modbus_set_runstate_dependent_choice(“PLC_PartNumber1”, 0)

word0 = < somehow convert the letters “te” into the correct ASCII encoded word-length integer >
word1 = < somehow convert the letters “st” into the correct ASCII encoded word-length integer >
modbus_set_output_register(“PLC_PartNumber0”, word0)
modbus_set_output_register(“PLC_PartNumber1”, word1)

This seems rather complex - I would think there’d be an existing function for this sort of thing. If not, then at least tell me how to convert a string into an encoded word-length integer so I can piece it together.

Hi there, did you find a solution to your problem? I´d like to hear about it

As far as I can tell, Modbus doesn’t work with strings on the UR. The robot only seems to want its Modbus registers to use 16-bit unsigned integers. To send strings, I had to use TCP socket communication instead.

I never did send any strings, but I did send floating point decimals. What I had to do was convert the floating point decimal to an integer by multiplying by 1000, then send it as an unsigned 16-bit integer, then on the other end divide by 1000 to get it back to a float. I also had to send a separate bit for the sign. 1 = positive, 0 = negative. Then if the bit was a 1, I left the number positive, and if the bit was a 0, I multiplied by -1.

You could conceivably do something similar for strings… it’s just a question of how much complexity you want to introduce.

Long story short, I wouldn’t use Modbus on the UR if I had a choice. I’d use TCP socket communication.