From 9a45063077f27140367ccb749c8d794f60729526 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Mon, 18 Nov 2013 13:01:32 -0800 Subject: b2xx_fx3_utils: catch error when WinUSB drivers aren't installed --- host/utils/b2xx_fx3_utils.cpp | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'host/utils') diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp index d4e3b0f9a..391b45ab9 100644 --- a/host/utils/b2xx_fx3_utils.cpp +++ b/host/utils/b2xx_fx3_utils.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -178,8 +179,17 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { << boost::format("0x%X") % pid << std::endl; return -1; } - usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); - b200 = b200_iface::make(usb_ctrl); + try { + usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); + b200 = b200_iface::make(usb_ctrl); + } + catch(const std::exception &e) { + std::cerr << "Failed to communicate with device!" << std::endl; + #ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details." << std::endl; + #endif /* UHD_PLATFORM_WIN32 */ + return -1; + } if (!(handles[0]->firmware_loaded())) { @@ -226,8 +236,17 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { std::cerr << "Cannot find device" << std::endl; return -1; } - usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); - b200 = b200_iface::make(usb_ctrl); + try { + usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); + b200 = b200_iface::make(usb_ctrl); + } + catch(const std::exception &e) { + std::cerr << "Failed to communicate with device!" << std::endl; + #ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details." << std::endl; + #endif /* UHD_PLATFORM_WIN32 */ + return -1; + } if (!(handles[0]->firmware_loaded())) { @@ -307,8 +326,17 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { std::cout << "Initialized B2xx detected..." << std::flush; - usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); - b200 = b200_iface::make(usb_ctrl); + try { + usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); + b200 = b200_iface::make(usb_ctrl); + } + catch(const std::exception &e) { + std::cerr << "Failed to communicate with device!" << std::endl; + #ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details." << std::endl; + #endif /* UHD_PLATFORM_WIN32 */ + return -1; + } std::cout << " Control of B2xx granted..." << std::endl << std::endl; @@ -383,9 +411,18 @@ boost::int32_t main(boost::int32_t argc, char *argv[]) { std::cout << "Uninitialized B2xx detected..." << std::flush; - usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); - b200 = b200_iface::make(usb_ctrl); - + try { + usb_ctrl = uhd::transport::usb_control::make(handles[0], 0); + b200 = b200_iface::make(usb_ctrl); + } + catch(const std::exception &e) { + std::cerr << "Failed to communicate with device!" << std::endl; + #ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details." << std::endl; + #endif /* UHD_PLATFORM_WIN32 */ + return -1; + } + std::cout << " Control of B2xx granted..." << std::endl << std::endl; if (!(handles[0]->firmware_loaded())) -- cgit v1.2.3