Skip to content

Commit

Permalink
Dump serial messages to file in order to debug communication issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Dec 26, 2015
1 parent f5326c3 commit 83c91a3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions xs/src/libslic3r/GCodeSender.cpp
Expand Up @@ -19,6 +19,12 @@
#include <linux/serial.h>
#endif

//#define DEBUG_SERIAL
#ifdef DEBUG_SERIAL
#include <fstream>
std::fstream fs;
#endif

namespace Slic3r {

namespace asio = boost::asio;
Expand Down Expand Up @@ -61,6 +67,11 @@ GCodeSender::connect(std::string devname, unsigned int baud_rate)
this->open = true;
this->reset();

/* Initialize debugger */
#ifdef DEBUG_SERIAL
fs.open("serial.txt", std::fstream::out | std::fstream::trunc);
#endif

// this gives some work to the io_service before it is started
// (post() runs the supplied function in its thread)
this->io.post(boost::bind(&GCodeSender::do_read, this));
Expand Down Expand Up @@ -131,6 +142,10 @@ GCodeSender::disconnect()
"Error while closing the device"));
}
*/

#ifdef DEBUG_SERIAL
fs.close();
#endif
}

bool
Expand Down Expand Up @@ -285,6 +300,10 @@ GCodeSender::on_read(const boost::system::error_code& error,
std::string line;
std::getline(is, line);
if (!line.empty()) {
#ifdef DEBUG_SERIAL
fs << "<< " << line;
#endif

// note that line might contain \r at its end
// parse incoming line
if (!this->connected
Expand Down Expand Up @@ -440,6 +459,10 @@ GCodeSender::do_send(const std::string &line)

this->last_sent = line;
this->can_send = false;

#ifdef DEBUG_SERIAL
fs << ">> " << full_line;
#endif
}

void
Expand Down

0 comments on commit 83c91a3

Please sign in to comment.