MBM_FC02_DIRd() - Modbus-M

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

Prototype

CPU_INT16U  MBM_FC02_DIRd (MODBUS_CH  *pch, 
                           CPU_INT08U  slave_addr,
                 CPU_INT16U  start_addr,
                 CPU_INT08U *p_di_tbl,
                 CPU_INT16U  nbr_di);

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 discrete input number. This can be from 0 to 65535.

p_di_tbl

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

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

nbr_di

specifies the number of discrete inputs 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.