多线程支持
This commit is contained in:
parent
2404e17d10
commit
cea5209222
@ -138,6 +138,8 @@ void ComKit::Start(std::string watchingPort, std::string input_commands) {
|
||||
}
|
||||
void ComKit::Work() {
|
||||
if (isWorking) {
|
||||
std::thread([]() {
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
auto currentPortStructures = GetAllComPortNames();
|
||||
std::vector<std::string> currentPorts;
|
||||
for (auto s : *currentPortStructures) {
|
||||
@ -146,7 +148,8 @@ void ComKit::Work() {
|
||||
for (auto &port : watchingComPort) {
|
||||
if (std::find(currentPorts.begin(), currentPorts.end(), port) !=
|
||||
currentPorts.end()) {
|
||||
spdlog::info(std::format("Start Work With Port [{}]", port));
|
||||
spdlog::info(
|
||||
std::format("Start Work With Port [{}]", port));
|
||||
device.OpenDevice(port);
|
||||
for (auto &command : commands) {
|
||||
spdlog::info(std::format("Send Command: {}", command));
|
||||
@ -158,6 +161,7 @@ void ComKit::Work() {
|
||||
device.CloseDevice();
|
||||
}
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user