添加读取串口函数
This commit is contained in:
parent
10d47de9b8
commit
01dba9107e
@ -292,6 +292,27 @@ namespace serial {
|
||||
return false;
|
||||
}
|
||||
|
||||
template<int timeout = 1000, _SupportString... Args>
|
||||
bool ReadUntil(Args... args){
|
||||
auto end_time = std::chrono::system_clock::now() + 1s;
|
||||
std::string resp;
|
||||
while(std::chrono::system_clock::now() < end_time){
|
||||
std::this_thread::sleep_for(10ms);
|
||||
auto available_size = ser.available();
|
||||
auto buffer = std::unique_ptr<char[]>{available_size + 1};
|
||||
auto read_size = ser.readBytes(buffer.get(), available_size, timeout);
|
||||
buffer[read_size] = '\0';
|
||||
auto str = std::string(buffer.get());
|
||||
resp += str;
|
||||
if(read_size > 0){
|
||||
Log("Read: " + str);
|
||||
}
|
||||
if(((resp.find(args) != std::string::npos) && ...)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <int timeout = 200, _SupportString T, _SupportString... Args>
|
||||
std::string GetAtUntilAndReturn(T command, Args... expect)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user