From 74e5d380f51635ee9eceb51d46bcf9a1376ee792 Mon Sep 17 00:00:00 2001 From: Jie Date: Fri, 1 Nov 2024 16:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Until=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/serial.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/serial.h b/include/serial.h index 44a257f..6ddc17f 100644 --- a/include/serial.h +++ b/include/serial.h @@ -268,6 +268,7 @@ namespace serial { auto endTime = std::chrono::system_clock::now() + std::chrono::milliseconds(timeout); ser.flushReceiver(); + std::string resp; std::string reallyCommand = std::string(command) + endChar; ser.writeString(reallyCommand.c_str()); Log("Send : " + reallyCommand); @@ -278,8 +279,10 @@ namespace serial { auto size = ser.readBytes(buffer.get(), availableSize, timeout); buffer[size] = '\0'; auto str = std::string(buffer.get()); - if (size > 0) + if (size > 0){ Log("Receive: " + str); + resp += str; + } if (((str.find(expect) != std::string::npos) && ...)) { return true; } @@ -307,7 +310,7 @@ namespace serial { resp += str; if (size > 0) Log("Receive: " + str); - if (((str.find(expect) != std::string::npos) && ...)) { + if (((resp.find(expect) != std::string::npos) && ...)) { return resp; } }