1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +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 void
open (); open ();
void
cancel();
void void
close (); close ();

View File

@ -211,6 +211,10 @@ public:
bool bool
isOpen () const; isOpen () const;
/*! Cancels all pending read and write operation. */
void
cancel();
/*! Closes the serial port. */ /*! Closes the serial port. */
void void
close (); 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 void
Serial::SerialImpl::close () Serial::SerialImpl::close ()
{ {
this->cancel();
if (is_open_ == true) { if (is_open_ == true) {
if (fd_ != INVALID_HANDLE_VALUE) { if (fd_ != INVALID_HANDLE_VALUE) {
int ret; int ret;

View File

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