espressif / esp-modbus

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

如何运行多个master?How can I run multiple masters? (IDFGH-13567) #70

Closed zhuangqingshu closed 1 month ago

zhuangqingshu commented 1 month ago

假设我要在UART 1运行master_rtu 1,UART 2运行master_rtu 2,这能做到吗? Suppose I want to run master_rtu 1 on UART 1 and master_rtu 2 on UART 2. Can this be done?

另一种情况是,UART 1运行master_rtu 1,再运行一个master_tcp,这能做到吗? Another situation is that master_rtu 1 runs on UART 1 and then a master_tcp is run. Can this be done?

alisitsyn commented 1 month ago

Hi @zhuangqingshu,

Suppose I want to run master_rtu 1 on UART 1 and master_rtu 2 on UART 2. Can this be done?

It is not possible on esp-modbus v1.0.x because of limitation but is possible to do on esp-modbus v2.0.0-beta.

Another situation is that master_rtu 1 runs on UART 1 and then a master_tcp is run. Can this be done?

It is not possible on esp-modbus v1.0.x because of limitation (only one master and one slave is supported in the same application). However, this can be done with esp-modbus v2.0.0-beta. The latest update of component v2.0.0-beta is almost ready and it will support any number of Modbus master and slave instances with different options (limited by resources and performance). The TCP instances handling is performed using the event state machine and dedicated tasks. The common Modbus driver is used to handle the TCP communication for each instance. Please refer to the esp-modbus v2.0.0-beta, the update will be announced soon.

alisitsyn commented 1 month ago

@zhuangqingshu , The esp-modbus v2.0.0-beta.1 component is released. The updated version supports the multi-instance TCP Slave and Master with its own communication options. The pre-release esp-modbus component version 2.0.0-beta.1 can be selected by idf_component.yml in main folder like below:

dependencies:
  idf:
     version: ">=4.1.0"
  espressif/esp-modbus:
    version: "^2.0.0-beta"
  espressif/mdns:
    version: "^1.0.0"
    rules:
      - if: "idf_version >=5.0"
  mb_example_common:
    path: "../mb_example_common"
  protocol_examples_common:
    path: ${IDF_PATH}/examples/common_components/protocol_examples_common