Skip to content

Feature/modbus serial with generic transport (EPROT-74) - #180

Open
MrS-E wants to merge 5 commits into
espressif:mainfrom
MrS-E:feature/modbus-with-generic-transport
Open

Feature/modbus serial with generic transport (EPROT-74)#180
MrS-E wants to merge 5 commits into
espressif:mainfrom
MrS-E:feature/modbus-with-generic-transport

Conversation

@MrS-E

@MrS-E MrS-E commented Jul 17, 2026

Copy link
Copy Markdown

Description

Adds an opt-in generic RTU transport factory API for ESP-Modbus serial controllers.

  • Adds mbc_slave_create_serial_with_transport() and mbc_master_create_serial_with_transport().
  • Lets applications create and supply an initialized mb_trans_base_t through a documented factory callback for MB_RTU mode.
  • Preserves existing mbc_*_create_serial() behavior by using the stock transport when no factory is supplied;

Motivation: I ran into a similar problem to issue #176 while integrating a custom serial transport, so I added a small, generic serial factory for custom RTU transports.

Related

Related issue: #176

This change provides an RTU transport-factory extension point for custom
communication and routing implementations, supporting the issue's goal of
reusing ESP-Modbus protocol/controller logic with application-provided I/O.

Testing

I tested it using my own transport implementation (I can't disclose here) that is wired to the esp-modbus component (via managed components) that is pinned to commit e74eeaa.
The wiring looks kinda like:

     #include "esp_modbus_slave.h"                                                                                                                                                                                  
     #include "transport_common.h"                                                                                                                                                                                  
     static mb_err_enum_t custom_transport_factory(                                                                                                                                                                 
         const mbc_slave_transport_factory_args_t *args,                                                                                                                                                            
         mb_trans_base_t **transport)                                                                                                                                                                               
     {                                                                                                                                                                                                              
         return custom_transport_create(args->comm_info,                                                                                                                                                            
                                        args->parent,                                                                                                                                                               
                                        args->user_ctx,                                                                                                                                                             
                                        transport);                                                                                                                                                                 
     }                                                                                                                                                                                                              
     void app_main(void)                                                                                                                                                                                            
     {                                                                                                                                                                                                              
         mb_communication_info_t comm_info = {                                                                                                                                                                      
             .mode = MB_MODE_RTU,                                                                                                                                                                                   
             .slave_addr = 1,                                                                                                                                                                                       
             .port = UART_NUM_0,                                                                                                                                                                                    
             .baudrate = 19200,                                                                                                                                                                                     
             .parity = MB_PARITY_NONE,                                                                                                                                                                              
         };                                                                                                                                                                                                         
         custom_transport_config_t transport_config = {0};                                                                                                                                                          
         void *slave = NULL;                                                                                                                                                                                        
         ESP_ERROR_CHECK(mbc_slave_create_serial_with_transport(                                                                                                                                                    
             &comm_info,                                                                                                                                                                                            
             custom_transport_factory,                                                                                                                                                                              
             &transport_config,                                                                                                                                                                                     
             &slave));                                                                                                                                                                                              
         ESP_ERROR_CHECK(mbc_slave_start(slave));                                                                                                                                                                   
     }

Additionally, I tested it shortly by using the slave example.

I did not test the master.


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@CLAassistant

CLAassistant commented Jul 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot changed the title Feature/modbus serial with generic transport Feature/modbus serial with generic transport (EPROT-74) Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants