modbus master tcp destroy function works not correctly

Mykyta_Markovskyi
Posts: 3
Joined: Tue Jan 09, 2024 8:42 am

modbus master tcp destroy function works not correctly

Postby Mykyta_Markovskyi » Thu Feb 22, 2024 2:14 pm

Hardware:
Board: ESP32-S3 Dev Module
Ethernet: W5500 SPI Ethernet Modul

Description:
Hello, I am trying to make solution with one Master and more then 5 Slaves, for example 20. I read thet the Modbus implementation von ESP connected to all slaves at the beginning and then starting a modbus communication. Becose of low number of sockets, it is recommendet to connect not more then 5 slaves.
My decision is to connect slave number 1 then disconnect and go to slave N2 and so own. Based on example from Espressif:

To connect i use:
______________________________________________________________________________________________________________
void mb_master_start_dm()
{
vTaskDelay(100);
mb_tcp_addr_type_t ip_addr_type;

ip_addr_type = MB_IPV4;

int ip_cnt = master_get_slave_ip_stdin(slave_ip_address_table);
if (ip_cnt) { ESP_LOGI(TAG, "Configured %d IP addresse(s).", ip_cnt); }
else
{
ESP_LOGE(TAG, "Fail to get IP address from stdin. Continue.");
// return ESP_ERR_NOT_FOUND;
}

mb_communication_info_t comm_info = { 0 };
comm_info.ip_port = MB_TCP_PORT;
comm_info.ip_addr_type = ip_addr_type;
comm_info.ip_mode = MB_MODE_TCP;
comm_info.ip_addr = (void *)slave_ip_address_table;

volatile esp_netif_t *pp_netif = NULL;
ntwrk_get_active_netif(&pp_netif);
comm_info.ip_netif_ptr = pp_netif; //(void*)get_example_netif();

ESP_ERROR_CHECK(master_init_mb_master_dm(&comm_info));
vTaskDelay(50);

}
______________________________________________________________________________________________________________
and
______________________________________________________________________________________________________________
static esp_err_t master_init_mb_master_dm(mb_communication_info_t *comm_info)
{
void *master_handler = NULL;

esp_err_t err = mbc_master_init_tcp(&master_handler);
MB_RETURN_ON_FALSE((master_handler != NULL), ESP_ERR_INVALID_STATE, TAG, "mb controller initialization fail.");
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG, "mb controller initialization fail, returns(0x%lx).", (uint32_t)err);

err = mbc_master_setup((void *)comm_info);
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG, "mb controller setup fail, returns(0x%lx).", (uint32_t)err);

err = mbc_master_set_descriptor(&device_parameters, num_device_parameters);
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG, "mb controller set descriptor fail, returns(0x%lx).", (uint32_t)err);
ESP_LOGI(TAG, "Modbus master stack initialized...");

err = mbc_master_start();
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG, "mb controller start fail, returns(0x%lx).", (uint32_t)err);
vTaskDelay(5);
return err;
}
______________________________________________________________________________________________________________

For disconnect i call:
______________________________________________________________________________________________________________
static esp_err_t master_destroy(void)
{
esp_err_t err = mbc_master_destroy();
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG, "mbc_master_destroy fail, returns(0x%lx).", (uint32_t)err);
ESP_LOGI(TAG, "Modbus master stack destroy...");
return err;
}
______________________________________________________________________________________________________________


i fixed a problem with sockets that would be not removed.

after some successful connects, communications and disconnects i am getting a core panic:

I (724264) MB_TCP_MASTER_PORT: Connecting to slaves...
-I (724264) MB_TCP_MASTER_PORT: Connected 1 slaves, start polling...
Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).

Core 0 register dump:
PC : 0x4037cb38 PS : 0x00060234 A0 : 0x80382e78 A1 : 0x3fcd4620
0x4037cb38: esp_cpu_compare_and_set at C:/Users/Mykyta/esp_n/esp-idf/components/esp_hw_support/cpu.c:406


Has someone a solution to this problem?

Victorrova
Posts: 3
Joined: Mon Jul 11, 2022 9:23 pm

Re: modbus master tcp destroy function works not correctly

Postby Victorrova » Fri Jul 12, 2024 10:48 am

Hello!
I have the same problem, have you made any progress?
thank you!

mjgciltd
Posts: 2
Joined: Tue Jul 02, 2024 4:03 pm

Re: modbus master tcp destroy function works not correctly

Postby mjgciltd » Tue Sep 24, 2024 3:55 pm

Similar problem on my end as well.

My application involves reconfiguring the Wifi and restart the the Modbus TCP Slave init() when the correct IP address is acquired.
I am trying to use mbc_slave_destroy() to stop the slave and it seems it doesn't like reconfiguring the TCP info again.

Update (25 September 2024): If this is useful to anyone, the github component for modbus highlights the changes made to the library for closing the Modbus TCP peripheral.
Link: https://github.com/espressif/esp-modbus ... a825afad0a

Who is online

Users browsing this forum: sNova78 and 83 guests