Modbus RTU - Multi Devices
This commit is contained in:
32
modbus_uart.txt
Normal file
32
modbus_uart.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
if (cfg->rtu.de_pin >= 0)
|
||||
{
|
||||
ret = uart_set_mode(uart_num, UART_MODE_RS485_HALF_DUPLEX);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "uart_set_mode(RS485_HALF_DUPLEX) failed: %s", esp_err_to_name(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "UART RS485 half-duplex mode enabled (DE pin=%d)", cfg->rtu.de_pin);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "UART normal mode enabled (shield auto-direction assumed)");
|
||||
}
|
||||
|
||||
if (resp_len > 0U)
|
||||
{
|
||||
int written = uart_write_bytes(g_rtu_ctx.uart_num,
|
||||
(const char *)tx_buf,
|
||||
(uint32_t)resp_len);
|
||||
|
||||
ESP_LOGI(TAG, "UART wrote %d bytes", written);
|
||||
|
||||
if (written < 0)
|
||||
{
|
||||
ESP_LOGW(TAG, "uart_write_bytes failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(uart_wait_tx_done(g_rtu_ctx.uart_num, pdMS_TO_TICKS(100)));
|
||||
}
|
||||
Reference in New Issue
Block a user