diff --git a/src/async_port/async_can.cpp b/src/async_port/async_can.cpp index e88cab5..7343ee3 100644 --- a/src/async_port/async_can.cpp +++ b/src/async_port/async_can.cpp @@ -76,15 +76,15 @@ bool AsyncCAN::SetupPort() { } void AsyncCAN::StopService() { - // release port fd - const int close_result = ::close(can_fd_); - can_fd_ = -1; - // stop io thread io_context_.stop(); if (io_thread_.joinable()) io_thread_.join(); io_context_.reset(); + // release port fd + const int close_result = ::close(can_fd_); + can_fd_ = -1; + port_opened_ = false; } diff --git a/src/async_port/async_serial.cpp b/src/async_port/async_serial.cpp index fcd561d..bc1595a 100644 --- a/src/async_port/async_serial.cpp +++ b/src/async_port/async_serial.cpp @@ -71,16 +71,16 @@ bool AsyncSerial::SetupPort() { } void AsyncSerial::StopService() { - if (IsOpened()) { - serial_port_.cancel(); - serial_port_.close(); - } - // stop io thread io_context_.stop(); if (io_thread_.joinable()) io_thread_.join(); io_context_.reset(); + if (IsOpened()) { + serial_port_.cancel(); + serial_port_.close(); + } + port_opened_ = false; }