MBM_FC04_InRegRd() - Modbus-M
This function is called from YOUR application code to read 16-bit input registers registers from a Modbus slave.
Prototype
CPU_INT16U MBM_FC04_InRegRd (MODBUS_CH *pch, CPU_INT08U slave_node, CPU_INT16U start_addr, CPU_INT16U *p_reg_tbl, CPU_INT16U nbr_regs);
Arguments
pch
is a pointer to the channel (returned by MB_CfgCh()
). This pointer specifies onto which channel the Modbus master will be communicating on. Of course, ‘pch
’ must have been configured as a Master when you configured the channel.
slave_node
specifies the slave ‘node address’ that you desire to read the registers from. This can be a number between 1 and 255 but needs to match the number assigned to the slave node.
start_addr
specifies the start address of the registers. This can be from 0 to 65535. Note that the start address must be a number lower than MODBUS_CFG_FP_START_IX
(of the slave) if you intend to have floating-point registers (i.e you set MODBUS_CFG_FP_EN
to DEF_ENABLED
in mb_cfg.h
in the slave).
p_reg_tbl
is a pointer to an array of unsigned 16 bit values that will receive the value of all the registers you are reading. The size of the array needs to be at least nbr_regs
. Note that you can ‘cast’ the unsigned values to signed values. As far as the Modbus protocol is concerned, it sends and receives 16 bit values and the interpretation of what these values mean is application specific.
nbr_regs
specifies the number of registers you want to read from the slave.
Returned Value
MODBUS_ERR_NONE
if the call was successful.
MODBUS_ERR_RX
if a response was not received from the slave within the timeout specified for this channel (see MB_CfgCh()
).
MODBUS_ERR_SLAVE_ADDR
If the transmitted slave address doesn't correspond to the received slave address
MODBUS_ERR_FC
If the transmitted function code doesn't correspond to the received function code
MODBUS_ERR_BYTE_COUNT
If the expected number of bytes to receive doesn't correspond to the number of bytes received.
Notes / Warnings
MODBUS_CFG_FP_START_IX
corresponds to that of the slave.
Called By
Your Modbus master application.