![]() |
GaIA BIOS Library
|
Modbus serial defnitions and functions. More...
#include <stdbool.h>#include <modbus_core/modbus.h>#include <modbus_core/modbus_exceptions.h>#include <modbus_core/modbus_types.h>#include <modbus_core/modbus_rtos.h>Data Structures | |
| struct | mb_ser_adu_t |
| This structure represents a serial line modbus ADU. More... | |
| struct | timer_t |
| struct | mb_ser_channel_t |
| This structure represents the configuration of a modbus channel. More... | |
Macros | |
| #define | MB_SER_MODE_ASCII (0) |
| Modbus serial ASCII mode. | |
| #define | MB_SER_MODE_RTU (1) |
| Modbus serial RTU mode. | |
Functions | |
| void | mb_start_tx (mb_ser_channel_t *ch, mb_ser_adu_t *msg) |
| Sends the given message on the given channel. | |
| bool | mb_is_rx_msg (mb_ser_channel_t *ch) |
| Checks if there is a message in the receiving queue for the given channel. | |
| mb_ser_channel_t * | mb_serial_open (uintptr_t task_no, uint8_t mb_ser_mode, uint8_t jbus, uint8_t baud, uint8_t frame, uint8_t port, uint8_t timer, mb_data_handlers_t *handlers, uint8_t address, uint16_t timeout) |
| Opens a modbus serial channel. | |
| void | mb_serial_close (mb_ser_channel_t *ch) |
| Closes e modbus channel. | |
| void | mb_serial_set_timeout (mb_ser_channel_t *ch, uint16_t timeout) |
| Sets the timeout of the specified modbus channel. | |
| uint16_t | mb_slave_loop (mb_ser_channel_t *ch, uint32_t timeout) |
| Handles the Modbus slave protocol stack. | |
| int | mb_ser_rd_coils (mb_ser_channel_t *ch, uint8_t *buf, uint8_t addr, uint16_t start_addr, uint16_t qty, uint16_t timeout) |
| Read Coils. | |
| int | mb_ser_rd_discrete_inputs (mb_ser_channel_t *ch, uint8_t *buf, uint8_t addr, uint16_t start_addr, uint16_t qty, uint16_t timeout) |
| Read Discrete Inputs. | |
| int | mb_ser_rd_holding_regs (mb_ser_channel_t *ch, uint16_t *buf, uint8_t addr, uint16_t start_addr, uint16_t qty, uint16_t timeout) |
| Read Holding Registers. | |
| int | mb_ser_rd_input_regs (mb_ser_channel_t *ch, uint16_t *buf, uint8_t addr, uint16_t start_addr, uint16_t qty, uint16_t timeout) |
| Read Input Registers. | |
| int | mb_ser_wr_single_coil (mb_ser_channel_t *ch, bool value, uint8_t addr, uint16_t output_addr, uint16_t timeout) |
| Write Single Coil. | |
| int | mb_ser_wr_single_reg (mb_ser_channel_t *ch, uint16_t value, uint8_t addr, uint16_t output_addr, uint16_t timeout) |
| Write Single Register. | |
| int | mb_ser_wr_coils (mb_ser_channel_t *ch, uint8_t *values, uint8_t addr, uint16_t start_addr, uint16_t qty, uint16_t timeout) |
| Write Multiple Coils. | |
| int | mb_ser_wr_regs (mb_ser_channel_t *ch, uint16_t *values, uint8_t addr, uint16_t start_addr, uint16_t qty, uint16_t timeout) |
| Write Multiple Registers. | |
Modbus serial defnitions and functions.
| bool mb_is_rx_msg | ( | mb_ser_channel_t * | ch | ) |
Checks if there is a message in the receiving queue for the given channel.
| ch | pointer to the channel to check. |
true if a message was received, false otherwise. | int mb_ser_rd_coils | ( | mb_ser_channel_t * | ch, |
| uint8_t * | buf, | ||
| uint8_t | addr, | ||
| uint16_t | start_addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Read Coils.
| ch | modbus channel. |
| buf | buffer where to store read values. |
| addr | slave address. |
| start_addr | starting address of coils to read. |
| qty | number of coils to read. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were read without errors, an error code otherwise. | int mb_ser_rd_discrete_inputs | ( | mb_ser_channel_t * | ch, |
| uint8_t * | buf, | ||
| uint8_t | addr, | ||
| uint16_t | start_addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Read Discrete Inputs.
| ch | modbus channel. |
| buf | buffer where to store read values. |
| addr | slave address. |
| start_addr | starting address of discrete inputs to read. |
| qty | number of discrete inputs to read. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were read without errors, an error code otherwise. | int mb_ser_rd_holding_regs | ( | mb_ser_channel_t * | ch, |
| uint16_t * | buf, | ||
| uint8_t | addr, | ||
| uint16_t | start_addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Read Holding Registers.
| ch | modbus channel. |
| buf | buffer where to store read values. |
| addr | slave address. |
| start_addr | starting address of holding registers to read. |
| qty | number of holding registers to read. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were read without errors, an error code otherwise. | int mb_ser_rd_input_regs | ( | mb_ser_channel_t * | ch, |
| uint16_t * | buf, | ||
| uint8_t | addr, | ||
| uint16_t | start_addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Read Input Registers.
| ch | modbus channel. |
| buf | buffer where to store read values. |
| addr | slave address. |
| start_addr | starting address of input registers to read. |
| qty | number of input registers to read. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were read without errors, an error code otherwise. | int mb_ser_wr_coils | ( | mb_ser_channel_t * | ch, |
| uint8_t * | values, | ||
| uint8_t | addr, | ||
| uint16_t | start_addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Write Multiple Coils.
| ch | modbus channel. |
| values | values of the coils to set. |
| addr | slave address. |
| start_addr | starting address of the coils to write. |
| qty | number of coils to write. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were written without errors, an error code otherwise. | int mb_ser_wr_regs | ( | mb_ser_channel_t * | ch, |
| uint16_t * | values, | ||
| uint8_t | addr, | ||
| uint16_t | start_addr, | ||
| uint16_t | qty, | ||
| uint16_t | timeout ) |
Write Multiple Registers.
| ch | modbus channel. |
| values | values of the registers to set. |
| addr | slave address. |
| start_addr | starting address of the registers to write. |
| qty | number of registers to write. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were written without errors, an error code otherwise. | int mb_ser_wr_single_coil | ( | mb_ser_channel_t * | ch, |
| bool | value, | ||
| uint8_t | addr, | ||
| uint16_t | output_addr, | ||
| uint16_t | timeout ) |
Write Single Coil.
| ch | modbus channel. |
| value | value of the coil to set. |
| addr | slave address. |
| output_addr | address of the coil to write. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were written without errors, an error code otherwise. | int mb_ser_wr_single_reg | ( | mb_ser_channel_t * | ch, |
| uint16_t | value, | ||
| uint8_t | addr, | ||
| uint16_t | output_addr, | ||
| uint16_t | timeout ) |
Write Single Register.
| ch | modbus channel. |
| value | value of the register to set. |
| addr | slave address. |
| output_addr | address of the register to write. |
| timeout | maximum time to wait for the response. |
MB_RC_OK data were written without errors, an error code otherwise. | void mb_serial_close | ( | mb_ser_channel_t * | ch | ) |
Closes e modbus channel.
| ch | pointer to the modbus channel to close. |
| mb_ser_channel_t * mb_serial_open | ( | uintptr_t | task_no, |
| uint8_t | mb_ser_mode, | ||
| uint8_t | jbus, | ||
| uint8_t | baud, | ||
| uint8_t | frame, | ||
| uint8_t | port, | ||
| uint8_t | timer, | ||
| mb_data_handlers_t * | handlers, | ||
| uint8_t | address, | ||
| uint16_t | timeout ) |
Opens a modbus serial channel.
| task_no | number of the task that processes messages, 0 if signals should not be used. |
| mb_ser_mode | MB_SER_MODE_ASCII or MB_SER_MODE_RTU. |
| jbus | whether or not this channel use jbus mode. |
| baud | baudrate to use. |
| frame | configuration of the serial port. |
| port | serial port to use. |
| timer | timer to use. |
| handlers | pointer to the data handlers structure containing the function pointers to use to process modbus requests. |
| address | address of the node, 0 if this node is a master. |
| timeout | timeout to set, expressed in number of time slots of 51 microsec. |
| void mb_serial_set_timeout | ( | mb_ser_channel_t * | ch, |
| uint16_t | timeout ) |
Sets the timeout of the specified modbus channel.
| ch | modbus channel to set the timeout for. |
| timeout | timeout to set, expressed in number of time slots of 25 microsec. |
| uint16_t mb_slave_loop | ( | mb_ser_channel_t * | ch, |
| uint32_t | timeout ) |
Handles the Modbus slave protocol stack.
It should be called regularly.
| ch | modbus channel to set the timeout for. |
| timeout | if not set to 0, it's the maximum time to wait for a signal to wake-up the process calling this function. |
MSG_RECEIVED if a message was received and processed, MSG_TIMEOUT otherwise. | void mb_start_tx | ( | mb_ser_channel_t * | ch, |
| mb_ser_adu_t * | msg ) |
Sends the given message on the given channel.
| ch | pointer to the channel to use. |
| msg | message to send. |