From d53dfce90ddc7f2f6dbd6e56b8011c363b87f584 Mon Sep 17 00:00:00 2001 From: jarvis Date: Sat, 8 Mar 2025 10:17:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=B0=86Modbus=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA=E5=AD=90=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 ++- 桌面.psd => SquareLineProj/桌面.psd | Bin components/FluxMod/CMakeLists.txt | 3 +++ main/FreeBus.c => components/FluxMod/FluxMod.c | 8 ++------ main/FreeBus.h => components/FluxMod/FluxMod.h | 2 +- components/FluxUI/ui_events.c | 1 + main/CMakeLists.txt | 4 ++-- main/i80_controller_example_main.c | 7 ++++++- 8 files changed, 17 insertions(+), 11 deletions(-) rename 桌面.psd => SquareLineProj/桌面.psd (100%) create mode 100644 components/FluxMod/CMakeLists.txt rename main/FreeBus.c => components/FluxMod/FluxMod.c (94%) rename main/FreeBus.h => components/FluxMod/FluxMod.h (98%) diff --git a/.vscode/settings.json b/.vscode/settings.json index ee293ab..3e4fd63 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,6 +17,7 @@ "files.associations": { "ledc.h": "c", "gpio.h": "c", - "sdmmc_host.h": "c" + "sdmmc_host.h": "c", + "modbus_params.h": "c" } } diff --git a/桌面.psd b/SquareLineProj/桌面.psd similarity index 100% rename from 桌面.psd rename to SquareLineProj/桌面.psd diff --git a/components/FluxMod/CMakeLists.txt b/components/FluxMod/CMakeLists.txt new file mode 100644 index 0000000..49aa046 --- /dev/null +++ b/components/FluxMod/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "FluxMod.c" + REQUIRES espressif__esp-modbus + INCLUDE_DIRS "." "C:/Espressif/frameworks/esp-idf-v5.3.1/examples/protocols/modbus/mb_example_common/include") \ No newline at end of file diff --git a/main/FreeBus.c b/components/FluxMod/FluxMod.c similarity index 94% rename from main/FreeBus.c rename to components/FluxMod/FluxMod.c index 9c7596c..9946769 100644 --- a/main/FreeBus.c +++ b/components/FluxMod/FluxMod.c @@ -1,5 +1,5 @@ -#include "FreeBus.h" +#include "FluxMod.h" static const char *TAG = "MASTER_TEST"; @@ -14,16 +14,12 @@ const mb_parameter_descriptor_t device_parameters[] = { // Calculate number of parameters in the table const uint16_t num_device_parameters = (sizeof(device_parameters)/sizeof(device_parameters[0])); -static esp_err_t master_init(void) +esp_err_t modbus_master_init(void) { // Initialize and start Modbus controller mb_communication_info_t comm = { .port = MB_PORT_NUM, -#if CONFIG_MB_COMM_MODE_ASCII - .mode = MB_MODE_ASCII, -#elif CONFIG_MB_COMM_MODE_RTU .mode = MB_MODE_RTU, -#endif .baudrate = MB_DEV_SPEED, .parity = MB_PARITY_NONE }; diff --git a/main/FreeBus.h b/components/FluxMod/FluxMod.h similarity index 98% rename from main/FreeBus.h rename to components/FluxMod/FluxMod.h index 2257862..f45884a 100644 --- a/main/FreeBus.h +++ b/components/FluxMod/FluxMod.h @@ -62,4 +62,4 @@ enum { }; /*Modbus߳ʼ*/ -static esp_err_t master_init(void); \ No newline at end of file +esp_err_t modbus_master_init(void); \ No newline at end of file diff --git a/components/FluxUI/ui_events.c b/components/FluxUI/ui_events.c index cbf267a..e947bec 100644 --- a/components/FluxUI/ui_events.c +++ b/components/FluxUI/ui_events.c @@ -19,6 +19,7 @@ void ReadSdCallFunc(lv_event_t * e) void F1callbackFunc(lv_event_t * e) { // Your code here + } void F2callbackFunc(lv_event_t * e) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 8b4dbb6..942e114 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -3,8 +3,8 @@ if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_EMBEDDED_BINARY) file(GLOB_RECURSE embedded_images images/*.c) endif() -idf_component_register(SRCS "FreeBus.c" "i80_controller_example_main.c" "lvgl_demo_ui.c" ${embedded_images} -REQUIRES FluxUI FluxPower spiffs FluxSD +idf_component_register(SRCS "i80_controller_example_main.c" "lvgl_demo_ui.c" ${embedded_images} +REQUIRES FluxUI FluxPower spiffs FluxSD FluxMod INCLUDE_DIRS ".") if(CONFIG_EXAMPLE_LCD_IMAGE_FROM_FILE_SYSTEM) diff --git a/main/i80_controller_example_main.c b/main/i80_controller_example_main.c index 2ba92dc..a1d83b1 100644 --- a/main/i80_controller_example_main.c +++ b/main/i80_controller_example_main.c @@ -23,7 +23,7 @@ #include "FluxSD.h" /*导入Modbus控制头文件*/ -#include "FreeBus.h" +#include "FluxMod.h" //新增触摸屏驱动头文件 #include "driver/i2c.h" @@ -34,6 +34,8 @@ static const char *TAG = "example"; +#include "modbus_params.h" + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// Please update the following configuration according to your LCD spec ////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -454,6 +456,9 @@ void app_main(void) /*初始化SD卡*/ flux_sd_init(); + + /*初始化Modbus*/ + //modbus_master_init(); // Lock the mutex due to the LVGL APIs are not thread-safe if (example_lvgl_lock(-1)) {