Rtop 55 plugin modbus mstr#30
Merged
Merged
Conversation
* [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>
…omy-Logic/openplc-runtime into RTOP-55-Plugin-Modbus-Mstr
* 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>
Contributor
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ugin.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…imize polling logic
- 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
…rdless of enabled status
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request introduces the following features:
How to manually test the Modbus Master plugin?
plugins.conffile.