1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 03:34:53 +08:00

Merge b520457b14f9b5570a6bae5afde4f6967863bd71 into 69e0372cf0d3796e84ce9a09aff1d74496f68720

This commit is contained in:
Morteza Aghazamani 2022-03-14 01:22:31 -06:00 committed by GitHub
commit 5275fd6336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 0 deletions

View File

@ -66,6 +66,9 @@ public:
void
open ();
void
cancel();
void
close ();

View File

@ -211,6 +211,10 @@ public:
bool
isOpen () const;
/*! Cancels all pending read and write operation. */
void
cancel();
/*! Closes the serial port. */
void
close ();

View File

@ -274,9 +274,27 @@ Serial::SerialImpl::reconfigurePort ()
}
}
void
Serial::SerialImpl::cancel()
{
if (is_open_ == true) {
if (fd_ != INVALID_HANDLE_VALUE) {
int ret;
ret = CancelIoEx(fd_, NULL);
DWORD last_error = GetLastError();
if (ret == 0 && last_error != ERROR_NOT_FOUND) {
stringstream ss;
ss << "Error while canceling serial port: " << last_error;
THROW(IOException, ss.str().c_str());
}
}
}
}
void
Serial::SerialImpl::close ()
{
this->cancel();
if (is_open_ == true) {
if (fd_ != INVALID_HANDLE_VALUE) {
int ret;

View File

@ -83,6 +83,12 @@ Serial::open ()
pimpl_->open ();
}
void
Serial::cancel()
{
pimpl_->cancel();
}
void
Serial::close ()
{