freemodbus: fix merge issues

pull/4494/head
Alex Lisitsyn 2019-12-10 14:30:25 +08:00 zatwierdzone przez Angus Gratton
rodzic 671fea5c58
commit ba1ee4092a
12 zmienionych plików z 78 dodań i 20 usunięć

Wyświetl plik

@ -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:

Wyświetl plik

@ -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.

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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)"