Wait for modbus signal

Hey,

We are currently developing a URcap to let the robot control and interact with an external device. Modbus is used for the communication between the robot controller and the device. when the robot sends a command to the device using an output register (modbus signal “OUTPUT1”), the device will perform its tasks and once done respond with the same register value on an input register (modbus signal “INPUT1”). In the meantime the robot should wait, however in the simulator the robot seems to skip right by the wait node even though the signals do not match.

The following code was extracted from the script file generated by the program

while(not(modbus_get_signal_status("OUTPUT1") == modbus_get_signal_status("INPUT1"))):
sync()
end

Any clues as to why this behaviour is happening?

Kind regards,
Gunther Moors

Took me a while, but i finally figured it out. the modbus server has a small response time between setting a register and being able to read this new register value. I had to include a wait period for the new output value to be set before comparing it to the response coming from our device.
So it seems the signals did in fact match for just a fraction of a second too long.
Below the revised code for those interested:

output1_old = modbus_get_signal_status("OUTPUT1")
modbus_set_output_register("OUTPUT1",65217,False)
while(output1_old == modbus_get_signal_status("OUTPUT1")):
  sync()
end

while (not(modbus_get_signal_status("OUTPUT1")==modbus_get_signal_status("INPUT1"))):
  sync()
end
1 Like