Skip to content

Commit

Permalink
Change modbus send_wait_time configuration to timeout only if bytes a…
Browse files Browse the repository at this point in the history
…re 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.
  • Loading branch information
exciton committed Oct 20, 2024
1 parent 439a7ab commit 160bdca
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions esphome/components/modbus/modbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

}
Expand Down

0 comments on commit 160bdca

Please sign in to comment.