From 5ab33e3a7b7db4cd6ad064aaac355cde4e97a607 Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Fri, 13 Jun 2025 08:26:49 +0200 Subject: [PATCH] minimal changes --- software/lib/modbus.c | 3 +-- software/modbus_test/src/main.c | 41 +++++++++++++++------------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/software/lib/modbus.c b/software/lib/modbus.c index 7ad2703..ed118cf 100644 --- a/software/lib/modbus.c +++ b/software/lib/modbus.c @@ -4,8 +4,7 @@ #include #include -// LOG_MODULE_REGISTER(mbc, CONFIG_LOG_DEFAULT_LEVEL); -LOG_MODULE_REGISTER(mbc, 4); // Set log level to 4 (Debug) +LOG_MODULE_REGISTER(mbc, CONFIG_LOG_DEFAULT_LEVEL); #define MODBUS_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(zephyr_modbus_serial) diff --git a/software/modbus_test/src/main.c b/software/modbus_test/src/main.c index dd57a08..7a79b40 100644 --- a/software/modbus_test/src/main.c +++ b/software/modbus_test/src/main.c @@ -1,8 +1,9 @@ /* Testing MODBUS functionality - This code initializes a Modbus client, sets minimum and maximum water levels, - reads the current water level, and logs the results. - You can set the zero point and the 2m point for water level in lines 32 and 38. + This code initializes a Modbus client, sets the zero point and the 2m point for water level, + and reads the water level in both meters and millimeters. + It uses the Zephyr RTOS and its Modbus library to communicate with a Modbus server. */ + #include #include #include @@ -56,26 +57,22 @@ int main(void) LOG_INF("Water zero point is set to: %dmm", water_level_min_mm); LOG_INF("Water 2m point is set to: %dmm", water_level_max_mm); - while (1) - { /* Read water level */ - rc = mb_read_water_level(&water_level); - if (rc < 0) - { - LOG_ERR("Failed to read water level: %d", rc); - return rc; - } - rc = mb_read_water_level_mm(&water_level_mm); - if (rc < 0) - { - LOG_ERR("Failed to read water level: %d", rc); - return rc; - } - LOG_INF("Water level: %.3fm", water_level); - LOG_INF("Water level: %dmm", water_level_mm); - LOG_INF("Modbus test completed successfully"); - return 0; - k_sleep(K_SECONDS(1)); + /* Read water level */ + rc = mb_read_water_level(&water_level); + if (rc < 0) + { + LOG_ERR("Failed to read water level: %d", rc); + return rc; } + rc = mb_read_water_level_mm(&water_level_mm); + if (rc < 0) + { + LOG_ERR("Failed to read water level: %d", rc); + return rc; + } + LOG_INF("Water level: %.3fm", water_level); + LOG_INF("Water level: %dmm", water_level_mm); + LOG_INF("Modbus test completed successfully"); return 0; }