mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-19 04:37:52 -06:00
Initial work for G-code sender and more intensive usage of Boost
This commit is contained in:
parent
43cbad8867
commit
11dd67ab34
1649 changed files with 1860 additions and 1642 deletions
78
xs/src/libslic3r/GCodeSender.cpp
Normal file
78
xs/src/libslic3r/GCodeSender.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifdef BOOST_LIBS
|
||||
#include "GCodeSender.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
GCodeSender::GCodeSender(std::string devname, unsigned int baud_rate)
|
||||
: io(), serial(io)
|
||||
{
|
||||
this->serial.open(devname);
|
||||
this->serial.set_option(asio::serial_port_base::baud_rate(baud_rate));
|
||||
this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::odd));
|
||||
this->serial.set_option(asio::serial_port_base::character_size(asio::serial_port_base::character_size(8)));
|
||||
this->serial.set_option(asio::serial_port_base::flow_control(asio::serial_port_base::flow_control::none));
|
||||
this->serial.set_option(asio::serial_port_base::stop_bits(asio::serial_port_base::stop_bits::one));
|
||||
this->serial.close();
|
||||
this->serial.open(devname);
|
||||
this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::none));
|
||||
|
||||
std::string greeting;
|
||||
this->read_line(&greeting);
|
||||
}
|
||||
|
||||
void
|
||||
GCodeSender::send(const std::vector<std::string> &lines)
|
||||
{
|
||||
this->lines = lines;
|
||||
}
|
||||
|
||||
void
|
||||
GCodeSender::send(const std::string &s)
|
||||
{
|
||||
{
|
||||
std::stringstream ss(s);
|
||||
std::string line;
|
||||
while (std::getline(ss, line, '\n'))
|
||||
this->lines.push_back(line);
|
||||
}
|
||||
|
||||
for (std::vector<std::string>::const_iterator line = this->lines.begin(); line != this->lines.end(); ++line) {
|
||||
this->send_line(*line);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GCodeSender::send_line(const std::string &line)
|
||||
{
|
||||
asio::streambuf b;
|
||||
std::ostream os(&b);
|
||||
os << line << "\n";
|
||||
asio::write(this->serial, b);
|
||||
}
|
||||
|
||||
void
|
||||
GCodeSender::read_line(std::string* line)
|
||||
{
|
||||
for (;;) {
|
||||
char c;
|
||||
asio::read(this->serial, asio::buffer(&c, 1));
|
||||
switch (c) {
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
return;
|
||||
default:
|
||||
*line += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(GCodeSender, "GCode::Sender");
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue