renamed modbus test to fit other tests I will add

This commit is contained in:
2025-06-13 08:29:22 +02:00
parent 5ab33e3a7b
commit dc83c27306
6 changed files with 0 additions and 0 deletions

1
software/test_modbus/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build

View File

@@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
]
}
],
"version": 4
}

View File

@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)
target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE ../lib/modbus.c)
target_include_directories(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../lib
)

View File

@@ -0,0 +1,9 @@
&usart1 {
status = "okay";
current-speed = <9600>;
modbus0 {
compatible = "zephyr,modbus-serial";
status = "okay";
// de-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */
};
};

View File

@@ -0,0 +1,13 @@
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_UART_CONSOLE=y # Console on USART1
#CONFIG_RTT_CONSOLE=y
#CONFIG_USE_SEGGER_RTT=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=n
CONFIG_MODBUS=y
CONFIG_MODBUS_ROLE_CLIENT=y

View File

@@ -0,0 +1,78 @@
/* Testing MODBUS functionality
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 <zephyr/logging/log.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include "modbus.h"
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
int main(void)
{
int rc;
rc = mb_init_client();
if (rc != 0)
{
LOG_ERR("Failed to initialize Modbus client: %d", rc);
return rc;
}
LOG_INF("Modbus client initialized successfully");
double water_level = 0.0;
int water_level_mm, water_level_min_mm, water_level_max_mm = 0;
rc = mb_write_minimum_mm(42); // Set the zero point for water level
if (rc < 0)
{
LOG_ERR("Failed to write minimum water level: %d", rc);
return rc;
}
rc = mb_write_maximum_mm(2000); // Set the 2m point for water level
if (rc < 0)
{
LOG_ERR("Failed to write maximum water level: %d", rc);
return rc;
}
rc = mb_read_minimum_mm(&water_level_min_mm);
if (rc < 0)
{
LOG_ERR("Failed to read minimum water level: %d", rc);
return rc;
}
rc = mb_read_maximum_mm(&water_level_max_mm);
if (rc < 0)
{
LOG_ERR("Failed to read maximum water level: %d", rc);
return rc;
}
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);
/* 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;
}