From 125c105e3fe01de3143d1e9b6d92dbfe181c58e8 Mon Sep 17 00:00:00 2001 From: daniser Date: Tue, 6 Aug 2013 01:28:46 +0300 Subject: [PATCH 1/2] Implemented Serial::available() for Windows --- src/impl/win.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/impl/win.cc b/src/impl/win.cc index a17b83e..dc79e8e 100644 --- a/src/impl/win.cc +++ b/src/impl/win.cc @@ -274,7 +274,16 @@ Serial::SerialImpl::isOpen () const size_t Serial::SerialImpl::available () { - THROW (IOException, "available is not implemented on Windows."); + if (!is_open_) { + return 0; + } + COMSTAT cs; + if(!ClearCommError(fd_, NULL, &cs)) { + stringstream ss; + ss << "Error while checking status of the serial port: " << GetLastError(); + THROW (IOException, ss.str().c_str()); + } + return (size_t) (cs.cbInQue); } size_t From 079615f11f9f01e4eaf1224d45c5ace2eaa01d52 Mon Sep 17 00:00:00 2001 From: daniser Date: Tue, 6 Aug 2013 02:08:22 +0300 Subject: [PATCH 2/2] Update win.cc --- src/impl/win.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl/win.cc b/src/impl/win.cc index dc79e8e..a8c0faf 100644 --- a/src/impl/win.cc +++ b/src/impl/win.cc @@ -283,7 +283,7 @@ Serial::SerialImpl::available () ss << "Error while checking status of the serial port: " << GetLastError(); THROW (IOException, ss.str().c_str()); } - return (size_t) (cs.cbInQue); + return static_cast(cs.cbInQue); } size_t