From b2cad02490ec7d9725712d33577355e53e55a6aa Mon Sep 17 00:00:00 2001
From: asantamaria <asantamaria@iri.upc.edu>
Date: Tue, 13 Dec 2016 10:12:35 +0100
Subject: [PATCH] minor modifications. after verif. with ros and opencv

---
 src/mvbluefox3.cpp | 54 ++++++++++++++++++++++++++++++----------------
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/mvbluefox3.cpp b/src/mvbluefox3.cpp
index 736a58d..d6cbfe5 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();
+        }
       }
     }
   }
-- 
GitLab