From 5317bfff6db3727a7829ab0dcfa35399fcd2dae6 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Wed, 21 May 2014 12:23:21 +1200 Subject: [PATCH] Added ability to enable/disable echo with 'SerialPort::EnableEcho()'. --- README.rst | 7 ++++--- include/SerialPort.hpp | 6 +++++- src/SerialPort.cpp | 12 +++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 00be6a5..bd285f4 100644 --- a/README.rst +++ b/README.rst @@ -11,8 +11,8 @@ Serial port library written in C++ - Author: gbmhunter (http://www.cladlab.com) - Created: 2014/01/07 -- Last Modified: 2014/05/15 -- Version: v1.0.0.0 +- Last Modified: 2014/05/21 +- Version: v1.0.1.0 - Company: CladLabs - Project: Free Code Libraries - Language: C++ @@ -89,5 +89,6 @@ Changelog ========= ========== =================================================================================================== Version Date Comment ========= ========== =================================================================================================== -v1.0.0.0 2013/05/15 Initial commit. serial-port-cpp library has basic functions up and running. +v1.0.1.0 2014/05/21 Added ability to enable/disable echo with 'SerialPort::EnableEcho()'. +v1.0.0.0 2014/05/15 Initial commit. serial-port-cpp library has basic functions up and running. ========= ========== =================================================================================================== \ No newline at end of file diff --git a/include/SerialPort.hpp b/include/SerialPort.hpp index 953bb02..7a035a7 100644 --- a/include/SerialPort.hpp +++ b/include/SerialPort.hpp @@ -2,7 +2,7 @@ //! @file SerialPort.hpp //! @author Geoffrey Hunter () //! @created 2014/01/07 -//! @last-modified 2014/05/14 +//! @last-modified 2014/05/21 //! @brief The main serial port class. //! @details //! See README.rst in repo root dir for more info. @@ -51,6 +51,10 @@ namespace SerialPort //! @param numOfCharToWait Minimum number of characters to wait for before returning. Set to 0 for non-blocking mode. void SetNumCharsToWait(uint32_t numCharsToWait); + //! @brief Enables/disables echo. + //! param echoOn Pass in true to enable echo, false to disable echo. + void EnableEcho(bool echoOn); + //! @brief Opens the COM port for use. //! @throws {std::runtime_error} if filename has not been set. //! {std::system_error} if system open() operation fails. diff --git a/src/SerialPort.cpp b/src/SerialPort.cpp index 035519b..ea6636b 100644 --- a/src/SerialPort.cpp +++ b/src/SerialPort.cpp @@ -2,7 +2,7 @@ //! @file SerialPort.cpp //! @author Geoffrey Hunter () //! @created 2014/01/07 -//! @last-modified 2014/05/15 +//! @last-modified 2014/05/21 //! @brief The main serial port class. //! @details //! See README.rst in repo root dir for more info. @@ -118,6 +118,16 @@ namespace SerialPort } + void SerialPort::EnableEcho(bool echoOn) + { + termios settings = this->GetTermios(); + settings.c_lflag = echoOn + ? (settings.c_lflag | ECHO ) + : (settings.c_lflag & ~(ECHO)); + //tcsetattr( STDIN_FILENO, TCSANOW, &settings ); + this->SetTermios(settings); + } + void SerialPort::SetEverythingToCommonDefaults() { this->sp->PrintDebug(SmartPrint::Ss() << "Configuring COM port \"" << this->filePath << "\"."); -- libgit2 0.21.4