Skip to content

Rtop 55 plugin modbus mstr#30

Merged
thiagoralves merged 75 commits into
developmentfrom
RTOP-55-Plugin-Modbus-Mstr
Dec 5, 2025
Merged

Rtop 55 plugin modbus mstr#30
thiagoralves merged 75 commits into
developmentfrom
RTOP-55-Plugin-Modbus-Mstr

Conversation

@marconetsf

@marconetsf marconetsf commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

This Pull Request introduces the following features:

  • Modbus Master plugin designed to synchronize runtime data with external Modbus slaves
  • Support layer for native plugins, providing the foundation for future extensibility
  • Test coverage for both Modbus Master and Modbus Slave implementations
  • Example native plugin to demonstrate usage and integration patterns
  • Plugin configuration reference document to help the front-end team understand and contextualize the plugin settings

How to manually test the Modbus Master plugin?

  • First, create a program in the editor that generates the location vars to be synchronized. (This ensures they are allocated and addressed in memory, allowing them to be accessed without issues.)
  • Next, generate the JSON configuration file containing the external device description — IP, port, and the I/O points that map Modbus registers to the correct memory indices.
  • Enable the plugin in the plugins.conf file.
  • Start the runtime.

marconetsf and others added 30 commits October 16, 2025 14:42
* [WIP] implementing abstract and modbus config model

* improving plugin config decoder files disposition

* Now imports and submodules are test friendly

* simplifyin logi

* adjusting abstract from_json_file method

* applying foward reference in ModbusIoPointConfig

* MasterConfig Class now handles more slaves

* adjusting __ini__ from shared module
* [WIP] implementing abstract and modbus config model

* improving plugin config decoder files disposition

* Now imports and submodules are test friendly

* simplifyin logi

* adjusting abstract from_json_file method

* applying foward reference in ModbusIoPointConfig

* MasterConfig Class now handles more slaves

* adjusting __ini__ from shared module

* adding init function and simple tests on direct file call

* Update core/src/drivers/plugins/python/modbus_master/modbus_master_plugin.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* renaming function and changing constructor param

* avoiding wrong config parsing

* fix venv is now installing requirements only once

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* adding iec conversion class and function

* adjusting model class to handle multiple devices

* Now manage_plugin_venvs.sh only install and check venvs of listed and enabled plugins

* updating plugins.conf with modbus_master plugin

* returning pyEval implementation to give python permission

* adding script slave modbus 4test

* moving IEC dataclass to shared folder

* improving mutex taking and releasing logic

* adding proper convertion from hex string to int

* updating modbus master plugin config file

* avoiding manipulate python GIL when no plugins

* avoiding python GIL manipulation when no plugins

* adjusting wrong buffer association

* retry connection

* forcing requirements commit

* adjusting to initialize plugins only after socket connection

* adjusting modbus cycle time interaction

* adjusting default config modbus master

* updating run-image.sh

* updating run-imag-dev.sh

* fixing comments language

* enabling runtime processing windows editor generated files

* Update core/src/drivers/plugins/python/shared/plugin_config_decode/modbus_master_config_model.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* adjusting comments to default language

* adjusting slave script test to default language

* Update core/src/drivers/plugins/python/modbus_master/modbus_master_plugin.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
lucasbutzke and others added 2 commits November 17, 2025 10:17
* adding iec conversion class and function

* adjusting model class to handle multiple devices

* Now manage_plugin_venvs.sh only install and check venvs of listed and enabled plugins

* updating plugins.conf with modbus_master plugin

* returning pyEval implementation to give python permission

* adding script slave modbus 4test

* moving IEC dataclass to shared folder

* improving mutex taking and releasing logic

* adding proper convertion from hex string to int

* updating modbus master plugin config file

* avoiding manipulate python GIL when no plugins

* avoiding python GIL manipulation when no plugins

* adjusting wrong buffer association

* retry connection

* forcing requirements commit

* [RTOP-84] Fix tests and init master unit tests

* [RTOP-85] Pytest conf and read/write integration

* [RTOP-84] Pytest conftest and mock

* [RTOP-84] IOs config test and renaming files files

* [RTOP-84] Modbus config tests

* [RTOP-84] Mock server for clients tests

* [RTOP-84] conftest and modbus slave test

* [RTOP-84] Moving test script

* [RTOP-84] Test modbus master plugin

* [RTOP-84] Fix tests assertions

* [RTOP-84] Fix read and write on mock slave device

* [RTOP-84] Modbus slave SBA moxk fix

* Fix merge error on modbus master plugin

* [RTOP-60] Script for Linux and Docker image running tests

* [RTOP-60] Modbus slave tests and setup config

* [RTOP-60] Fix conftest for input read

* [RTOP-60] Fix datablock read

* Remove invalid chary

* [RTOP-60] Removing comments

---------

Co-authored-by: Marcone Tenorio <marconetsf@gmail.com>
@marconetsf marconetsf requested a review from Copilot November 18, 2025 11:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This Pull Request introduces comprehensive support for Modbus Master functionality alongside foundational improvements for native plugins. The core changes enable OpenPLC Runtime to synchronize data with external Modbus slaves through a configurable, multi-device plugin architecture.

Key changes:

  • Modbus Master plugin with multi-device support, IEC address mapping, and automatic reconnection
  • Native plugin infrastructure with shared library loading and lifecycle management
  • Extensive test coverage for Modbus Slave and Master implementations
  • Configuration documentation to guide front-end integration

Reviewed Changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
webserver/plcapp_management.py Cross-platform path normalization for ZIP extraction
start_openplc.sh Runtime venv setup and plugin filtering based on enabled status
scripts/setup-tests-env.sh Extended test execution to include driver plugin tests
scripts/run-image.sh, scripts/run-image-dev.sh Updated Docker volume mounts for plugin configuration
scripts/run-drivers-tests.sh New script for isolated driver plugin testing
pytest.ini Added commented coverage configuration
plugins.conf Updated with new plugin entries (commented out by default)
core/src/plc_app/plc_main.c Moved plugin initialization to occur after PLC state is RUNNING
core/src/drivers/plugins/python/shared/plugin_config_decode/* Configuration models and validation for plugin configs
core/src/drivers/plugins/python/modbus_slave/* Test suites for Modbus Slave implementation
core/src/drivers/plugins/python/modbus_master/* Complete Modbus Master plugin with tests and documentation
core/src/drivers/plugins/native/examples/* Example native plugin with loader and build system
core/src/drivers/plugin_driver.h, plugin_driver.c Native plugin support with dlopen/dlsym integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/drivers/plugins/python/modbus_master/modbus_master_plugin.py Outdated
Comment thread core/src/drivers/plugins/python/shared/__init__.py Outdated
marconetsf and others added 3 commits November 18, 2025 13:56
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ugin.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@marconetsf marconetsf marked this pull request as ready for review November 18, 2025 13:00
marconetsf and others added 19 commits November 19, 2025 08:48
- Introduced `modbus_master_types.py` with data classes for Modbus connection configuration, I/O point representation, device configuration, and buffer access details.
- Created `modbus_master_utils.py` containing utility functions for GCD calculation, batch read/write request generation, IEC size handling, and conversion between Modbus registers and IEC values.
- Updated `modbus_master_config_model.py` to integrate cycle time configuration into I/O points and validate cycle times during device configuration.
- Implement automatic copying of default config if plugins.conf is missing
- Add logging for plugin state during configuration updates
- Skip disabled plugins during initialization and startup
- Remove outdated Modbus Master configuration documentation
- Update plugins.conf and plugins_default.conf for consistency
This commit adds functionality to fill NULL pointers in image tables with
temporary backing buffers after glueVars() runs, and clear them when the
PLC program is unloaded.

Problem:
Plugins like Modbus Master may be configured to access addresses that are
not used by the PLC program. When glueVars() maps located variables, only
the addresses actually used in the program are mapped, leaving other
addresses as NULL pointers. This causes plugins to fail when trying to
read/write these NULL pointers.

Solution:
- Add static backing arrays for each data type in image_tables.c
- Add image_tables_fill_null_pointers() to fill NULL entries with
  temporary buffers after glueVars() runs
- Add image_tables_clear_null_pointers() to reset temporary pointers
  back to NULL when the program is unloaded
- Use address range checking to identify temporary pointers vs
  glueVars-mapped pointers
- Integrate with PLC lifecycle: fill after ext_glueVars() in
  plc_cycle_thread(), clear before plugin_manager_destroy() in
  unload_plc_program()
- Use buffer_mutex for thread safety during fill/clear operations

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
Per feedback, simplified the clear function to reset ALL pointers in
image tables to NULL, rather than only clearing pointers that point
to temporary buffers.

This simplification is valid because all pointers will be remapped
when a new program is loaded via glueVars(). This removes the need
for address range checking macros, significantly simplifying the
architecture.

Changes:
- Removed 13 IS_IN_TEMP_* address range checking macros
- Simplified image_tables_clear_null_pointers() to unconditionally
  set all pointers to NULL
- Updated header documentation to reflect simplified behavior

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
…ter-management

Add NULL pointer management for image tables
- Introduced SafeLoggingAccess class to provide safe logging operations for OpenPLC Python plugins.
- Implemented validation for logging function pointers to ensure they are available before logging.
- Added methods for logging messages at different levels (info, debug, warn, error) with exception handling.
- Centralized exception handling for logging operations to improve error reporting.

feat(buffer): Refactor SafeBufferAccess with modular architecture

- Refactored SafeBufferAccess class to maintain API compatibility while adopting a modular component architecture.
- Centralized buffer type definitions, validation logic, mutex management, and buffer access.
- Introduced batch processing capabilities for read and write operations.
- Separated debug utilities and configuration handling for improved maintainability.
- Change read_coils, read_discrete_inputs, read_holding_registers, and
  read_input_registers to use count=count keyword argument (pymodbus 3.x API)
- Remove unused imports
- Add pylint disable comments for necessary exceptions
- Fix unnecessary elif after continue
- Remove inner traceback import in cleanup function
- Break long lines to comply with 100 character limit
- Configure ruff and black to be compatible (pyproject.toml)

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
…bus-api

Fix pymodbus 3.x API compatibility and pylint issues in Modbus Master plugin
@thiagoralves thiagoralves merged commit fa964cd into development Dec 5, 2025
1 check passed
@thiagoralves thiagoralves deleted the RTOP-55-Plugin-Modbus-Mstr branch December 5, 2025 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants