This code:
void Controller::write(const std::string& str) {
std::cout << "Writing: [" << str << "] to board." << std::endl;
s.write(str);
takes a string and pushes it over a serial link to a microcontroller. (This works fine). However, when I try to push a like this: write("ats203?\r"), the console output looks like this:
] to board.ts203?
So the Writing: [a gets overwritten by the ] to board. after std::cout encounters the \r in the string.
How can I print the string as a bunch of characters rather than mangling console output when an escape character is encountered?
EDIT: To clarify.
I want my string to be ats203?\r. This is because the microcontroller is controlled using a slightly modified version of an AT command, and doesn’t accept the command until it reads a \r. When the string is pushed to the microcontroller, it reads the \r as a carriage return, and acts on things it read prior to the \r.
What I want is to display the string that I’ve constructed. There is a bunch of other commands elsewhere that get created depending on flags that are set at runtime. So I end up with strings that look something like ate1\ratv0\rat+OSA=7\rat+OSX=255\r.
I would like to see what I’ve constructed and what I’m pushing. I can’t do this, because std::cout reads the carriage return, acts on it, and mangles my console output.
EDIT: Clarification, again:
I want std::cout << "Writing: [" << str << "] to board." << std::endl; to produce (when str is ats203?\r):
Writing: [ats203?\r] to board.
So then
write("ats203?\r")will literally print out