| 503 | } |
| 504 | |
| 505 | void |
| 506 | SerialStream::SetStopBits(const StopBits& stopBits) |
| 507 | try |
| 508 | { |
| 509 | auto my_buffer = dynamic_cast<SerialStreamBuf *>(this->rdbuf()) ; |
| 510 | |
| 511 | // Make sure that we are dealing with a SerialStreamBuf before |
| 512 | // proceeding. This check also makes sure that we have a non-NULL |
| 513 | // buffer associated with this stream. |
| 514 | if (my_buffer != nullptr) |
| 515 | { |
| 516 | // Try to set the number of stop bits. If the corresponding function of the |
| 517 | // SerialStreamBuf class returns STOP_BITS_INVALID, then we have a |
| 518 | // problem and the stream is no longer valid for I/O. |
| 519 | my_buffer->SetStopBits(stopBits) ; |
| 520 | } |
| 521 | else |
| 522 | { |
| 523 | // If the dynamic_cast above failed then we either have a NULL |
| 524 | // streambuf associated with this stream or we have a buffer of |
| 525 | // class other than SerialStreamBuf. In either case, we have a |
| 526 | // problem and we should stop all I/O using this stream. |
| 527 | setstate(badbit) ; |
| 528 | } |
| 529 | } |
| 530 | catch (const std::exception&) |
| 531 | { |
| 532 | setstate(std::ios_base::failbit) ; |
| 533 | throw ; |
| 534 | } |
| 535 | |
| 536 | StopBits |
| 537 | SerialStream::GetStopBits() |