diff --git a/src/mvbluefox3.cpp b/src/mvbluefox3.cpp index 736a58df70be8bde22ba1343c3e6c2ef884adf1f..d6cbfe5291791291fb555539c63d6340283a0854 100644 --- a/src/mvbluefox3.cpp +++ b/src/mvbluefox3.cpp @@ -18,22 +18,33 @@ namespace CMvbluefox3 { CMvbluefox3::CMvbluefox3(const std::string &serial) { - if (this->devMgr_.getDeviceBySerial(serial) == 0) - throw CmvBlueFOX3Exception(_HERE_, "No device found! Unable to continue. " + AvailableDevices()); + if( !serial.empty() ) + { + std::cout << "[mvBlueFOX3]: Trying to open device with serial: " << serial << std::endl; - // create an interface to the found device - this->device_ = this->devMgr_[0]; + if (this->devMgr_.getDeviceBySerial(serial) == 0) + { + throw CmvBlueFOX3Exception(_HERE_, "No device found! Unable to continue. " + AvailableDevices()); + } + else + { + // create an interface to the found device + this->device_ = this->devMgr_[0]; - // Initialize other vars - this->timeout_ms_ = -1; - this->depth_ = 8; - this->bytes_per_pixel_ = 1; + // Initialize other vars + this->timeout_ms_ = -1; + this->depth_ = 8; + this->bytes_per_pixel_ = 1; -// displayPropertyData(this->device_->defaultRequestCount); -// WriteProperty(this->device_->defaultRequestCount,1); + // displayPropertyData(this->device_->defaultRequestCount); + // WriteProperty(this->device_->defaultRequestCount,1); - // open device - OpenDevice(serial); + // open device + OpenDevice(serial); + } + } + else + throw CmvBlueFOX3Exception(_HERE_, "Device cannot be found because serial number is not specified."); } CMvbluefox3::~CMvbluefox3() @@ -57,16 +68,23 @@ CMvbluefox3::~CMvbluefox3() std::string CMvbluefox3::AvailableDevices(SUPPORTED_DEVICE_CHECK pSupportedDeviceCheckFn) const { std::ostringstream devices; - devices << "[mvBlueFOX3]: Available device(s): \n"; + devices << "Available device(s): "; const unsigned int devCnt = this->devMgr_.deviceCount(); - for( unsigned int i = 0; i < devCnt; i++ ) + if (devCnt == 0) + { + devices << "0."; + } + else { - Device* pDev = this->devMgr_[i]; - if( pDev ) + for( unsigned int i = 0; i < devCnt; i++ ) { - if( !pSupportedDeviceCheckFn || pSupportedDeviceCheckFn( pDev ) ) + Device* pDev = this->devMgr_[i]; + if( pDev ) { - devices << " - " << pDev->product.read() << ": " << pDev->serial.read(); + if( !pSupportedDeviceCheckFn || pSupportedDeviceCheckFn( pDev ) ) + { + devices << " \n - " << pDev->product.read() << ": " << pDev->serial.read(); + } } } }