From 160bdca396214e0d0e7cffb5bc66fe367923063a Mon Sep 17 00:00:00 2001 From: Bonne Eggleston Date: Sun, 20 Oct 2024 11:23:57 -0700 Subject: [PATCH] Change modbus send_wait_time configuration to timeout only if bytes are not received. Previous functionality would allow a send in the middle of a long response, which causes a conflict on the bus New functionality times out only if bytes are not incoming. --- esphome/components/modbus/modbus.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/components/modbus/modbus.cpp b/esphome/components/modbus/modbus.cpp index c583c6a29190..731c5c735ea9 100644 --- a/esphome/components/modbus/modbus.cpp +++ b/esphome/components/modbus/modbus.cpp @@ -35,13 +35,13 @@ void Modbus::loop() { ESP_LOGV(TAG, "Clearing buffer of %d bytes - timeout", at); this->rx_buffer_.clear(); } - } - // stop blocking new send commands after sent_wait_time_ ms regardless if a response has been received since then - if (now - this->last_send_ > send_wait_time_) { - if (waiting_for_response > 0) - ESP_LOGV(TAG, "Stop waiting for response from %d", waiting_for_response); - waiting_for_response = 0; + // stop blocking new send commands after sent_wait_time_ ms after response received + if (now - this->last_send_ > send_wait_time_) { + if (waiting_for_response > 0) + ESP_LOGV(TAG, "Stop waiting for response from %d", waiting_for_response); + waiting_for_response = 0; + } } }