Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

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.

...

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.