Commit 5317bfff6db3727a7829ab0dcfa35399fcd2dae6

Authored by Geoffrey Hunter
1 parent 4ec9c734

Added ability to enable/disable echo with 'SerialPort::EnableEcho()'.

README.rst
@@ -11,8 +11,8 @@ Serial port library written in C++ @@ -11,8 +11,8 @@ Serial port library written in C++
11 11
12 - Author: gbmhunter <gbmhunter@gmail.com> (http://www.cladlab.com) 12 - Author: gbmhunter <gbmhunter@gmail.com> (http://www.cladlab.com)
13 - Created: 2014/01/07 13 - Created: 2014/01/07
14 -- Last Modified: 2014/05/15  
15 -- Version: v1.0.0.0 14 +- Last Modified: 2014/05/21
  15 +- Version: v1.0.1.0
16 - Company: CladLabs 16 - Company: CladLabs
17 - Project: Free Code Libraries 17 - Project: Free Code Libraries
18 - Language: C++ 18 - Language: C++
@@ -89,5 +89,6 @@ Changelog @@ -89,5 +89,6 @@ Changelog
89 ========= ========== =================================================================================================== 89 ========= ========== ===================================================================================================
90 Version Date Comment 90 Version Date Comment
91 ========= ========== =================================================================================================== 91 ========= ========== ===================================================================================================
92 -v1.0.0.0 2013/05/15 Initial commit. serial-port-cpp library has basic functions up and running. 92 +v1.0.1.0 2014/05/21 Added ability to enable/disable echo with 'SerialPort::EnableEcho()'.
  93 +v1.0.0.0 2014/05/15 Initial commit. serial-port-cpp library has basic functions up and running.
93 ========= ========== =================================================================================================== 94 ========= ========== ===================================================================================================
94 \ No newline at end of file 95 \ No newline at end of file
include/SerialPort.hpp
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 //! @file SerialPort.hpp 2 //! @file SerialPort.hpp
3 //! @author Geoffrey Hunter <gbmhunter@gmail.com> () 3 //! @author Geoffrey Hunter <gbmhunter@gmail.com> ()
4 //! @created 2014/01/07 4 //! @created 2014/01/07
5 -//! @last-modified 2014/05/14 5 +//! @last-modified 2014/05/21
6 //! @brief The main serial port class. 6 //! @brief The main serial port class.
7 //! @details 7 //! @details
8 //! See README.rst in repo root dir for more info. 8 //! See README.rst in repo root dir for more info.
@@ -51,6 +51,10 @@ namespace SerialPort @@ -51,6 +51,10 @@ namespace SerialPort
51 //! @param numOfCharToWait Minimum number of characters to wait for before returning. Set to 0 for non-blocking mode. 51 //! @param numOfCharToWait Minimum number of characters to wait for before returning. Set to 0 for non-blocking mode.
52 void SetNumCharsToWait(uint32_t numCharsToWait); 52 void SetNumCharsToWait(uint32_t numCharsToWait);
53 53
  54 + //! @brief Enables/disables echo.
  55 + //! param echoOn Pass in true to enable echo, false to disable echo.
  56 + void EnableEcho(bool echoOn);
  57 +
54 //! @brief Opens the COM port for use. 58 //! @brief Opens the COM port for use.
55 //! @throws {std::runtime_error} if filename has not been set. 59 //! @throws {std::runtime_error} if filename has not been set.
56 //! {std::system_error} if system open() operation fails. 60 //! {std::system_error} if system open() operation fails.
src/SerialPort.cpp
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 //! @file SerialPort.cpp 2 //! @file SerialPort.cpp
3 //! @author Geoffrey Hunter <gbmhunter@gmail.com> () 3 //! @author Geoffrey Hunter <gbmhunter@gmail.com> ()
4 //! @created 2014/01/07 4 //! @created 2014/01/07
5 -//! @last-modified 2014/05/15 5 +//! @last-modified 2014/05/21
6 //! @brief The main serial port class. 6 //! @brief The main serial port class.
7 //! @details 7 //! @details
8 //! See README.rst in repo root dir for more info. 8 //! See README.rst in repo root dir for more info.
@@ -118,6 +118,16 @@ namespace SerialPort @@ -118,6 +118,16 @@ namespace SerialPort
118 118
119 } 119 }
120 120
  121 + void SerialPort::EnableEcho(bool echoOn)
  122 + {
  123 + termios settings = this->GetTermios();
  124 + settings.c_lflag = echoOn
  125 + ? (settings.c_lflag | ECHO )
  126 + : (settings.c_lflag & ~(ECHO));
  127 + //tcsetattr( STDIN_FILENO, TCSANOW, &settings );
  128 + this->SetTermios(settings);
  129 + }
  130 +
121 void SerialPort::SetEverythingToCommonDefaults() 131 void SerialPort::SetEverythingToCommonDefaults()
122 { 132 {
123 this->sp->PrintDebug(SmartPrint::Ss() << "Configuring COM port \"" << this->filePath << "\"."); 133 this->sp->PrintDebug(SmartPrint::Ss() << "Configuring COM port \"" << this->filePath << "\".");