X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=b8e98ece9a5dce42ce5e6e774e689bd34abed5a0;hp=6b7645bc7c7ef92e876e74076e062f7f532171c0;hb=168bd8ac353d715257e7267dcf4eeb1aaef6365c;hpb=cc9a7898ee7afc32e03dbcc991ed7ba722ed8f1b diff --git a/pv/session.cpp b/pv/session.cpp index 6b7645bc..b8e98ece 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -161,7 +161,15 @@ void Session::set_device(shared_ptr device) signals_changed(); device_ = std::move(device); - device_->open(); + + try { + device_->open(); + } catch (const QString &e) { + device_.reset(); + device_selected(); + throw; + } + device_->session()->add_datafeed_callback([=] (shared_ptr device, shared_ptr packet) { data_feed_in(device, packet); @@ -195,10 +203,14 @@ Session::capture_state Session::get_capture_state() const void Session::start_capture(function error_handler) { + if (!device_) { + error_handler(tr("No active device set, can't start acquisition.")); + return; + } + stop_capture(); // Check that at least one channel is enabled - assert(device_); const shared_ptr sr_dev = device_->device(); if (sr_dev) { const auto channels = sr_dev->channels(); @@ -219,8 +231,7 @@ void Session::start_capture(function error_handler) // Begin the session sampling_thread_ = std::thread( - &Session::sample_thread_proc, this, device_, - error_handler); + &Session::sample_thread_proc, this, error_handler); } void Session::stop_capture() @@ -454,13 +465,12 @@ shared_ptr Session::signal_from_channel( return shared_ptr(); } -void Session::sample_thread_proc(shared_ptr device, - function error_handler) +void Session::sample_thread_proc(function error_handler) { - assert(device); assert(error_handler); - (void)device; + if (!device_) + return; cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE);