How MBMaster really works?

Hello,
I’m using the modbus RTU with the X20CS1030 to connect to up to 5 devices and read information from them.
I want to read the information from one device at a time so I have created a state machine where I read the information from the first one, after the reading has done I enable the reading of the second one and so on.
To do that I’m using the MBMaster FB but I cannot understand 100% its functionality:

  1. how the output “recordnum” is calculated? (In the help it’s: “Number of the entry in the data object currently being processed”)
  2. the “exectute” output should go TRUE when the FB has completed the command given (“Command executed (execute = 1)”) and I saw that the command given is automatically reset. But what I see is that the reading is not completed when the “execute” is true.

What I could state is that the reading is completed when the recordnum reaches the maximum value (all records read) and it is reset to zero. Only in that case I’m sure that the reading has been completed and I can use the values read.

So my process is:

  1. activate the reading command in the dataobject,
  2. if execute goes true, force again the reading command and go to the next step
  3. wait for the recordnum to reach the maximum value
  4. reset the command.

Do you have any other ideas on how to use this FB properly?
Probably I should use MBMCmd()…

Thank you
Andrea

Hello Andrea,

In the appendix you will find an example of Modbus RTU communication via RS485. You can use the event variable to control communication with the devices.

Regards
Stephan
Modbus.zip (81.5 KB)

Hello Stephan,
thank you for your reply but it doesn’t satisfy my requirements.
I solved the problem using the MBMCmd FB.
It’s faster and more flexible.

Thank you for your support

Hello Andrea,

A data object is specified at the MBMopen function block. Each line in the data object corresponds to a Modbus function.

The recordnum output from the MBMaster function block shows which line in the data object is currently being processed by the Modbus master.

The execute output from the MBMaster function block shows whether the addressed device has sent feedback to the Modbus function.

2 posts were split to a new topic: Modbus - Error 20263

A post was merged into an existing topic: Modbus - Error 20263