AVT相机arm版本SDK

This commit is contained in:
zhangpeng
2025-04-30 09:26:04 +08:00
parent 837c870f18
commit 78a1c63a95
705 changed files with 148770 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
PROJECT_NAME = UserSet
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/UserSet.o \
$(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,78 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: Exception.h
Description: Helper for exceptions.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_EXCEPTION
#define AVT_VMBAPI_EXAMPLES_EXCEPTION
#include "VimbaCPP/Include/VimbaCPP.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class Exception: public std::exception
{
private:
std::string m_sMsg;
// Vimba error code
VmbErrorType m_eError;
public:
Exception( const std::string &rsMessage, const VmbErrorType eError )
: m_eError(eError)
{
try
{
m_sMsg = rsMessage ;
}catch(...) {}
}
virtual ~Exception() throw()
{
}
VmbErrorType GetError() const
{
return m_eError;
}
std::string GetMessageStr() const
{
return m_sMsg;
}
// Translates Vimba error codes to readable error messages
static std::string ErrorCodeToMessage( VmbErrorType eErr )
{
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
}
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,299 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: UserSet.cpp
Description: The UserSet example will demonstrate how deal with the user sets
stored inside the cameras using VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <string>
#include <sstream>
#include <vector>
#include "UserSet.h"
#include "Exception.h"
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
CameraPtr UserSetCollection::m_pCamera;
std::vector<UserSetControl> UserSetCollection::m_usersets;
UserSetCollection::UserSetCollection( CameraPtr pCamera )
{
//Check parameters
if ( NULL == pCamera )
{
throw Exception( "UserSetCollection failed.", VmbErrorBadParameter );
}
m_pCamera = pCamera;
VmbErrorType err = VmbErrorSuccess;
VmbInt64_t nCount;
err = GetCount ( nCount );
if ( VmbErrorSuccess == err )
{
m_usersets.reserve( (size_t)nCount );
}
if ( VmbErrorSuccess == err )
{
for ( int i = 0; i < nCount; i++ )
{
AVT::VmbAPI::Examples::UserSetControl control( m_pCamera, i ) ;
m_usersets.push_back( control );
}
}
if ( VmbErrorSuccess != err )
{
throw Exception( "UserSetCollection failed.", err );
}
}
//Get user set count
VmbErrorType UserSetCollection::GetCount ( VmbInt64_t& rCount )
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
AVT::VmbAPI::StringVector selector;
err = m_pCamera->GetFeatureByName ( "UserSetSelector", pFeature );
if ( VmbErrorSuccess == err )
{
err = pFeature->GetValues ( selector );
rCount = selector.size();
}
return err;
}
//Get user set control
VmbErrorType UserSetCollection::GetControl ( VmbInt64_t nIndex, UserSetControl& rUserSet )
{
VmbErrorType err = VmbErrorSuccess;
VmbInt64_t nCount;
err = GetCount ( nCount );
if ( VmbErrorSuccess == err )
{
if ( nIndex >= nCount )
{
err = VmbErrorBadParameter;
}
FeaturePtr pFeature;
//Access to user set changes the selector
if ( VmbErrorSuccess == err )
{
err = m_pCamera->GetFeatureByName( "UserSetSelector", pFeature );
}
if(VmbErrorSuccess == err)
{
err = pFeature->SetValue( nIndex );
}
if(VmbErrorSuccess == err)
{
rUserSet = m_usersets[ (size_t)nIndex ];
}
}
return err;
}
//Get selected user set index
VmbErrorType UserSetCollection::GetSelectedIndex ( VmbInt64_t& rIndex )
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName ( "UserSetSelector", pFeature );
if ( VmbErrorSuccess == err )
{
err = pFeature->GetValue ( rIndex );
}
return err;
}
//Get default user set index
VmbErrorType UserSetCollection::GetDefaultIndex ( VmbInt64_t& rDefaultIndex )
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName ( "UserSetDefaultSelector", pFeature );
if ( VmbErrorSuccess == err )
{
err = pFeature->GetValue ( rDefaultIndex );
}
return err;
}
UserSetControl::UserSetControl( CameraPtr pCamera, VmbInt64_t nIndex )
{
//Check parameters
if ( NULL == pCamera )
{
throw Exception( "UserSetControl failed.", VmbErrorBadParameter );
}
m_pCamera = pCamera;
m_nIndex = nIndex;
}
//Is user set default
VmbErrorType UserSetControl::IsDefault ( bool& bIsDefault )
{
bIsDefault = false;
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName( "UserSetDefaultSelector", pFeature );
VmbInt64_t nDefaultIndex;
if(VmbErrorSuccess == err)
{
err = pFeature->GetValue( nDefaultIndex );
}
if(VmbErrorSuccess == err)
{
if ( nDefaultIndex == m_nIndex )
{
bIsDefault = true;
}
}
return err;
}
//Make user set default
VmbErrorType UserSetControl::MakeDefault ()
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName( "UserSetDefaultSelector", pFeature );
if ( VmbErrorNotFound == err )
{
err = m_pCamera->GetFeatureByName ( "UserSetMakeDefault", pFeature );
if(VmbErrorSuccess == err)
{
err = pFeature->RunCommand();
}
}
else if(VmbErrorSuccess == err)
{
err = pFeature->SetValue( m_nIndex );
}
return err;
}
//Save user set to flash
VmbErrorType UserSetControl::SaveToFlash ()
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName( "UserSetSave", pFeature );
if(VmbErrorSuccess == err)
{
err = pFeature->RunCommand();
}
return err;
}
//Load user set from flash
VmbErrorType UserSetControl::LoadFromFlash ()
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName( "UserSetLoad", pFeature );
if(VmbErrorSuccess == err)
{
err = pFeature->RunCommand();
}
return err;
}
//Get user set operation result
VmbErrorType UserSetControl::GetOperationResult( VmbInt64_t& nResult )
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName( "UserSetOperationResult", pFeature );
if(VmbErrorSuccess == err)
{
err = pFeature->GetValue( nResult );
}
return err;
}
//Get user set operation status
VmbErrorType UserSetControl::GetOperationStatus( VmbInt64_t& nStatus )
{
VmbErrorType err = VmbErrorSuccess;
FeaturePtr pFeature;
err = m_pCamera->GetFeatureByName( "UserSetOperationStatus", pFeature );
if(VmbErrorSuccess == err)
{
err = pFeature->GetValue( nStatus );
}
return err;
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,95 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: UserSet.h
Description: The UserSet example will demonstrate how deal with the user sets
stored inside the cameras.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_USERSET
#define AVT_VMBAPI_EXAMPLES_USERSET
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class UserSetControl
{
private:
CameraPtr m_pCamera;
VmbInt64_t m_nIndex;
public:
//ctor
UserSetControl( CameraPtr pCamera, VmbInt64_t nIndex );
//Is user set default
VmbErrorType IsDefault ( bool& bIsDefault );
//Make user set default
VmbErrorType MakeDefault ();
//Save current camera settings to user set
VmbErrorType SaveToFlash ();
//Load settings from user set into the camera
VmbErrorType LoadFromFlash ();
//Get operation result
VmbErrorType GetOperationResult( VmbInt64_t& nResult );
//Get operation status
VmbErrorType GetOperationStatus( VmbInt64_t& nStatus );
};
class UserSetCollection
{
private:
static CameraPtr m_pCamera;
static std::vector<UserSetControl> m_usersets;
public:
//ctor
UserSetCollection( CameraPtr pCamera );
//Get count
static VmbErrorType GetCount ( VmbInt64_t& nCount );
//Get control
static VmbErrorType GetControl ( VmbInt64_t nIndex, UserSetControl& control );
//Get selected index
static VmbErrorType GetSelectedIndex ( VmbInt64_t& nIndex );
//Get default index
static VmbErrorType GetDefaultIndex ( VmbInt64_t& nDefaultIndex );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,518 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of UserSet example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "UserSet.h"
#include "Exception.h"
#include "Common/StreamSystemInfo.h"
enum Mode
{
ModeUnknown = 0,
ModeSave = 1,
ModeLoad = 2,
ModeCount = 3,
ModeIndex = 4,
ModeMakeDefault = 5,
ModeIsDefault = 6,
ModeOperationResult = 7,
ModeOperationStatus = 8,
};
bool StartsWith( const char *pString, const char *pStart )
{
if( NULL == pString )
{
return false;
}
if( NULL == pStart )
{
return false;
}
if( std::strlen(pString) < std::strlen(pStart) )
{
return false;
}
if( std::memcmp(pString, pStart, std::strlen(pStart)) != 0 )
{
return false;
}
return true;
}
int main( int argc, char* argv[] )
{
std::cout << "//////////////////////////////////" << std::endl;
std::cout << "/// Vimba API User Set Example ///" << std::endl;
std::cout << "//////////////////////////////////" << std::endl << std::endl;
VmbErrorType err = VmbErrorSuccess;
std::string cameraID;
std::string controlIndex;
Mode eMode = ModeUnknown;
bool printHelp = false;
//////////////////////
//Parse command line//
//////////////////////
for(int i = 1; i < argc; i++)
{
char *pParameter = argv[i];
if( std::strlen( pParameter ) < 0 )
{
err = VmbErrorBadParameter;
break;
}
if( pParameter[0] == '/' )
{
if( std::strcmp( pParameter, "/s" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeSave;
}
else if( std::strcmp( pParameter, "/l" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeLoad;
}
else if( std::strcmp( pParameter, "/n" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeCount;
}
else if( std::strcmp( pParameter, "/i" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeIndex;
}
else if( StartsWith( pParameter, "/i:" ))
{
if( controlIndex.empty() == false )
{
err = VmbErrorBadParameter;
break;
}
controlIndex = pParameter + 3;
if( controlIndex.size() <= 0 )
{
err = VmbErrorBadParameter;
break;
}
}
else if( std::strcmp( pParameter, "/m" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeMakeDefault;
}
else if( std::strcmp( pParameter, "/d" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeIsDefault;
}
else if( std::strcmp( pParameter, "/or" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeOperationResult;
}
else if( std::strcmp( pParameter, "/os" ) == 0 )
{
if( ModeUnknown != eMode )
{
err = VmbErrorBadParameter;
break;
}
eMode = ModeOperationStatus;
}
else if( std::strcmp( pParameter, "/h" ) == 0 )
{
if( (cameraID.empty() == false)
|| (ModeUnknown != eMode)
|| (true == printHelp))
{
err = VmbErrorBadParameter;
break;
}
printHelp = true;
}
else
{
err = VmbErrorBadParameter;
break;
}
}
else
{
if( cameraID.empty() == false )
{
err = VmbErrorBadParameter;
break;
}
cameraID = pParameter;
}
}
//Write out an error if we could not parse the command line
if( VmbErrorBadParameter == err )
{
std::cout << "Invalid parameters!\n\n";
printHelp = true;
}
//Print out help and end program
if( true == printHelp )
{
std::cout << "Usage: UserSet [CameraID] [/i:Index] [/h] [/{s|l|i|m|d|or|os|n}]\n";
std::cout << "Parameters: CameraID ID of the camera to use\n";
std::cout << " (using first camera if not specified)\n";
std::cout << " /i:Index Set user set index\n";
std::cout << " /h Print out help\n";
std::cout << " /s Save user set to flash\n";
std::cout << " /l Load user set from flash\n";
std::cout << " (default if not specified)\n";
std::cout << " /i Get selected user set index\n";
std::cout << " /m Make user set default\n";
std::cout << " /d Is user set default\n";
std::cout << " /or Get user set operation result\n";
std::cout << " /os Get user set operation status\n";
std::cout << " /n Get user set count\n\n";
std::cout << "For example to load user set 0 (factory set) from flash in order to\nactivate it call\n";
std::cout << "UserSet /i:0 /l\n\n" ;
std::cout << "To save the current settings to user set 1 call\n";
std::cout << "UserSet /i:1 /s\n\n";
return err;
}
bool bVimbaStarted = false;
AVT::VmbAPI::CameraPtr pCamera;
AVT::VmbAPI::VimbaSystem * pVimbaSystem = NULL;
try
{
// Get a pointer to the VimbaSystem singleton
pVimbaSystem = &AVT::VmbAPI::VimbaSystem::GetInstance();
// Print out version of Vimba
std::cout<<"Vimba C++ API Version "<<*pVimbaSystem<<"\n";
//Startup API
if( VmbErrorSuccess == err )
{
err = pVimbaSystem->Startup();
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not start system.", err );
}
bVimbaStarted = true;
}
//Open camera
if( VmbErrorSuccess == err )
{
if( cameraID.empty() )
{
//Open first available camera
//Fetch all cameras known to Vimba
AVT::VmbAPI::CameraPtrVector cameras;
err = pVimbaSystem->GetCameras(cameras);
if( VmbErrorSuccess == err )
{
if( cameras.size() > 0 )
{
for ( AVT::VmbAPI::CameraPtrVector::const_iterator iter = cameras.begin();
cameras.end() != iter;
++iter )
{
//Check if we can open the camera in full mode
VmbAccessModeType eAccessMode = VmbAccessModeNone;
err = (*iter)->GetPermittedAccess( eAccessMode );
if( VmbErrorSuccess == err )
{
if( (VmbAccessModeFull == (VmbAccessModeFull & eAccessMode)) ||
((cameras.end() - 1) == iter) )
{
//Now get the camera ID
err = (*iter)->GetID(cameraID);
if(VmbErrorSuccess == err)
{
//Try to open the camera
err = (*iter)->Open(VmbAccessModeFull);
if(VmbErrorSuccess == err)
{
pCamera = *iter;
break;
}
}
}
}
}
if( VmbErrorSuccess != err )
{
err = VmbErrorNotFound;
throw AVT::VmbAPI::Examples::Exception("Could not open any camera.", err);
}
}
else
{
err = VmbErrorNotFound;
throw AVT::VmbAPI::Examples::Exception("Could not open any camera.", err);
}
}
else
{
throw AVT::VmbAPI::Examples::Exception("Could not list cameras.", err);
}
}
else
{
//Open specific camera
err = pVimbaSystem->OpenCameraByID(cameraID.c_str(), VmbAccessModeFull, pCamera);
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception("Could not open camera.", err);
}
}
}
if( VmbErrorSuccess == err )
{
std::cout << "Camera ID: " << cameraID << std::endl << std::endl;
AVT::VmbAPI::Examples::UserSetCollection collection( pCamera );
VmbInt64_t nIndex;
if ( controlIndex.empty() == false )
{
nIndex = atoi( controlIndex.c_str() );
}
else
{
err = collection.GetSelectedIndex( nIndex );
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not get selected user set index.", err );
}
}
AVT::VmbAPI::Examples::UserSetControl control( pCamera, nIndex );
if ( (ModeCount != eMode) && (ModeIndex != eMode) )
{
err = collection.GetControl( nIndex, control );
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not get user set control.", err );
}
}
switch( eMode )
{
default:
case ModeLoad:
{
//Load user set
err = control.LoadFromFlash();
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not load user set from flash.", err );
}
std::cout << "User set successfully loaded from flash." << std::endl;
}
break;
case ModeSave:
{
//Save user set
err = control.SaveToFlash();
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not save user set to flash.", err );
}
std::cout << "User set successfully saved to flash." << std::endl;
}
break;
case ModeCount:
{
//Get user set count
VmbInt64_t nCount;
err = collection.GetCount( nCount );
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not get user set count.", err );
}
std::cout << "Get user set count was successful. Count = " << nCount << std::endl;
}
break;
case ModeIndex:
{
//Get selected user set index
VmbInt64_t nSelectedIndex;
err = collection.GetSelectedIndex( nSelectedIndex );
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not get user set index.", err );
}
std::cout << "Get selected user set was successful. Index = " << nSelectedIndex << std::endl;
}
break;
case ModeMakeDefault:
{
err = control.MakeDefault();
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not set user set default.", err );
}
std::cout << "Make user set default was successful. " << std::endl;
}
break;
case ModeIsDefault:
{
bool bIsDefault = false;
if( VmbErrorSuccess == err )
{
err = control.IsDefault( bIsDefault );
}
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not get user set default.", err );
}
std::cout << "Is user set default was successful. Result = " << bIsDefault << std::endl;
}
break;
case ModeOperationResult:
{
VmbInt64_t nResult;
err = control.GetOperationResult( nResult );
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not get user set opration result.", err );
}
std::cout << "Get user set operation result was successful. Operation Result = " << nResult << std::endl;
}
break;
case ModeOperationStatus:
{
VmbInt64_t nStatus;
err = control.GetOperationStatus( nStatus );
if( VmbErrorSuccess != err )
{
throw AVT::VmbAPI::Examples::Exception( "Could not get user set operation status.", err );
}
std::cout << "Get user set operation status was successful. Operation Status = " << nStatus << std::endl;
}
break;
}
}
}
catch( AVT::VmbAPI::Examples::Exception& ex )
{
std::cout << ex.GetMessageStr() << " VimbaException: " << ex.GetError() << " = " << ex.ErrorCodeToMessage( ex.GetError() ) << std::endl;
}
//Close camera
if( NULL != pCamera )
{
pCamera->Close();
}
//Shutdown API
if(true == bVimbaStarted)
{
pVimbaSystem->Shutdown();
}
return err;
}