From ba1ee4092a6f6e13c46ebf799812c82375830a16 Mon Sep 17 00:00:00 2001 From: Alex Lisitsyn Date: Tue, 10 Dec 2019 14:30:25 +0800 Subject: [PATCH] freemodbus: fix merge issues --- .../modbus_controller/mbc_serial_master.c | 2 +- examples/protocols/modbus/serial/README.md | 79 +++++++++++++++---- .../CMakeLists.txt | 0 .../modbus/serial/mb_example_common/README.md | 7 ++ .../component.mk | 0 .../include/modbus_params.h | 0 .../modbus_params.c | 0 .../modbus/serial/mb_master/CMakeLists.txt | 2 +- .../modbus/serial/mb_master/Makefile | 2 +- .../modbus/serial/mb_slave/CMakeLists.txt | 2 +- .../protocols/modbus/serial/mb_slave/Makefile | 2 +- tools/ci/check_examples_cmake_make.sh | 2 +- 12 files changed, 78 insertions(+), 20 deletions(-) rename examples/protocols/modbus/serial/{common_components => mb_example_common}/CMakeLists.txt (100%) create mode 100644 examples/protocols/modbus/serial/mb_example_common/README.md rename examples/protocols/modbus/serial/{common_components => mb_example_common}/component.mk (100%) rename examples/protocols/modbus/serial/{common_components => mb_example_common}/include/modbus_params.h (100%) rename examples/protocols/modbus/serial/{common_components => mb_example_common}/modbus_params.c (100%) diff --git a/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c b/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c index 74df9c68bf..66019b3c4c 100644 --- a/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c +++ b/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c @@ -262,7 +262,7 @@ static esp_err_t mbc_serial_master_send_request(mb_param_request_t* request, voi break; case MB_MRE_MASTER_BUSY: - error = ESP_ERR_INVALID_STATE; // Master is busy (previous request is pending + error = ESP_ERR_INVALID_STATE; // Master is busy (previous request is pending) break; default: diff --git a/examples/protocols/modbus/serial/README.md b/examples/protocols/modbus/serial/README.md index a164d5f276..2e5d0b7fc8 100644 --- a/examples/protocols/modbus/serial/README.md +++ b/examples/protocols/modbus/serial/README.md @@ -1,31 +1,82 @@ -### Modbus Master-Slave Example +# Modbus Master-Slave Example ## Overview These two projects illustrate the communication between Modbus master and slave device in the segment. Master initializes Modbus interface driver and then reads parameters from slave device in the segment. After several successful read attempts slave sets the alarm relay (end of test condition). -Once master reads the alarm it stops communication and destroy driver. See README.md for each project for more information. +Once master reads the alarm it stops communication and destroy driver. -## Wiring +The examples: -The master and slave boards should be connected to each other through the RS485 interface line driver. +* `examples/protocols/modbus/serial/mb_master` - Modbus serial master ASCII/RTU +* `examples/protocols/modbus/serial/mb_slave` - Modbus serial slave ASCII/RTU + +See README.md for each individual project for more information. + +## How to use example + +### Hardware Required + +This example can be run on any commonly available ESP32 development board. +The master and slave boards should be connected to each other through the RS485 interface line driver. See the connection schematic in README.md files of each example. -## Configure the project +### Configure the project This example test requires communication mode setting for master and slave be the same and slave address set to 1. +Please refer to README.md files of each example project for more information. ## About common_component in this example -The folder "common_components" includes definitions of parameter structures for master and slave device (share the same parameters). -However, currently it is for example purpose only. +The folder "mb_example_common" includes definitions of parameter structures for master and slave device (both projects share the same parameters). +However, currently it is for example purpose only and can be modified for particular application. -## Start example test +## Example Output + +Example of Slave output: + +``` +I (343) SLAVE_TEST: Modbus slave stack initialized. +I (343) SLAVE_TEST: Start modbus test... +I (81463) SLAVE_TEST: HOLDING READ (81150420 us), ADDR:1, TYPE:2, INST_ADDR:0x3ffb2868, SIZE:6 +I (82463) SLAVE_TEST: HOLDING READ (82150720 us), ADDR:1, TYPE:2, INST_ADDR:0x3ffb2868, SIZE:6 +I (83573) SLAVE_TEST: HOLDING READ (83260630 us), ADDR:1, TYPE:2, INST_ADDR:0x3ffb2868, SIZE:6 +I (84603) SLAVE_TEST: HOLDING READ (84290530 us), ADDR:1, TYPE:2, INST_ADDR:0x3ffb2868, SIZE:6 +I (85703) SLAVE_TEST: HOLDING READ (85396692 us), ADDR:1, TYPE:2, INST_ADDR:0x3ffb2868, SIZE:6 +``` + +Example of Modbus Master output: + +``` +I (399) MASTER_TEST: Modbus master stack initialized... +I (499) MASTER_TEST: Start modbus test... +I (549) MASTER_TEST: Characteristic #0 Data_channel_0 (Volts) value = 1.230000 (0x3f9d70a4) read successful. +I (629) MASTER_TEST: Characteristic #1 Humidity_1 (%rH) value = 12.100000 (0x4141999a) read successful. +I (709) MASTER_TEST: Characteristic #2 Temperature_1 (C) value = 3.560000 (0x4063d70a) read successful. +I (769) MASTER_TEST: Characteristic #3 Humidity_2 (%rH) value = 23.400000 (0x41bb3333) read successful. +I (829) MASTER_TEST: Characteristic #4 Temperature_2 (C) value = 5.890000 (0x40bc7ae1) read successful. +I (889) MASTER_TEST: Characteristic #5 Humidity_3 (%rH) value = 34.500000 (0x420a0000) read successful. +E (949) MB_CONTROLLER_MASTER: mbc_master_get_parameter(111): SERIAL master get parameter failure error=(0x108) (ESP_ERR_INVALID_RESPONSE). +E (949) MASTER_TEST: Characteristic #6 (RelayP1) read fail, err = 264 (ESP_ERR_INVALID_RESPONSE). +E (1029) MB_CONTROLLER_MASTER: mbc_master_get_parameter(111): SERIAL master get parameter failure error=(0x108) (ESP_ERR_INVALID_RESPONSE). +E (1029) MASTER_TEST: Characteristic #7 (RelayP2) read fail, err = 264 (ESP_ERR_INVALID_RESPONSE). +``` + +## Troubleshooting + +If the examples do not work as expected and slave and master boards are not able to communicate correctly it is possible to find the reason for errors. +The most important errors are described in master example output and formatted as below: + +``` +E (1692332) MB_CONTROLLER_MASTER: mbc_master_get_parameter(111): SERIAL master get parameter failure error=(0x107) (ESP_ERR_TIMEOUT). +``` + +ESP_ERR_TIMEOUT (0x107) - Modbus slave device does not respond during configured timeout. Check the connection and ability for communication using uart_echo_rs485 example or increase +Kconfig value CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND (CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS). + +ESP_ERR_NOT_SUPPORTED (0x106), ESP_ERR_INVALID_RESPONSE (0x108) - Modbus slave device does not support requested command or register and sent exeption response. + +ESP_ERR_INVALID_STATE (0x103) - Modbus stack is not configured correctly or can't work correctly due to critical failure. + -This test requires to set ```TEST_FW_PATH``` environment variable and other required tools and python packages. -1. Build the master and slave examples in appropriate folders as described in README.md file of each example. -2. Set current folder to ```examples/protocols/modbus/serial/``` and start the example test script ```python example_test.py``` -3. The script has to find two ESP32 connected boards and flash master and slave applications, checks its configuration parameters then start test. -4. Once boards flashed it starts applications and captures master and slave boards output through the terminal. -5. The script uses regular expressions to check correctness of initialization and quality of communication between boards over RS485 interface. diff --git a/examples/protocols/modbus/serial/common_components/CMakeLists.txt b/examples/protocols/modbus/serial/mb_example_common/CMakeLists.txt similarity index 100% rename from examples/protocols/modbus/serial/common_components/CMakeLists.txt rename to examples/protocols/modbus/serial/mb_example_common/CMakeLists.txt diff --git a/examples/protocols/modbus/serial/mb_example_common/README.md b/examples/protocols/modbus/serial/mb_example_common/README.md new file mode 100644 index 0000000000..6fa4b2e6ed --- /dev/null +++ b/examples/protocols/modbus/serial/mb_example_common/README.md @@ -0,0 +1,7 @@ +# Modbus Example Common + +This directory contains component that is common for Modbus master and slave examples. The component defines Modbus parameters that are shared between examples and provide code that you can copy and adapt into your own projects. +For more information please refer to Modbus example README.md files located in the folders: + +* `examples/protocols/modbus/serial/mb_master` Modbus serial master implementation (RTU and ASCII) +* `examples/protocols/modbus/serial/mb_slave` Modbus serial slave implementation (RTU and ASCII) \ No newline at end of file diff --git a/examples/protocols/modbus/serial/common_components/component.mk b/examples/protocols/modbus/serial/mb_example_common/component.mk similarity index 100% rename from examples/protocols/modbus/serial/common_components/component.mk rename to examples/protocols/modbus/serial/mb_example_common/component.mk diff --git a/examples/protocols/modbus/serial/common_components/include/modbus_params.h b/examples/protocols/modbus/serial/mb_example_common/include/modbus_params.h similarity index 100% rename from examples/protocols/modbus/serial/common_components/include/modbus_params.h rename to examples/protocols/modbus/serial/mb_example_common/include/modbus_params.h diff --git a/examples/protocols/modbus/serial/common_components/modbus_params.c b/examples/protocols/modbus/serial/mb_example_common/modbus_params.c similarity index 100% rename from examples/protocols/modbus/serial/common_components/modbus_params.c rename to examples/protocols/modbus/serial/mb_example_common/modbus_params.c diff --git a/examples/protocols/modbus/serial/mb_master/CMakeLists.txt b/examples/protocols/modbus/serial/mb_master/CMakeLists.txt index 7e322563da..f97cc2e6e2 100644 --- a/examples/protocols/modbus/serial/mb_master/CMakeLists.txt +++ b/examples/protocols/modbus/serial/mb_master/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.5) set(SUPPORTED_TARGETS esp32) -set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/serial/common_components) +set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/serial/mb_example_common) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(modbus_master) diff --git a/examples/protocols/modbus/serial/mb_master/Makefile b/examples/protocols/modbus/serial/mb_master/Makefile index 8711a84aa3..4f9ca73454 100644 --- a/examples/protocols/modbus/serial/mb_master/Makefile +++ b/examples/protocols/modbus/serial/mb_master/Makefile @@ -5,7 +5,7 @@ PROJECT_NAME := modbus_master -EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/protocols/modbus/serial/common_components +EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/protocols/modbus/serial/mb_example_common include $(IDF_PATH)/make/project.mk diff --git a/examples/protocols/modbus/serial/mb_slave/CMakeLists.txt b/examples/protocols/modbus/serial/mb_slave/CMakeLists.txt index 1427402626..13fa6301dc 100644 --- a/examples/protocols/modbus/serial/mb_slave/CMakeLists.txt +++ b/examples/protocols/modbus/serial/mb_slave/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5) set(SUPPORTED_TARGETS esp32) -set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/serial/common_components) +set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/serial/mb_example_common) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(modbus_slave) diff --git a/examples/protocols/modbus/serial/mb_slave/Makefile b/examples/protocols/modbus/serial/mb_slave/Makefile index be383a5fe9..851d87eef7 100644 --- a/examples/protocols/modbus/serial/mb_slave/Makefile +++ b/examples/protocols/modbus/serial/mb_slave/Makefile @@ -5,7 +5,7 @@ PROJECT_NAME := modbus_slave -EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/protocols/modbus/serial/common_components +EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/protocols/modbus/serial/mb_example_common include $(IDF_PATH)/make/project.mk diff --git a/tools/ci/check_examples_cmake_make.sh b/tools/ci/check_examples_cmake_make.sh index ed560a21bc..f23ebc56e2 100755 --- a/tools/ci/check_examples_cmake_make.sh +++ b/tools/ci/check_examples_cmake_make.sh @@ -2,7 +2,7 @@ # While we support GNU Make & CMake together, check the same examples are present for both -CMAKE_EXAMPLE_PATHS=$( find ${IDF_PATH}/examples/ -type f -name CMakeLists.txt | grep -v "/components/" | grep -v "/common_components/" | grep -v "/main/" | grep -v "/build_system/cmake/") +CMAKE_EXAMPLE_PATHS=$( find ${IDF_PATH}/examples/ -type f -name CMakeLists.txt | grep -v "/components/" | grep -v "/common_components/" | grep -v "/main/" | grep -v "/build_system/cmake/" | grep -v "/mb_example_common/") MAKE_EXAMPLE_PATHS=$( find ${IDF_PATH}/examples/ -type f -name Makefile | grep -v "/build_system/cmake/") CMAKE_EXAMPLE_PATHS="$(/usr/bin/dirname $CMAKE_EXAMPLE_PATHS | sort -n)"