modbus库功能码和函数对应关系

/* Function codes */
#define _FC_READ_COILS                0x01            
#define _FC_READ_DISCRETE_INPUTS      0x02
#define _FC_READ_HOLDING_REGISTERS    0x03
#define _FC_READ_INPUT_REGISTERS      0x04
#define _FC_WRITE_SINGLE_COIL         0x05
#define _FC_WRITE_SINGLE_REGISTER     0x06
#define _FC_READ_EXCEPTION_STATUS     0x07
#define _FC_WRITE_MULTIPLE_COILS      0x0F
#define _FC_WRITE_MULTIPLE_REGISTERS  0x10
#define _FC_REPORT_SLAVE_ID           0x11
#define _FC_WRITE_AND_READ_REGISTERS  0x17

0x01:读取线圈状态取得一组逻辑线圈的当前状态(ON/OFF)  
/* Reads the boolean status of bits and sets the array elements
   in the destination to TRUE or FALSE (single bits). */
int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)

0x02:
读取输入状态 取得一组开关输入的当前状态(ON/OFF)  
/* Same as modbus_read_bits but reads the remote device input table */
int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest)

0x03:读取保持寄存器 在一个或多个保持寄存器中取得当前的二进制值 
/* Reads the holding registers of remote device and put the data into an
   array */
int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest)

0x04:读取输入寄存器 在一个或多个输入寄存器中取得当前的二进制值 
/* Reads the input registers of remote device and put the data into an array */
int modbus_read_input_registers(modbus_t *ctx, int addr, int nb,
                                uint16_t *dest)

0x05:强置单线圈 强置一个逻辑线圈的通断状态
/* Turns ON or OFF a single bit of the remote device */
int modbus_write_bit(modbus_t *ctx, int addr, int status)

0x06:预置单寄存器 把具体二进值装入一个保持寄存器
/* Writes a value in one register of the remote device */
int modbus_write_register(modbus_t *ctx, int addr, int value)
 0x07:读取异常状态 取得8个内部线圈的通断状态,这8个线圈的地址由控制器决定,用户逻辑可以将这些线圈定义,以说明从机状态,短报文适宜于迅速读取状态  

0x0F:强置多线圈 强置一串连续逻辑线圈的通断
/* Write the bits of the array in the remote device */
int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *src)

0x10:控询(只用于484) 可使主机与一台正在执行长程序任务从机通信,探询该从机是否已完成其操作任务,仅在含有功能码9的报文发送后,本功能码才发送
/* Write the values from the array to the registers of the remote device */
int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *src)

0x17:报告从机标识 可使主机判断编址从机的类型及该从机运行指示灯的状态
 
  /* 
    
  Write 
    
  multiple 
    
  registers 
    
  from 
    
  src 
    
  array 
    
  to 
    
  remote 
    
  device 
    
  and 
    
  read 
    
  multiple 
  
   registers from remote device to dest array. */
int modbus_write_and_read_registers(modbus_t *ctx,
                                    int write_addr, int write_nb, const uint16_t *src,
                                    int read_addr, int read_nb, uint16_t *dest)
 
   
  

你可能感兴趣的:(modbus库功能码和函数对应关系)