From 73872bb212d68a7f82351fe02e0ebbe697920663 Mon Sep 17 00:00:00 2001 From: lzq Date: Mon, 20 Oct 2025 13:09:41 +0800 Subject: [PATCH] 1 --- config/xin_shun_jie.json | 6 +++++- src/platform_scale/generic_platform_scale.cpp | 8 ++++---- src/platform_scale/platform_scale_properties.h | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config/xin_shun_jie.json b/config/xin_shun_jie.json index 990810b..c714917 100644 --- a/config/xin_shun_jie.json +++ b/config/xin_shun_jie.json @@ -1,6 +1,6 @@ { "name": "鑫顺洁", - "delay": 0, + "delay": 60, "daemon": true, "httpSvr": { "port": 11000 @@ -94,7 +94,10 @@ { "sn": "1", "name": "地磅", + "delay": 5, "sample": 20, + "retries": 30, + "weight": 200.0, "port": "COM7", "baudRate": 9600, "byteSize": 8, @@ -114,6 +117,7 @@ { "sn": "1", "name": "摄像头", + "type": 0, "ip": "192.168.1.206", "port": 8000, "username": "admin", diff --git a/src/platform_scale/generic_platform_scale.cpp b/src/platform_scale/generic_platform_scale.cpp index 48d736c..0204e87 100644 --- a/src/platform_scale/generic_platform_scale.cpp +++ b/src/platform_scale/generic_platform_scale.cpp @@ -119,15 +119,15 @@ namespace zsy /*status = 2;*/ LOGGER_INFO("正在称重..."); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + if (config.delay > 0) std::this_thread::sleep_for(std::chrono::milliseconds(config.delay * 1000)); auto processor = static_cast(serialPort->processor); int count = 0; - while (processor->steady.load() < config.sample) + while (processor->steady.load() < config.sample || processor->weight.load() <= config.weight) { count++; - if (count >= 10) + if (count >= config.retries) { - LOGGER_ERROR("称重失败,连续 {} 次未稳定", count); + LOGGER_ERROR("称重失败,连续 {} 次未稳定或磅重低于阈值 {} KG,当前磅重:{} KG", count, config.weight, processor->weight.load()); /*status = 1;*/ return 0.0; } diff --git a/src/platform_scale/platform_scale_properties.h b/src/platform_scale/platform_scale_properties.h index 3888783..f6abac1 100644 --- a/src/platform_scale/platform_scale_properties.h +++ b/src/platform_scale/platform_scale_properties.h @@ -8,7 +8,10 @@ namespace zsy { std::string sn; std::string name; + uint8_t delay; uint8_t sample; + uint8_t retries; + double weight; std::string port; uint32_t baudRate{9600}; uint8_t byteSize{8}; @@ -20,7 +23,10 @@ namespace zsy { PARSE_JSON(sn, o.sn); PARSE_JSON(name, o.name); + PARSE_JSON(delay, o.delay); PARSE_JSON(sample, o.sample); + PARSE_JSON(retries, o.retries); + PARSE_JSON(weight, o.weight); PARSE_JSON(port, o.port); PARSE_JSON(baudRate, o.baudRate); PARSE_JSON(byteSize, o.byteSize);