From bf271f4286bda615c07694f42b326418a4d6f40b Mon Sep 17 00:00:00 2001 From: aleks Date: Mon, 18 Dec 2023 12:13:20 +0100 Subject: [PATCH] modbus master tcp port: fix to close sockets correctly, minor additions for the PR https://github.com/espressif/esp-modbus/pull/44 --- freemodbus/tcp_master/port/port_tcp_master.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/freemodbus/tcp_master/port/port_tcp_master.c b/freemodbus/tcp_master/port/port_tcp_master.c index 7e2d2f7..665d039 100644 --- a/freemodbus/tcp_master/port/port_tcp_master.c +++ b/freemodbus/tcp_master/port/port_tcp_master.c @@ -236,7 +236,6 @@ static BOOL xMBTCPPortMasterCloseConnection(MbSlaveInfo_t *pxInfo) static void xMBTCPPortMasterShutdown(void) { xSemaphoreGive(xShutdownSema); - xMbPortConfig.xMbTcpTaskHandle = NULL; for (USHORT ucCnt = 0; ucCnt < MB_TCP_PORT_MAX_CONN; ucCnt++) { MbSlaveInfo_t* pxInfo = xMbPortConfig.pxMbSlaveInfo[ucCnt]; @@ -251,6 +250,7 @@ static void xMBTCPPortMasterShutdown(void) } free(xMbPortConfig.pxMbSlaveInfo); vTaskDelete(NULL); + xMbPortConfig.xMbTcpTaskHandle = NULL; } void vMBTCPPortMasterSetNetOpt(void *pvNetIf, eMBPortIpVer xIpVersion, eMBPortProto xProto) @@ -754,7 +754,8 @@ static void vMBTCPPortMasterTask(void *pvParameters) break; } putchar(ucDot); - vTaskDelay(pdMS_TO_TICKS(100)); /* if we don't yield we run the risk of hogging CPU */ + // if we don't yield we run the risk of hogging CPU + vTaskDelay(pdMS_TO_TICKS(MB_TCP_CONNECTION_TIMEOUT_MS)); xErr = xMBTCPPortMasterConnect(pxInfo); switch(xErr) {