![]() |
GaIA BIOS Library
|
Modbus/TCP master function definitions. More...
#include <stdbool.h>#include <stdint.h>#include <modbus_core/modbus.h>#include <modbus_core/modbus_exceptions.h>#include <modbus_core/modbus_types.h>#include <modbus_core/modbus_rtos.h>#include <modbus_tcp/modbus_tcp.h>Data Structures | |
| struct | mb_tcp_master_ch_t |
| Structure representing a Modbus/TCP master channel. More... | |
Macros | |
| #define | MB_TRANS_EVENT_COMPLETED 0 |
| Modbus/TCP transaction successfully completed event. | |
| #define | MB_TRANS_EVENT_TIMEOUT 1 |
| Modbus/TCP transaction timeout event. | |
Typedefs | |
| typedef void(* | transaction_callback) (uint16_t trans_id, int event) |
| Transaction callback. | |
Functions | |
| mb_tcp_master_ch_t * | mb_tcp_master_open (const ip_addr_t *slave_addr, uint16_t slave_port, uint8_t trans_count, transaction_callback trans_callback) |
| Opens a master channel. | |
| int | mb_tcp_master_connect (mb_tcp_master_ch_t *ch, uint32_t timeout) |
| Opens the connection to the slave. | |
| int | mb_tcp_master_disconnect (mb_tcp_master_ch_t *ch, uint32_t timeout) |
| Closes the connection to the slave. | |
| int | mb_tcp_master_close (mb_tcp_master_ch_t *ch) |
| Closes a Modbus/TCP master channel. | |
| int | mb_tcp_master_loop (mb_tcp_master_ch_t *ch) |
| Processes pending transactions. | |
| int | mb_tcp_rd_coils (mb_tcp_master_ch_t *ch, uint8_t *buf, uint8_t unit_id, uint16_t addr, uint16_t qty, uint16_t timeout) |
| Makes a read coils request on the provided channel. | |
| int | mb_tcp_rd_discrete_inputs (mb_tcp_master_ch_t *ch, uint8_t *buf, uint8_t unit_id, uint16_t addr, uint16_t qty, uint16_t timeout) |
| Makes a read discrete inputs request on the provided channel. | |
| int | mb_tcp_rd_holding_regs (mb_tcp_master_ch_t *ch, uint16_t *buf, uint8_t unit_id, uint16_t addr, uint16_t qty, uint16_t timeout) |
| Makes a read holding registers request on the provided channel. | |
| int | mb_tcp_rd_input_regs (mb_tcp_master_ch_t *ch, uint16_t *buf, uint8_t unit_id, uint16_t addr, uint16_t qty, uint16_t timeout) |
| Makes a read input registers request on the provided channel. | |
| int | mb_tcp_wr_single_coil (mb_tcp_master_ch_t *ch, bool value, uint8_t unit_id, uint16_t addr, uint16_t timeout) |
| Makes a write single coil request on the provided channel. | |
| int | mb_tcp_wr_single_reg (mb_tcp_master_ch_t *ch, uint16_t value, uint8_t unit_id, uint16_t addr, uint16_t timeout) |
| Makes a write single register request on the provided channel. | |
| int | mb_tcp_wr_coils (mb_tcp_master_ch_t *ch, uint8_t *values, uint8_t unit_id, uint16_t addr, uint16_t qty, uint16_t timeout) |
| Makes a write multiple coils request on the provided channel. | |
| int | mb_tcp_wr_regs (mb_tcp_master_ch_t *ch, uint16_t *values, uint8_t unit_id, uint16_t addr, uint16_t qty, uint16_t timeout) |
| Makes a write multiple coils request on the provided channel. | |
Modbus/TCP master function definitions.
| typedef void(* transaction_callback) (uint16_t trans_id, int event) |
Transaction callback.
| trans_id | transaction id. |
| event | transaction event. It can be MB_TRANS_EVENT_COMPLETED or MB_TRANS_EVENT_TIMEOUT. |
| int mb_tcp_master_close | ( | mb_tcp_master_ch_t * | ch | ) |
Closes a Modbus/TCP master channel.
The connection must be closed before calling this function.
| ch | opened master channel to be closed. |
| int mb_tcp_master_connect | ( | mb_tcp_master_ch_t * | ch, |
| uint32_t | timeout ) |
Opens the connection to the slave.
| ch | opened master channel. |
| timeout | timeout for the connection to be established. |
| int mb_tcp_master_disconnect | ( | mb_tcp_master_ch_t * | ch, |
| uint32_t | timeout ) |
Closes the connection to the slave.
| ch | opened master channel. |
| timeout | timeout for the connection to be closed. |
| int mb_tcp_master_loop | ( | mb_tcp_master_ch_t * | ch | ) |
Processes pending transactions.
This function is supposed to be called in a loop and processes responses and timeouts calling the callback function provided when the master channel was opened.
| ch | opened master channel. |
| mb_tcp_master_ch_t * mb_tcp_master_open | ( | const ip_addr_t * | slave_addr, |
| uint16_t | slave_port, | ||
| uint8_t | trans_count, | ||
| transaction_callback | trans_callback ) |
Opens a master channel.
| slave_addr | IP address of the slave. |
| slave_port | slave TCP port to connect to. |
| trans_count | maximum number of concurrent transactions. |
| trans_callback | function to be invoked when a transaction ends or its timeout expires. |
| int mb_tcp_rd_coils | ( | mb_tcp_master_ch_t * | ch, |
| uint8_t * | buf, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Makes a read coils request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| buf | buffer to store the data read. It must be large enough to store the response. |
| unit_id | unit id of the slave. |
| addr | coils starting address. |
| qty | number of coils to be read. |
| timeout | transaction timeout. |
| int mb_tcp_rd_discrete_inputs | ( | mb_tcp_master_ch_t * | ch, |
| uint8_t * | buf, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Makes a read discrete inputs request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| buf | buffer to store the data read. It must be large enough to store the response. |
| unit_id | unit id of the slave. |
| addr | discrete inputs starting address. |
| qty | number of discrete inputs to be read. |
| timeout | transaction timeout. |
| int mb_tcp_rd_holding_regs | ( | mb_tcp_master_ch_t * | ch, |
| uint16_t * | buf, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Makes a read holding registers request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| buf | buffer to store the data read. It must be large enough to store the response. |
| unit_id | unit id of the slave. |
| addr | holding regiters starting address. |
| qty | number of holding registers to be read. |
| timeout | transaction timeout. |
| int mb_tcp_rd_input_regs | ( | mb_tcp_master_ch_t * | ch, |
| uint16_t * | buf, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Makes a read input registers request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| buf | buffer to store the data read. It must be large enough to store the response. |
| unit_id | unit id of the slave. |
| addr | input registers starting address. |
| qty | number of input registers to be read. |
| timeout | transaction timeout. |
| int mb_tcp_wr_coils | ( | mb_tcp_master_ch_t * | ch, |
| uint8_t * | values, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Makes a write multiple coils request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| values | value to be written. |
| unit_id | unit id of the slave. |
| addr | starting address of the coils to be written. |
| qty | number of coils to be written. |
| timeout | transaction timeout. |
| int mb_tcp_wr_regs | ( | mb_tcp_master_ch_t * | ch, |
| uint16_t * | values, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Makes a write multiple coils request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| values | value to be written. |
| unit_id | unit id of the slave. |
| addr | starting address of the registers to be written. |
| qty | number of registers to be written. |
| timeout | transaction timeout. |
| int mb_tcp_wr_single_coil | ( | mb_tcp_master_ch_t * | ch, |
| bool | value, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | timeout ) |
Makes a write single coil request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| value | value to be written. |
| unit_id | unit id of the slave. |
| addr | address of the coil to be written. |
| timeout | transaction timeout. |
| int mb_tcp_wr_single_reg | ( | mb_tcp_master_ch_t * | ch, |
| uint16_t | value, | ||
| uint8_t | unit_id, | ||
| uint16_t | addr, | ||
| uint16_t | timeout ) |
Makes a write single register request on the provided channel.
The transaction response is processed by the mb_tcp_master_loop function.
| ch | opened master channel. |
| value | value to be written. |
| unit_id | unit id of the slave. |
| addr | address of the register to be written. |
| timeout | transaction timeout. |