Put everything into try {} catch {} in GCodeSender::connect

This commit is contained in:
Alessandro Ranellucci 2017-03-09 20:51:43 +01:00
parent afacf0c99d
commit f1f1444637

View File

@ -46,14 +46,9 @@ bool
GCodeSender::connect(std::string devname, unsigned int baud_rate) GCodeSender::connect(std::string devname, unsigned int baud_rate)
{ {
this->disconnect(); this->disconnect();
this->set_error_status(false); this->set_error_status(false);
try { try {
this->serial.open(devname); this->serial.open(devname);
} catch (boost::system::system_error &e) {
this->set_error_status(true);
return false;
}
this->serial.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::odd)); 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::character_size(asio::serial_port_base::character_size(8)));
@ -69,6 +64,11 @@ GCodeSender::connect(std::string devname, unsigned int baud_rate)
this->set_baud_rate(baud_rate); this->set_baud_rate(baud_rate);
this->open = true; this->open = true;
this->reset(); this->reset();
} catch (boost::system::system_error &e) {
printf("Caught error\n");
this->set_error_status(true);
return false;
}
// a reset firmware expect line numbers to start again from 1 // a reset firmware expect line numbers to start again from 1
this->sent = 0; this->sent = 0;