How stephane/libmodbus works
Main Components
a. Libmodbus Core Library:
• This is the heart of the project, containing generic Modbus functionality found in files such as src/modbus.c and src/modbus.h.
b. Protocol-Specific Modules:
• RTU Module: Found in files like src/modbus-rtu.c and src/modbus-rtu.h, handling serial port communication.
• TCP Module: Found in files like src/modbus-tcp.c and src/modbus-tcp.h, handling Ethernet-based communication.
• Win32 Specific Code: Located in src/win32, which provides build and configuration specifics for Windows environments.
c. Testing Suite:
• Tests directory contains various test applications (e.g., unit-test-client.c and unit-test-server.c) to verify both TCP and RTU interactions.
d. Documentation and Build Infrastructure:
• Build scripts and configuration files (configure.ac, autogen.sh, Makefile.am) that facilitate cross-platform compiling.
e. External Integration Points:
• The library exposes a pkg-config file (libmodbus.pc.in) helping users integrate it into their projects.
• It interacts with external systems through Modbus protocol implementations.
Relationships and Interactions
• The core API acts as an abstraction layer that both protocol-specific modules (RTU/TCP) implement upper-level functions.
• Client applications interact with the libmodbus API to send/receive messages by using either the RTU or TCP module depending on the connection.
• The test suite simulates modbus server/client interactions and verifies proper functioning of the underlying API.
• The build and configuration modules ensure the library can be properly compiled across various platforms (Linux, Mac OS X, Windows, RTOS like Embox).
Architectural Patterns and Design Principles
• Separation of concerns: The library clearly separates protocol-specific functionality from core modbus handling.
• Modularity: Both RTU and TCP implementations are encapsulated in their own source files, and the cross-platform support (e.g., win32 directory) is isolated.
• Testability: A dedicated tests directory demonstrates unit tests and integration tests, echoing the importance of continuous testing.
• Portability/Cross-Platform: Use of autotools and specific build guides (Windows, OS X, Embox) indicates a design aimed at portability.
Relevant Technologies
• C Language for core implementation.
• Autotools (automake, autoconf, libtool) for build system.
• Testing scripts and unit tests for validation.
• MkDocs (with the mkdocs.yml file) for serving up local documentation.
• External dependencies like pkg-config for integration.