Modbus Response buffer

When we send a message using MbmCmd with the drv_mbus library, where do we read back the response contents? Is it in the data variable that we define in the .data member that we pass in as a parameter in MbmCmd? From below example code, will the command be in CmdTable[i].data? Is there a way to read the whole response message received or only the data portion?

            MCmd.enable             = 1;
            MCmd.ident              = ident;
            MCmd.mfc                = CmdTable[i].mfc;
            MCmd.node               = CmdTable[i].node;
            MCmd.data               = CmdTable[i].data;
            MCmd.offset             = CmdTable[i].offset;
            MCmd.len                = CmdTable[i].length;
            MBMCmd(&MCmd);
            statusMCmd              = MCmd.status;

Hello,
CmdTable[i].data is the “data” you either send or receive - depending on the used function code.
CmdTable[i].length is the length of the data you send or receive

best regards
Oliver

Thanks. I have managed to send a read register and write register command to the modbus device to perform an operation. I realised the MCmd.offset field in the example is the address offset specified by the device specification, the MCmd.length field is the number of registers to read/write as defined by the Modbus protocol.

Best Regards,
Kenneth

1 Like