Reading Response for Modbus message

Hi,

I am trying to integrate Modbus Master example in my code to send a Modbus message.

How do we read the response for the message that we send through MCmd?

Thanks and Regards,
Kenneth

There is acknowledging in modbus. You write to a register and that’s it. If you tried to write to a register that does not exist, you would see the error response in the status of the function block.

Thanks. For commands like reading a software version of the controller for example, do we read back the response for the version in the same register address as we sent the command?

modbus itself does not define any commands. You call functions with a specific register. This registers can be coils (bools) or registers (2 byte integer).

Ok, assuming I use the function read holding register and use it to read a software version from a device. I write the command id (to read software version) in a data structure and provide its address as the start address for data, do I read back the response to this command in the same data structure?

Sorry, now I see what you are trying to do. You want to call function code 23 where you call a read/write in one step with MCmd. In this case the response data is written into the address that you provide under the “data” input. So the same data is used for the information you send and for the information you receive.

The Modbus frame in the case of Modbus functions 8, 20, 21, 22, 23 and 24 comprises the device address, the Modbus function, the data area with the specified length and the checksum. Remember that the data is stored in the data area according to its mode (RTU, ASCII). The data contained in the response from the slave is then written over the data that was originally sent in the specified data area. The user is again responsible for ensuring that the data area is long enough.

How about Modbus functions 3 and 6? Do they behave the same way? (ie. response data is written over the data originally sent)

If you just read there is no data that is overwritten. The function code is entered with mfc and the address if controlled with the input offset. If you write with function code 6 there is no response data. This is only used for functions 8, 20, 21, 22, 23 and 24.

I came across an example from another webpage for modbus function 3, it seems there is a response. Is the B&R module functioning in the same way?

Mobdbus function code 3 - read multiple holding registers

in the case of function code 0x03, we would fill mfc with 3 and in the data section, we will put the command code defined by the device? Would this data be overwritten by the response?

From how I read the help I would say no but I am not 100% sure