mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 10:56:43 +00:00
Allow ignoring of failed Modbus response CRC (#3930)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -102,8 +102,12 @@ bool Modbus::parse_modbus_byte_(uint8_t byte) {
|
||||
uint16_t computed_crc = crc16(raw, data_offset + data_len);
|
||||
uint16_t remote_crc = uint16_t(raw[data_offset + data_len]) | (uint16_t(raw[data_offset + data_len + 1]) << 8);
|
||||
if (computed_crc != remote_crc) {
|
||||
ESP_LOGW(TAG, "Modbus CRC Check failed! %02X!=%02X", computed_crc, remote_crc);
|
||||
return false;
|
||||
if (this->disable_crc_) {
|
||||
ESP_LOGD(TAG, "Modbus CRC Check failed, but ignored! %02X!=%02X", computed_crc, remote_crc);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Modbus CRC Check failed! %02X!=%02X", computed_crc, remote_crc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<uint8_t> data(this->rx_buffer_.begin() + data_offset, this->rx_buffer_.begin() + data_offset + data_len);
|
||||
@@ -139,6 +143,7 @@ void Modbus::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Modbus:");
|
||||
LOG_PIN(" Flow Control Pin: ", this->flow_control_pin_);
|
||||
ESP_LOGCONFIG(TAG, " Send Wait Time: %d ms", this->send_wait_time_);
|
||||
ESP_LOGCONFIG(TAG, " CRC Disabled: %s", YESNO(this->disable_crc_));
|
||||
}
|
||||
float Modbus::get_setup_priority() const {
|
||||
// After UART bus
|
||||
|
||||
Reference in New Issue
Block a user