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 = BandwidthHelper
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)/BandwidthHelper.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,495 @@
/*=============================================================================
Copyright (C) 2012 - 2016 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: BandwidthHelper.cpp
Description: The BandwidthHelper example demonstrates how to get and set the
bandwidth used by a camera 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 <stdlib.h>
#include <string.h>
#include "BandwidthHelper.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
#define PACKET_SIZE_MAX_1394_S100 1024
#define PACKET_SIZE_MAX_1394_S200 2048
#define PACKET_SIZE_MAX_1394_S400 4096
#define PACKET_SIZE_MAX_1394_S800 8192
//
// Calculates the current bandwidth usage of a camera in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] rfBandwidth The current bandwidth usage (maximum 1)
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::GetBandwidthUsage( CameraPtr pCamera, double &rfBandwidth )
{
VmbErrorType res;
VmbInt64_t nValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem & system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch( interfaceType )
{
case VmbInterfaceEthernet:
res = pCamera->GetFeatureByName( "StreamBytesPerSecond", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetValue( nValue );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nValue / nMax;
}
}
}
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetValue( nValue );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
rfBandwidth = (double)nValue / (double)nPhySpeed;
}
}
}
}
break;
case VmbInterfaceUsb:
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimitMode", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strMode;
res = pFeature->GetValue( strMode );
if ( VmbErrorSuccess == res )
{
// If link speed limit is disabled, the used bandwidth can be up to 100%
if ( !strcmp( "Off", strMode.c_str() ))
{
rfBandwidth = 1.0;
}
else
{
// If link speed limit is enabled, get its current value
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimit", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetValue( nValue );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nValue / nMax;
}
}
}
}
}
}
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// Sets the current bandwidth usage in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] fBandwidth The bandwidth to be set (maximum 1)
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::SetBandwidthUsage( CameraPtr pCamera, double fBandwidth )
{
VmbErrorType res;
VmbInt64_t nValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem& system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch( interfaceType )
{
case VmbInterfaceEthernet:
res = pCamera->GetFeatureByName( "StreamBytesPerSecond", pFeature );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
nValue = (VmbUint64_t)(fBandwidth * nMax);
res = pFeature->SetValue( nValue );
}
}
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSizeAuto", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->SetValue( "Off" );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
// Set size to new percentage
nValue = (VmbUint64_t)(fBandwidth * nPhySpeed);
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
// Adjust new value to fit increment
VmbInt64_t nInc;
res = pFeature->GetIncrement( nInc );
if ( VmbErrorSuccess == res )
{
nValue -= (nValue % nInc);
// Write new value
res = pFeature->SetValue( nValue );
}
}
}
}
}
}
break;
case VmbInterfaceUsb:
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimitMode", pFeature );
if ( VmbErrorSuccess == res )
{
// Enable link speed limit
res = pFeature->SetValue( "On" );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimit", pFeature );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
nValue = (VmbUint64_t)(fBandwidth * nMax);
// Set link speed limit
res = pFeature->SetValue( nValue );
}
}
}
}
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// The relative minimum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of minimum and maximum of either stream bytes per second or the packet size
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::GetMinPossibleBandwidthUsage( CameraPtr pCamera, double &rfBandwidth )
{
VmbErrorType res;
VmbInt64_t nMinValue;
VmbInt64_t nMaxValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem & system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch( interfaceType )
{
case VmbInterfaceEthernet:
res = pCamera->GetFeatureByName( "StreamBytesPerSecond", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nMinValue / nMaxValue;
}
}
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
rfBandwidth = (double)nMinValue / (double)nPhySpeed;
}
}
}
}
break;
case VmbInterfaceUsb:
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimit", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nMinValue / nMaxValue;
}
}
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// The relative maximum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of maximum packet size as reported by the device and the maximum of the bus (for technologies other than fire wire always 1)
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::GetMaxPossibleBandwidthUsage( CameraPtr pCamera, double &rfBandwidth )
{
VmbErrorType res;
VmbInt64_t nMinValue;
VmbInt64_t nMaxValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem & system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch ( interfaceType )
{
case VmbInterfaceEthernet:
rfBandwidth = 1.0;
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
rfBandwidth = (double)nMaxValue / (double)nPhySpeed;
}
}
}
}
break;
case VmbInterfaceUsb:
rfBandwidth = 1.0;
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// Converts the interface type enum to a string representation
//
// Parameters:
// [in] interfaceType The interface enum to convert
//
// Returns:
// The string representation of the given enum
//
std::string BandwidthHelper::InterfaceToString( VmbInterfaceType interfaceType )
{
switch ( interfaceType )
{
case VmbInterfaceFirewire: return "FireWire";
case VmbInterfaceEthernet: return "GigE";
case VmbInterfaceUsb: return "USB";
default: return "Unknown";
}
}
}}} // AVT:VmbAPI::Examples

View File

@@ -0,0 +1,107 @@
/*=============================================================================
Copyright (C) 2012 - 2016 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: BandwidthHelper.h
Description: The BandwidthHelper example demonstrates how to get and set the
bandwidth used by a camera 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.
=============================================================================*/
#ifndef AVT_VMBAPI_HELPER_BANDWIDTHHELPER_H
#define AVT_VMBAPI_HELPER_BANDWIDTHHELPER_H
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class BandwidthHelper
{
public:
//
// Calculates the current bandwidth usage of a camera in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] rfBandwidth The current bandwidth usage (maximum 1)
//
// Returns:
// An API status code
//
static VmbErrorType GetBandwidthUsage( CameraPtr pCamera, double &bandwidth );
//
// Sets the current bandwidth usage in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] fBandwidth The bandwidth to be set (maximum 1)
//
// Returns:
// An API status code
//
static VmbErrorType SetBandwidthUsage( CameraPtr pCamera, double bandwidth );
//
// The relative minimum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of minimum and maximum of either stream bytes per second or the packet size
//
// Returns:
// An API status code
//
static VmbErrorType GetMinPossibleBandwidthUsage( CameraPtr pCamera, double &bandwidth );
//
// The relative maximum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of maximum packet size as reported by the device and the maximum of the bus (for technologies other than fire wire always 1)
//
// Returns:
// An API status code
//
static VmbErrorType GetMaxPossibleBandwidthUsage( CameraPtr pCamera, double &bandwidth );
//
// Converts the interface type enum to a string representation
//
// Parameters:
// [in] interfaceType The interface enum to convert
//
// Returns:
// The string representation of the given enum
//
static std::string InterfaceToString( VmbInterfaceType interfaceType );
private:
// No default ctor
BandwidthHelper();
};
}}} // AVT:VmbAPI::Examples
#endif

View File

@@ -0,0 +1,402 @@
/*=============================================================================
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 BandwidthHelper 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 <map>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include "BandwidthHelper.h"
#include "Common/StreamSystemInfo.h"
enum SettingsMode
{
SettingsModeUnknown = 0,
SettingsModeGet = 1,
SettingsModeSet = 2,
SettingsModeGetMin = 3,
SettingsModeGetMax = 4
};
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::string cameraID, cameraName;
VmbInterfaceType cameraInterfaceType;
double fValue;
SettingsMode settingsMode = SettingsModeUnknown;
bool printHelp = false;
std::cout << "\n";
std::cout << "//////////////////////////////////////////\n";
std::cout << "/// Vimba API Bandwidth Helper Example ///\n";
std::cout << "//////////////////////////////////////////\n";
std::cout << std::endl;
VmbErrorType err = VmbErrorSuccess;
//////////////////////
//Parse command line//
//////////////////////
if( 4 < argc )
{
err = VmbErrorBadParameter;
printHelp = true;
}
else
{
for( int i=1; i<argc; ++i )
{
char *pParameter = argv[i];
if( 0 >= std::strlen( pParameter ) )
{
err = VmbErrorBadParameter;
break;
}
if( pParameter[0] == '/' )
{
// Get bandwidth usage
if( 0 == std::strcmp( pParameter, "/g" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeGet;
}
// Set bandwidth usage
else if( true == StartsWith( pParameter, "/s:" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeSet;
std::string strVal = pParameter + 3;
if( 0 >= strVal.size() )
{
err = VmbErrorBadParameter;
break;
}
fValue = atof( strVal.c_str() ) / 100;
}
else if( 0 == std::strcmp( pParameter, "/h" ) )
{
if( true == printHelp )
{
err = VmbErrorBadParameter;
break;
}
printHelp = true;
}
// Get min bandwidth usage
else if( 0 == std::strcmp( pParameter, "/min" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeGetMin;
}
// Get max bandwidth usage
else if( 0 == std::strcmp( pParameter, "/max" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeGetMax;
}
else
{
err = VmbErrorBadParameter;
break;
}
}
else
{
if( false == cameraID.empty() )
{
err = VmbErrorBadParameter;
break;
}
cameraID = pParameter;
}
}
}
// Write out an error if we could not parse the command line
if( VmbErrorBadParameter == err )
{
std::cout << "Invalid parameter found.\n\n";
printHelp = true;
}
// Print out help
if( true == printHelp )
{
std::cout << "Gets or sets the current bandwidth as percentage of the theoretically possible bandwidth.\n\n";
std::cout << "Usage: BandwidthHelper [CameraID] [/h] [/{g|s:val|min|max}]\n";
std::cout << "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
std::cout << " /h Print out help\n";
std::cout << " /g Get bandwidth usage (default if not specified)\n";
std::cout << " /s:val Set bandwidth usage to <val> % of the maximum bandwidth\n";
std::cout << " /min Get minimal possible bandwidth usage\n";
std::cout << " /max Get maximal possible bandwidth usage\n\n";
return err;
}
if( VmbErrorSuccess == err )
{
// Get a reference to the VimbaSystem singleton
AVT::VmbAPI::VimbaSystem &rVimbaSystem = AVT::VmbAPI::VimbaSystem::GetInstance();
// Print out version of Vimba
std::cout << "Vimba C++ API Version " << rVimbaSystem << "\n";
// Startup API
err = rVimbaSystem.Startup();
if( VmbErrorSuccess != err )
{
std::cout << "Could not start system. Error code: " << err <<"\n";
}
else
{
AVT::VmbAPI::CameraPtr pCamera;
// Open first available camera
if( cameraID.empty() )
{
// Fetch all cameras known to Vimba
AVT::VmbAPI::CameraPtrVector cameras;
err = rVimbaSystem.GetCameras( cameras );
if( VmbErrorSuccess == err )
{
if( !cameras.empty() )
{
for( AVT::VmbAPI::CameraPtrVector::const_iterator iter = cameras.begin();
cameras.end() != iter;
++iter )
{
// Check if we can open the camera in full mode
VmbAccessModeType accessMode = VmbAccessModeNone;
err = (*iter)->GetPermittedAccess( accessMode );
if( VmbErrorSuccess == err )
{
if( VmbAccessModeFull & accessMode )
{
// 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;
// Get camera name and interface type
if( VmbErrorSuccess == pCamera->GetName( cameraName )
&& VmbErrorSuccess == pCamera->GetInterfaceType( cameraInterfaceType ) )
{
std::cout << "Successfully opened " << AVT::VmbAPI::Examples::BandwidthHelper::InterfaceToString( cameraInterfaceType ) << " camera " << cameraName << " (" << cameraID << ")\n" ;
}
else
{
std::cout << "Successfully opened camera " << "(" << cameraID << ")\n";
}
break;
}
}
}
}
}
if( NULL == pCamera )
{
std::cout << "Could not open any camera.\n";
err = VmbErrorNotFound;
}
}
else
{
std::cout << "No camera available.\n";
err = VmbErrorNotFound;
}
}
else
{
std::cout << "Could not list cameras. Error code: " << err << std::endl;
}
}
else
{
// Open specific camera
err = rVimbaSystem.OpenCameraByID( cameraID.c_str(), VmbAccessModeFull, pCamera );
if( VmbErrorSuccess != err )
{
std::cout << "Could not open camera. Error code: " << err <<"\n";
}
}
if( VmbErrorSuccess == err )
{
switch( settingsMode )
{
default:
case SettingsModeGet:
{
// Get bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::GetBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else if ( VmbErrorSuccess != err )
{
std::cout << "Could not get bandwidth usage. Error code: " << err <<"\n";
}
else
{
std::cout << "Bandwidth usage: " << fValue * 100 << "%\n";
}
}
break;
case SettingsModeSet:
{
// Set bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::SetBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else
{
if ( VmbErrorSuccess == err )
{
// Read back written value
err = AVT::VmbAPI::Examples::BandwidthHelper::GetBandwidthUsage( pCamera, fValue );
if ( VmbErrorSuccess == err )
{
std::cout << "Bandwidth usage successfully set to: " << fValue * 100 << "%\n";
}
}
if ( VmbErrorSuccess != err )
{
std::cout << "Could not set bandwidth usage. Error code: " << err <<"\n";
}
}
}
break;
case SettingsModeGetMin:
{
// Get bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::GetMinPossibleBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else if( VmbErrorSuccess != err )
{
std::cout << "Could not get minimal possible bandwidth usage. Error code: " << err <<"\n";
}
else
{
std::cout << "Minimal possible bandwidth usage: " << fValue * 100 << "%\n";
}
}
break;
case SettingsModeGetMax:
{
// Get bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::GetMaxPossibleBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else if ( VmbErrorSuccess != err )
{
std::cout << "Could not get maximal possible bandwidth usage. Error code: " << err <<"\n";
}
else
{
std::cout << "Maximal possible bandwidth usage: " << fValue * 100 << "%\n";
}
}
break;
}
// Close camera
err = pCamera->Close();
}
// Shutdown API
rVimbaSystem.Shutdown();
}
return err;
}
}