Function List


The functions used in this sample and the frequently used functions are shown below.

Libmodbus has other functions besides these functions, but we have not confirmed the operation.

Please refer to the libmodbus official Website for the functions not listed in this reference.

 

Communication Settings

modbus_new_tcp

Specifies the IP address and port of the slave device to communicate with, and initializes it as Modbus/TCP.

modbus_new_rtu

Specifies the COM port to connect to the slave device to communicate with, sets the baudrate, parity, etc., and initializes it as Modbus/RTU.

modbus_set_slave

Sets the slave ID.

modbus_get_slave

Retrieves the slave ID.

modbus_set_byte_timeout

Sets the timeout period between bytes in Modbus communication.

modbus_get_byte_timeout

Retrieves the timeout period between bytes in Modbus communication.

modbus_set_response_timeout

Sets the response timeout period in Modbus communication.

modbus_get_response_timeout

Retrieves the response timeout period in Modbus communication.

Communication Processing

modbus_connect

Connects to a Modbus slave device.

modbus_close

Disconnects from the Modbus slave device.

modbus_free

Releases the libmodbus structure.

modbus_flush

Flushes unsent data. The flushed data will be discarded.

Function Code

modbus_read_bits

Uses the function code Read Coils (code 01) to acquire multiple bits information of the Coil area.

modbus_read_input_bits

Uses the function code Read Discrete Inputs (code 02) to acquire multiple bits information of the Input Status area.

modbus_read_registers

Uses the function code Read Holding Registers (code 03) to acquire multiple registers information of the holding register area.

modbus_read_input_registers

Uses the function code Read Input Registers (code 04) to acquire multiple registers information of the input register area.

modbus_write_bit

Uses the function code Write Coil (code 05) to write 1 bit to the Coil area.

modbus_write_register

Uses the function code Write Register (code 06) to write 1 register to the holding register area.

modbus_write_bits

Uses the function code Write Multiple Coils (code 15) to write multiple bits to the Coil area.

modbus_write_registers

Uses the function code Write Multiple Registers (code 16) to write multiple registers to the holding register area.

Data Conversion

modbus_strerror

Retrieves the error message.

modbus_set_bits_from_byte

Retrieves bit information from byte information.

modbus_set_bits_from_bytes

Retrieves bit information from multiple byte information.

modbus_get_byte_from_bits

Converts bit information to byte information.

modbus_set_float_abcd

Converts the specified float value to 4-byte data. The byte order is in ABCD order.

modbus_get_float_abcd

Converts the specified 4-byte data to a float value. The byte order is in ABCD order.

modbus_set_float_badc

Converts the specified float value to 4-byte data. The byte order is in BADC order.

modbus_get_float_badc

Converts the specified 4-byte data to a float value. The byte order is in BADC order.

modbus_set_float_cdab

Converts the specified float value to 4-byte data. The byte order is in CDAB order.

modbus_get_float_cdab

Converts the specified 4-byte data to a float value. The byte order is in CDAB order.

modbus_set_float_dcba

Converts the specified float value to 4-byte data. The byte order is in DCBA order.

modbus_get_float_dcba

Converts the specified 4-byte data to a float value. The byte order is in DCBA order.