MBM_FC01_CoilRd() - Modbus-M

MBM_FC01_CoilRd() - Modbus-M

This function is called from YOUR application code to read coils from a Modbus slave.

Prototype

CPU_INT16U MBM_FC01_CoilRd (MODBUS_CH *pch, CPU_INT08U slave_addr, CPU_INT16U start_addr, CPU_INT08U *p_coil_tbl, CPU_INT16U nbr_coils);

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_addr

specifies the slave ‘node address’ that you desire to read the coil information 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 addres of the coil number. This can be from 0 to 65535.

pcoil_tbl

is a pointer to an array of 8 bit values that will receive the value of all the coils you are reading. The size of the array needs to be at least (nbr_coils - 1) / 8 + 1. The format of the table is as follows:

MSB LSB B7 B6 B5 B4 B3 B2 B1 B0 ------------------------------------- p_coil_tbl[0] #8 #7 #1 p_coil_tbl[1] #16 #15 #9 : :

nbr_coils

specifies the number of coils 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

None

Called By

Your Modbus master application.