结构体 | |
struct | mb_handler |
类型定义 | |
typedef enum mb_status | mb_status_t |
typedef struct mb_handler | mb_handler_t |
typedef mb_status_t(* | frame_send_func_t) (mb_handler_t *handler, uint32_t timeout) |
typedef mb_status_t(* | frame_recv_func_t) (mb_handler_t *handler) |
typedef mb_status_t(* | adu_assemble_func_t) (mb_handler_t *handler) |
typedef mb_status_t(* | adu_disassemble_func_t) (mb_handler_t *handler) |
枚举 | |
enum | mb_parity_t { MB_PAR_NONE , MB_PAR_ODD , MB_PAR_EVEN } |
enum | mb_status { MB_SUCCESS = 0u , MB_MUTEX_ERROR , MB_INVALID_SLAVE_ADDR , MB_INVALID_PARAM , MB_RESPOND_EXCEPTION , MB_RESPOND_LENGTH_ERR , MB_RESPOND_FRAME_ERR , MB_RESPOND_TIMEOUT , MB_CANNOT_GET_HANDLER , MB_SLAVE_NO_RESPOND , MB_FRAME_SEND_ERR , MB_SERIAL_INIT_FAILED , MB_SERIAL_UNINIT_FAILED , MB_FUNCTION_CODE_NOT_SUPPORT } |
enum | mb_mode_t { MB_RTU , MB_ASCII , MB_TCP } |
函数 | |
mb_status_t | mbmaster_rtu_init (mb_handler_t **handler, uint8_t port, uint32_t baud_rate, mb_parity_t parity, uint32_t timeout) |
mb_status_t | mbmaster_rtu_uninit (mb_handler_t *req_handler) |
mb_status_t | mbmaster_read_coils (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint8_t *respond_buf, uint8_t *respond_count, uint32_t timeout) |
mb_status_t | mbmaster_read_discrete_inputs (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint8_t *respond_buf, uint8_t *respond_count, uint32_t timeout) |
mb_status_t | mbmaster_read_holding_registers (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint8_t *respond_buf, uint8_t *respond_count, uint32_t timeout) |
mb_status_t | mbmaster_read_input_registers (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint8_t *respond_buf, uint8_t *respond_count, uint32_t timeout) |
mb_status_t | mbmaster_write_single_coil (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t coil_addr, uint16_t coil_value, uint16_t *resp_addr, uint16_t *resp_value, uint8_t *exception_code, uint32_t timeout) |
mb_status_t | mbmaster_write_single_register (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t register_addr, uint16_t register_value, uint16_t *resp_addr, uint16_t *resp_value, uint8_t *exception_code, uint32_t timeout) |
mb_status_t | mbmaster_write_multiple_coils (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint8_t *outputs_buf, uint16_t *resp_addr, uint16_t *resp_quantity, uint8_t *exception_code, uint32_t timeout) |
mb_status_t | mbmaster_write_multiple_registers (mb_handler_t *req_handler, uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint8_t *outputs_buf, uint16_t *resp_addr, uint16_t *resp_quantity, uint8_t *exception_code, uint32_t timeout) |
modbus master protocol.
typedef mb_status_t(* adu_assemble_func_t) (mb_handler_t *handler) |
在文件 mbmaster.h 第 67 行定义.
typedef mb_status_t(* adu_disassemble_func_t) (mb_handler_t *handler) |
在文件 mbmaster.h 第 68 行定义.
typedef mb_status_t(* frame_recv_func_t) (mb_handler_t *handler) |
在文件 mbmaster.h 第 66 行定义.
typedef mb_status_t(* frame_send_func_t) (mb_handler_t *handler, uint32_t timeout) |
在文件 mbmaster.h 第 65 行定义.
typedef struct mb_handler mb_handler_t |
在文件 mbmaster.h 第 1 行定义.
typedef enum mb_status mb_status_t |
enum mb_mode_t |
枚举值 | |
---|---|
MB_RTU | |
MB_ASCII | |
MB_TCP |
在文件 mbmaster.h 第 55 行定义.
enum mb_parity_t |
枚举值 | |
---|---|
MB_PAR_NONE | |
MB_PAR_ODD | |
MB_PAR_EVEN |
在文件 mbmaster.h 第 30 行定义.
enum mb_status |
在文件 mbmaster.h 第 37 行定义.
mb_status_t mbmaster_read_coils | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | start_addr, | ||
uint16_t | quantity, | ||
uint8_t * | respond_buf, | ||
uint8_t * | respond_count, | ||
uint32_t | timeout | ||
) |
This function will initiate a read coils request(function code 0x01)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | start_addr | starting address |
[in] | quantity | quantity of coils |
[out] | respond_buf | data receive from remote device, length must >= (quantity / 8 + 1) bytes |
[out] | respond_count | the number of bytes of data received |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |
mb_status_t mbmaster_read_discrete_inputs | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | start_addr, | ||
uint16_t | quantity, | ||
uint8_t * | respond_buf, | ||
uint8_t * | respond_count, | ||
uint32_t | timeout | ||
) |
This function will initiate a read discrete inputs request(function code 0x02)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | start_addr | starting address |
[in] | quantity | quantity of inputs |
[out] | respond_buf | data receive from remote device, length must >= (quantity / 8 + 1) bytes |
[out] | respond_count | the number of bytes of data received |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |
mb_status_t mbmaster_read_holding_registers | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | start_addr, | ||
uint16_t | quantity, | ||
uint8_t * | respond_buf, | ||
uint8_t * | respond_count, | ||
uint32_t | timeout | ||
) |
This function will initiate a read holding registers request(function code 0x03)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | start_addr | starting address |
[in] | quantity | quantity of registers |
[out] | respond_buf | data receive from remote device, length must >= (quantity * 2) bytes |
[out] | respond_count | the number of bytes of data received |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |
mb_status_t mbmaster_read_input_registers | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | start_addr, | ||
uint16_t | quantity, | ||
uint8_t * | respond_buf, | ||
uint8_t * | respond_count, | ||
uint32_t | timeout | ||
) |
This function will initiate a read input registers request(function code 0x04)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | start_addr | starting address |
[in] | quantity | quantity of input registers |
[out] | respond_buf | data receive from remote device, length must >= (quantity * 2) bytes |
[out] | respond_count | the number of bytes of data received |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |
mb_status_t mbmaster_rtu_init | ( | mb_handler_t ** | handler, |
uint8_t | port, | ||
uint32_t | baud_rate, | ||
mb_parity_t | parity, | ||
uint32_t | timeout | ||
) |
This function will alloc a handler and initializes the port for communication
[out] | handler | returns a pointer to the assigned handler |
[in] | port | port usend to communication |
[in] | baud_rate | baud rate used by port |
[in] | parity | parity used by port |
[in] | timeout | timeout for response |
mb_status_t mbmaster_rtu_uninit | ( | mb_handler_t * | req_handler | ) |
This function will free the handler and uninitializes the port for communication
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
mb_status_t mbmaster_write_multiple_coils | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | start_addr, | ||
uint16_t | quantity, | ||
uint8_t * | outputs_buf, | ||
uint16_t * | resp_addr, | ||
uint16_t * | resp_quantity, | ||
uint8_t * | exception_code, | ||
uint32_t | timeout | ||
) |
This function will initiate a write mutiple coils request(function code 0x0F)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | start_addr | start address |
[in] | quantity | quantity of outputs |
[in] | outputs_buf | outputs value(bit array, 0 to be OFF. 1 to be ON) |
[out] | resp_addr | start address responded from remote device |
[out] | resp_quantity | quantity responded from remote device |
[out] | excepiton_code | exception code, when MB_RESPOND_EXCEPTION is returned |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |
mb_status_t mbmaster_write_multiple_registers | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | start_addr, | ||
uint16_t | quantity, | ||
uint8_t * | outputs_buf, | ||
uint16_t * | resp_addr, | ||
uint16_t * | resp_quantity, | ||
uint8_t * | exception_code, | ||
uint32_t | timeout | ||
) |
This function will initiate a write mutiple registers request(function code 0x10)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | start_addr | start address |
[in] | quantity | quantity of registers |
[in] | outputs_buf | registers value |
[out] | resp_addr | start address responded from remote device |
[out] | resp_quantity | registers quantity responded from remote device |
[out] | excepiton_code | exception code, when MB_RESPOND_EXCEPTION is returned |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |
mb_status_t mbmaster_write_single_coil | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | coil_addr, | ||
uint16_t | coil_value, | ||
uint16_t * | resp_addr, | ||
uint16_t * | resp_value, | ||
uint8_t * | exception_code, | ||
uint32_t | timeout | ||
) |
This function will initiate a write single coil request(function code 0x05)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | register_addr | coil address |
[in] | register_value | coil value, 0x0000 for off, 0xFF00 for on |
[out] | resp_addr | coil address responded from remote device |
[out] | resp_value | coil value responded from remote device |
[out] | excepiton_code | exception code, when MB_RESPOND_EXCEPTION is returned |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |
mb_status_t mbmaster_write_single_register | ( | mb_handler_t * | req_handler, |
uint8_t | slave_addr, | ||
uint16_t | register_addr, | ||
uint16_t | register_value, | ||
uint16_t * | resp_addr, | ||
uint16_t * | resp_value, | ||
uint8_t * | exception_code, | ||
uint32_t | timeout | ||
) |
This function will initiate a write single register request(function code 0x06)
[in] | req_handler | the handler pointer returned from mbmaster_rtu_init |
[in] | slave_addr | slave address of the remote device |
[in] | register_addr | register address |
[in] | register_value | regitter value |
[out] | resp_addr | register address responded from remote device |
[out] | resp_value | register value responded from remote device |
[out] | excepiton_code | exception code, when MB_RESPOND_EXCEPTION is returned |
[in] | timeout | the timeout time(ms) for sending the request, 0xFFFFFFFF means waiting for ever |