Modbus Master¶
API Reference¶
Header File¶
Functions¶
-
int
mb_config(speed_t baud, const char *com_para)¶ Configure MODBUS Parameters
- Return
For return value see mb_err_e
- Parameters
baud: [in] Baudrate value as in termios.h e.g. B9600com_para: [in] Communication parameter data bits, partiy and stopbit in ascii format e.g. “8N1”, “8E2” Data bits: 8, 7, 6, 5 (not supported on all platforms) Parity: N - None, E - Even, O - Odd Parity Stop Bits: 1 or 2
-
unsigned short
mb_crc(unsigned char *msg, int len)¶ Calculate MODBUS CRC
- Return
CRC value
- Parameters
msg: [in] Input bufferlen: [in] Length of data in buffer
-
unsigned char
mb_lrc(unsigned char *msg, int len)¶ Calculate MODBUS LRC
- Return
LRC value
- Parameters
msg: [in] Input bufferlen: [in] Length of data in buffer
-
char *
mb_strerror(uint8_t errnum)¶ MODBUS exception to string
- Return
error description as string
- Parameters
errnum: [in] Exception code
Unions¶
-
union
mb_op¶ - #include <modbus.h>
Modbus operation
Structures¶
-
struct
_mb_read¶ Read operation structure
-
struct
_mb_write¶ Write operation structure
-
struct
modbus_t¶ MODBUS request structure
Public Members
-
uint8_t
slaveid¶ Slave ID
-
uint8_t
function¶ Function code
-
uint8_t *
resp_buf¶ Buffer pointer to store MODBUS response. In MODBUS ASCII mode, data will be stored after conversion from ASCII to hex
-
uint16_t
resp_buflen¶ Length of response buffer, On return this value will be updated with actual number of bytes stored in response buffer
-
uint8_t
resp_timeout¶ MODBUS response timeout in milliseconds
-
int
reserved¶ Reserved Unused
-
uint8_t
Type Definitions¶
Enumerations¶
-
enum
mb_err_e¶ Modbus Error codes
Values:
-
enumerator
MB_OK¶ No error.
-
enumerator
MB_ERR_INVALID_ARG= -1¶ Invalid argument
-
enumerator
MB_ERR_NOTSUP= 2¶ Mode or Function code not supported
-
enumerator
MB_ERR_TIMEOUT= -3¶ Modbus request timed out
-
enumerator
MB_ERR_INVALID_DATA= -4¶ Invalid response received from slave
-
enumerator
MB_ERR_CRC_FAIL= -5¶ Checksum failed, CRC (for RTU) or LRC (for ASCII)
-
enumerator
MB_ERR_INIT_FAIL= -6¶ Fail to initialize port or Port not initialized
-
enumerator
MB_ERR_CONF_FAIL= -7¶ Fail to configure port
-
enumerator
-
enum
_mb_func¶ MODBUS function code
Values:
-
enumerator
MB_FUNC_INVAL= 0¶ Invalid function code
-
enumerator
MB_FUNC_RD_COIL¶ Read coil
-
enumerator
MB_FUNC_RD_DISC_INPUT¶ Read discrete input
-
enumerator
MB_FUNC_RD_HOLDING¶ Read holding register
-
enumerator
MB_FUNC_RD_INPUT¶ Read input register
-
enumerator
MB_FUNC_WR_COIL¶ Write coil
-
enumerator
MB_FUNC_WR_REG¶ Write single holding register
-
enumerator
MB_FUNC_RD_EXP¶ Read exception status
-
enumerator
MB_FUNC_DIAG¶ Diagnostic
-
enumerator
MB_FUNC_COMM_EVT_COUNT= 11¶ Get COM event counter
-
enumerator
MB_FUNC_COMM_EVT_LOG¶ Get COM event log
-
enumerator
MB_FUNC_WR_MUL_COIL= 15¶ Write multiple coils
-
enumerator
MB_FUNC_WR_MUL_REG¶ Write multiple holding register
-
enumerator
MB_FUNC_REP_SERV_ID¶ Report slave ID
-
enumerator
MB_FUNC_RD_FILE_REC= 20¶ Read file record
-
enumerator
MB_FUNC_WR_FILE_REC¶ Write file record
-
enumerator
MB_FUNC_MASK_WR_REG¶ Mask write register
-
enumerator
MB_FUNC_RDWR_MUL_REG¶ Read/Write multiple register
-
enumerator
MB_FUNC_RD_FIFO_Q¶ Read FIFO Queue
-
enumerator
