Getting started
Installation
From packages
On Linux, a libmodbus package is provided for the following distributions:
- Archlinux,
pacman -S libmodbus
- Fedora,
rpm -i libmodbus
- Debian,
apt-get install libmodbus
- Ubuntu
- Buildroot
- Fink
On MacOS, the package is available via Homebrew brew install libmodbus
.
Compilation from official releases
You can compile libmodbus
from tarball releases by downloading the latest stable release.
The official tarball to use is the asset with a icon.
A C toolchain should be installed in your environment:
For Visual Studio, set your platform to x64 and make sure your set these settings in the project property pages:
- General / Project Defaults / Configuration Type, Dynamic Library (.dll)
- Linker / Input / Additional Dependencies, ws2_32.lib
Changelog
All version changes are described at GitHub releases.
Code Sample
#include <stdio.h>
#include <modbus.h>
int main(void) {
modbus_t *mb;
uint16_t tab_reg[32];
mb = modbus_new_tcp("127.0.0.1", 1502);
modbus_connect(mb);
/* Read 5 registers from the address 0 */
modbus_read_registers(mb, 0, 5, tab_reg);
modbus_close(mb);
modbus_free(mb);
}
To compile this snippet, you can pass the header and library parameters to your
C compiler (gcc
, llvm
, ...) with pkg-config --cflags --libs libmodbus
:
Documentation
Starting from libmodbus v3.1.8, the documentation is built by Material for mkdocs.
The new documentation is unified for all releases, changes and additions to each version are indicated. The documentation is updated at each release.
If you need to read the old documentation, the format of the old URL is https://libmodbus.org/olddocs/v3.1.7/libmodbus where v3.1.7
can be replaced by the version you're looking for.