mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
Implemented connection timeout in C++
This commit is contained in:
parent
4295d65115
commit
9ee6829ebc
5 changed files with 19 additions and 18 deletions
|
@ -301,12 +301,7 @@ sub connect {
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
$self->set_status("Connection failed");
|
$self->set_status("Connection failed");
|
||||||
}
|
}
|
||||||
{
|
if ($self->sender->wait_connected) {
|
||||||
# set up a timeout
|
|
||||||
my $timestamp = time();
|
|
||||||
1 until $self->sender->is_connected || (time - $timestamp) >= CONNECTION_TIMEOUT;
|
|
||||||
}
|
|
||||||
if ($self->sender->is_connected) {
|
|
||||||
$self->set_status("Printer is online. You can now start printing from the queue on the right.");
|
$self->set_status("Printer is online. You can now start printing from the queue on the right.");
|
||||||
$self->status_timer->Start(STATUS_TIMER_INTERVAL, wxTIMER_CONTINUOUS);
|
$self->status_timer->Start(STATUS_TIMER_INTERVAL, wxTIMER_CONTINUOUS);
|
||||||
$self->temp_timer->Start(TEMP_TIMER_INTERVAL, wxTIMER_CONTINUOUS);
|
$self->temp_timer->Start(TEMP_TIMER_INTERVAL, wxTIMER_CONTINUOUS);
|
||||||
|
|
|
@ -1094,16 +1094,7 @@ sub build {
|
||||||
$self->{config}->serial_port,
|
$self->{config}->serial_port,
|
||||||
$self->{config}->serial_speed,
|
$self->{config}->serial_speed,
|
||||||
);
|
);
|
||||||
if ($res) {
|
if ($res && $sender->wait_connected) {
|
||||||
{
|
|
||||||
# set up a timeout
|
|
||||||
my $timestamp = time();
|
|
||||||
my $CONNECTION_TIMEOUT = 3; # seconds
|
|
||||||
1 until $sender->is_connected || (time - $timestamp) >= $CONNECTION_TIMEOUT;
|
|
||||||
}
|
|
||||||
$res = $sender->is_connected;
|
|
||||||
}
|
|
||||||
if ($res) {
|
|
||||||
Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!");
|
Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!");
|
||||||
} else {
|
} else {
|
||||||
Slic3r::GUI::show_error($self, "Connection failed.");
|
Slic3r::GUI::show_error($self, "Connection failed.");
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
|
@ -134,6 +135,18 @@ GCodeSender::is_connected() const
|
||||||
return this->connected;
|
return this->connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
GCodeSender::wait_connected(unsigned int timeout) const
|
||||||
|
{
|
||||||
|
using namespace boost::posix_time;
|
||||||
|
ptime t0 = second_clock::local_time() + seconds(timeout);
|
||||||
|
while (!this->connected) {
|
||||||
|
if (second_clock::local_time() > t0) return false;
|
||||||
|
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
GCodeSender::queue_size() const
|
GCodeSender::queue_size() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@ class GCodeSender : private boost::noncopyable {
|
||||||
void disconnect();
|
void disconnect();
|
||||||
bool error_status() const;
|
bool error_status() const;
|
||||||
bool is_connected() const;
|
bool is_connected() const;
|
||||||
|
bool wait_connected(unsigned int timeout = 3) const;
|
||||||
size_t queue_size() const;
|
size_t queue_size() const;
|
||||||
void pause_queue();
|
void pause_queue();
|
||||||
void resume_queue();
|
void resume_queue();
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
|
|
||||||
bool connect(std::string port, unsigned int baud_rate);
|
bool connect(std::string port, unsigned int baud_rate);
|
||||||
void disconnect();
|
void disconnect();
|
||||||
bool is_connected() const;
|
bool is_connected();
|
||||||
int queue_size() const;
|
bool wait_connected(unsigned int timeout = 3);
|
||||||
|
int queue_size();
|
||||||
void send(std::string s, bool priority = false);
|
void send(std::string s, bool priority = false);
|
||||||
void pause_queue();
|
void pause_queue();
|
||||||
void resume_queue();
|
void resume_queue();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue