espressif / esp-modbus

ESP-Modbus - the officially suppported library for Modbus protocol (serial RS485 + TCP over WiFi or Ethernet).
Apache License 2.0
107 stars 49 forks source link

How to add word_length & stop_bits in mb_communication_info_t struct (IDFGH-9713) #25

Closed JimitD closed 1 month ago

JimitD commented 1 year ago

Hello Team,

In 'mb_communication_info_t stuct' there are no member given to configure 'word_length' and 'stop_bits'.

Where should I add this parameters to function accordingly.

comm_info.mode = MB_MODE_RTU, comm_info.slave_addr = SALVE_ADDR_; comm_info.port = MB_PORT_NUM; comm_info.baudrate = BAUDRATE_; comm_info.parity = PARITY_; esp_err_t err_slave_setup = ESP_ERROR_CHECK_WITHOUT_ABORT(mbc_slave_setup((void *)&comm_info));

alisitsyn commented 1 year ago

Hello @JimitD ,

Thank you for this report. Yes, the extended options are missing in the configuration structure. This was not addressed because the esp-modbus uses the legacy function prototypes from freemodbus. This is known issue and will be addressed in feature modbus update where the whole UART configuration structure will be propagated to modbus object constructor. For now, I would recommend you to use delayed init with call the function calls: uart_set_stop_bits , uart_set_word_length, in the application code after setup of modbus here. Note: even if you setup 2 stop bits but the peer sends the frame with one stop bit the ESP32 UART will not be able to recognize absence of one stop bit.

JimitD commented 1 year ago

Hi @alisitsyn,

Thank you for the input. I will check this out.

alisitsyn commented 8 months ago

The updated serial options in v2.0.0_beta release: serial options

alisitsyn commented 5 months ago

@JimitD , the documentation for v1.0.x will be updated to describe how to override the communication options:

image

alisitsyn commented 1 month ago

Closed as solved.