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,51 @@
PROJECT_NAME = ActionCommands
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 = -D_LITTLE_ENDIAN
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ActionCommands.o \
$(OBJ_DIR)/FrameObserver.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,985 @@
/*=============================================================================
Copyright (C) 2021 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: ActionCommands.cpp
Description: see header file for description
-------------------------------------------------------------------------------
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 <string.h>
#include <ActionCommands.h>
// socket library to check IP addresses
#ifdef _WIN32
#include <conio.h>
#include <WinSock.h>
#else
#include <arpa/inet.h>
#endif
// number of frame buffers to be used by example
#define NUM_FRAMES 3
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// Constructor
//
cActionCommands::cActionCommands()
: mSystem( VimbaSystem::GetInstance() )
, mFrameObserver( NULL )
, mSystemFlag( false )
, mInterfaceFlag( false )
, mCameraFlag( false )
, mStreamingFlag( false )
{
}
//
// Destructor
//
cActionCommands::~cActionCommands()
{
}
//
// Helper method to read feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [out] aType Feature data type
// [in/out] aValue Buffer for feature value
// [in/out] aSize Size of buffer
//
VmbErrorType cActionCommands::GetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType* aType, void* aValue, size_t* aSize )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( (NULL == aName) || (NULL == aValue) )
{
return VmbErrorBadParameter;
}
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
// get feature data type
VmbFeatureDataType lType = VmbFeatureDataUnknown;
lError = lFeature->GetDataType( lType );
if( (VmbErrorSuccess == lError) && (NULL != aType) )
{
*aType = lType;
}
// proceed in case of no error
if( VmbErrorSuccess == lError )
{
// set feature value
switch( lType )
{
case VmbFeatureDataInt:
{
// get value
VmbInt64_t lValue = 0;
lError = lFeature->GetValue( lValue );
if( VmbErrorSuccess == lError )
{
memcpy( aValue, &lValue, sizeof(VmbInt64_t) );
}
// set buffer size
if( NULL != aSize )
{
*aSize = sizeof(VmbInt64_t);
}
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
}
return lError;
}
//
// Helper method to write feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [in] aType Feature data type
// [in] aValue Buffer for feature value
// [in] aSize Size of buffer
//
VmbErrorType cActionCommands::SetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType aType, void* aValue, size_t aSize )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( (NULL == aName) || (NULL == aValue) )
{
return VmbErrorBadParameter;
}
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
// check feature data type
VmbFeatureDataType lType = VmbFeatureDataUnknown;
lFeature->GetDataType( lType );
if( lType != aType )
{
return VmbErrorBadParameter;
}
// proceed in case of no error
if( VmbErrorSuccess == lError )
{
// set feature value
switch( aType )
{
case VmbFeatureDataInt:
{
// check size
if( sizeof(VmbInt64_t) >= aSize )
{
// set value
VmbInt64_t lValue = (VmbInt64_t)aValue;
lError = lFeature->SetValue( lValue );
}
break;
}
case VmbFeatureDataEnum:
{
// set value
const char* lValue = (char*)aValue;
lError = lFeature->SetValue( lValue );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
}
return lError;
}
//
// Helper method to run a Command Feature
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
//
VmbErrorType cActionCommands::RunCommand( const char* aName, tFeatureOwner aOwner )
{
VmbErrorType lError = VmbErrorSuccess;
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
lError = VmbErrorBadParameter;
}
if( VmbErrorSuccess == lError )
{
lError = lFeature->RunCommand();
}
return lError;
}
//
// Called when any failure occurs within the example.
// Ensures to stop streaming, close interface, close camera and shutdown Vimba
//
void cActionCommands::FailureShutdown()
{
VmbErrorType lError = VmbErrorSuccess;
// stop streaming
if( true == this->mStreamingFlag )
{
lError = this->mCamera->StopContinuousImageAcquisition();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not stop camera acquisition. Reason: " << lError << std::endl;
}
std::cout << "......Streaming has been stopped." << std::endl;
}
// close camera
if( true == this->mCameraFlag )
{
lError = this->mCamera->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close camera. Reason: " << lError << std::endl;
}
std::cout << "......Camera has been closed." << std::endl;
}
// close interface
if( true == this->mInterfaceFlag )
{
lError = this->mInterface->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close interface. Reason: " << lError << std::endl;
}
std::cout << "......Interface has been closed." << std::endl;
}
// shutdown Vimba
if( true == this->mSystemFlag )
{
lError = this->mSystem.Shutdown();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not shutdown Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Vimba has been stooped." << std::endl;
}
}
//
// Convert given string to IP address,
// using respective socket library (Winsock/Arpa)
//
// Parameters:
// [in] aString String to be converted
// [out] aIPAddress Decimal representation of given IP address string
//
VmbErrorType cActionCommands::ConvertStringToIPAddress( std::string aString, VmbUint32_t* aIPAddress )
{
VmbErrorType lError = VmbErrorSuccess;
VmbUint32_t lIP = 0;
// check parameter
if( (true == aString.empty()) || (NULL == aIPAddress) )
{
std::cout << "[F]...Invalid parameter given" << std::endl;
return VmbErrorBadParameter;
}
// convert given string to IP struct
lIP = inet_addr( aString.c_str() );
if( -1 == lIP )
{
lError = VmbErrorInvalidValue;
}
else
{
#ifdef _LITTLE_ENDIAN
lIP = ntohl( lIP );
#endif
*aIPAddress = lIP;
}
return lError;
}
//
// Start Vimba and open camera with given string
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
//
VmbErrorType cActionCommands::PrepareCamera( std::string aCamera )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( true == aCamera.empty() )
{
std::cout << "[F]...Invalid device ID or IP address given." << std::endl;
return VmbErrorBadParameter;
}
// start Vimba
lError = this->mSystem.Startup();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not start Vimba API. Reason: " << lError << std::endl;
return lError;
}
this->mSystemFlag = true;
std::cout << "......Vimba has been started." << std::endl;
// open camera with given string (could be device ID or IP address)
lError = this->mSystem.OpenCameraByID( aCamera.c_str(), VmbAccessModeFull, this->mCamera );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not open camera " << aCamera << ". Reason: " << lError << std::endl;
this->FailureShutdown();
return lError;
}
this->mCameraFlag = true;
std::cout << "......Camera has been opened (" << aCamera << ")." << std::endl;
return lError;
}
//
// Close camera and shutdown Vimba
//
VmbErrorType cActionCommands::StopCamera()
{
VmbErrorType lError = VmbErrorSuccess;
if( true == this->mCameraFlag )
{
// close camera
lError = this->mCamera->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close camera. Reason: " << lError << std::endl;
}
this->mCameraFlag = false;
std::cout << "......Camera has been closed." << std::endl;
}
if( true == this->mSystemFlag )
{
// shutdown Vimba
lError = this->mSystem.Shutdown();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not stop Vimba. Reason: " << lError << std::endl;
}
this->mSystemFlag = false;
std::cout << "......Vimba has been stopped." << std::endl;
}
return lError;
}
//
// Prepare trigger settings for given camera
//
VmbErrorType cActionCommands::PrepareTrigger()
{
VmbErrorType lError = VmbErrorSuccess;
FeaturePtr lFeature;
char* lTemp = "";;
// select FrameStart trigger via TriggerSelector feature
lTemp = "FrameStart";
lError = this->SetFeatureValue( "TriggerSelector", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set TriggerSelector to FrameStart. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set trigger source to Action0
lTemp = "Action0";
lError = this->SetFeatureValue( "TriggerSource", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set TriggerSource to 'Action0'. Reason: " << lError << ". Probably this camera does not support Action Commands." << std::endl;
FailureShutdown();
return lError;
}
// enable trigger
lTemp = "On";
lError = this->SetFeatureValue( "TriggerMode", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not enable TriggerMode for FrameStart. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Trigger FrameStart has been activated and set to Action0" << std::endl;
return lError;
}
//
// Set Action Command information to given feature owner.
// This could be Vimba system, interface or the camera
//
// Parameters:
// [in] aOwner Feature owner, like System, Interface or Camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbErrorType cActionCommands::PrepareActionCommand( tFeatureOwner aOwner, tActionCommand* aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( NULL == aCommand )
{
std::cout << "[F]...Invalid Action Command given." << std::endl;
FailureShutdown();
return VmbErrorBadParameter;
}
// set device key
lError = this->SetFeatureValue( "ActionDeviceKey", aOwner, VmbFeatureDataInt, (void*)(aCommand->mDeviceKey), sizeof(aCommand->mDeviceKey) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionDeviceKey. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set group key
lError = this->SetFeatureValue( "ActionGroupKey", aOwner, VmbFeatureDataInt, (void*)(aCommand->mGroupKey), sizeof(aCommand->mGroupKey) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionGroupKey. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set group mask
lError = this->SetFeatureValue( "ActionGroupMask", aOwner, VmbFeatureDataInt, (void*)(aCommand->mGroupMask), sizeof(aCommand->mGroupMask) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionGroupMask. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been set (" << aCommand->mDeviceKey << ", " << aCommand->mGroupKey << ", " << aCommand->mGroupMask << ")" << std::endl;
return lError;
}
//
// Prepare streaming settings in Vimba and the camera,
// like allocating the buffers, start capture engine, etc.
//
VmbErrorType cActionCommands::PrepareStreaming()
{
VmbErrorType lError = VmbErrorSuccess;
FeaturePtr lFeature;
// set GVSP packet size to max value (MTU)
// and wait until command is done
lError = this->mCamera->GetFeatureByName( "GVSPAdjustPacketSize", lFeature );
if( VmbErrorSuccess == lError )
{
lError = lFeature->RunCommand();
}
// check if any failure occurred
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set GVSP packet size. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// check if operation is done
bool lFlag = false;
do
{
lError = lFeature->IsCommandDone( lFlag );
if( VmbErrorSuccess != lError )
{
break;
}
} while( VmbBoolFalse == lFlag );
// get GVSP packet size, which was actually set in the camera
VmbInt64_t lGVSPSize = 0;
lError = this->GetFeatureValue( "GVSPPacketSize", eFeatureOwnerCamera, NULL, &lGVSPSize, NULL );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not get GVSP packet size. Reason: " << lError << std::endl;
}
std::cout << "......GVSP packet size has been set to maximum (" << lGVSPSize << ")" << std::endl;
// create new frame observer
this->mFrameObserver = new cFrameObserver( this->mCamera );
// start continuous image acquisition
lError = this->mCamera->StartContinuousImageAcquisition( NUM_FRAMES, IFrameObserverPtr(this->mFrameObserver) );
if( VmbErrorSuccess != lError )
{
FailureShutdown();
std::cout << "[F]...Could not start continuous image acquisition. Reason: " << lError << std::endl;
return lError;
}
this->mStreamingFlag = true;
std::cout << "......Camera acquisition has been started." << std::endl;
return lError;
}
//
// End streaming
//
VmbErrorType cActionCommands::StopStreaming()
{
VmbErrorType lError = VmbErrorSuccess;
// stop continuous image acquisition
lError = this->mCamera->StopContinuousImageAcquisition();
if( VmbErrorSuccess != lError )
{
FailureShutdown();
std::cout << "[F]...Could not stop streaming. Reason: " << lError << std::endl;
return lError;
}
this->mStreamingFlag = false;
std::cout << "......Camera acquisition has been stopped." << std::endl;
return lError;
}
//
// Send Action Command on system level.
// This command will be broadcasted on all network interfaces.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType cActionCommands::SendActionCommandOnAllInterfaces( std::string aCamera, tActionCommand aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// -start Vimba
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger();
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( eFeatureOwnerCamera, &aCommand );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -adjust GVSP packet size
// -get payload size
// -allocate memory for frame buffers
// -announce frames and move them to buffer input pool
// -start capture engine
// -move frames to capture queue (buffer output queue)
// -call start acquisition feature in the camera
lError = PrepareStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// determine if Action Command shall be send as uni- or broadcast
// if IP address was given, send it as unicast
VmbUint32_t lIP = 0;
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address to Vimba
lError = this->SetFeatureValue( "GevActionDestinationIPAddress", eFeatureOwnerSystem, VmbFeatureDataInt, (void*)lIP, sizeof(lIP) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set IP address '" << aCamera << "' to Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Action Command will be send as unicast to IP '" << aCamera << "' (" << lIP << ")" << std::endl;
}
// set Action Command to Vimba system
// -device key
// -group key
// -group mask
lError = PrepareActionCommand(eFeatureOwnerSystem, &aCommand);
if (VmbErrorSuccess != lError)
{
std::cout << "[F]...Could not prepare Action Command. Reason: " << lError << std::endl;
}
#ifdef _WIN32
std::cout << "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n";
#else
std::cout << "\n<< Please enter 'a' and return to send prepared Action Command. To stop example enter 'q' and return >>\n\n";
#endif
// repeat this until user hits ESC
int lKey = 0;
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = RunCommand( "ActionCommand", eFeatureOwnerSystem );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not send Action Command. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been sent." << std::endl;
}
} while( 113 != lKey );
// stop streaming
lError = StopStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera();
return lError;
}
//
// Send Action Command on interface level.
// This command will be broadcasted on given network interface.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aInterface The network interface on which the Action Command
// will be sent out
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType cActionCommands::SendActionCommandOnInterface( std::string aCamera, std::string aInterface, tActionCommand aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// -start Vimba
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger();
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( eFeatureOwnerCamera, &aCommand );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -adjust GVSP packet size
// -get payload size
// -allocate memory for frame buffers
// -announce frames and move them to buffer input pool
// -start capture engine
// -move frames to capture queue (buffer output queue)
// -call start acquisition feature in the camera
lError = PrepareStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// get available interfaces
InterfacePtrVector lInterfaces;
lError = this->mSystem.GetInterfaces( lInterfaces );
if( (VmbErrorSuccess != lError) || (0 == lInterfaces.size()) )
{
std::cout << "[F]...Could not retrieve interfaces" << std::endl;
FailureShutdown();
return lError;
}
// print interface list
bool lFound = false;
int lIndex = 0;
for( int i=0; i<lInterfaces.size(); ++i )
{
InterfacePtr lInterface = lInterfaces.at(i);
std::string lInterfaceID = "";
lError = lInterface->GetID( lInterfaceID );
if( VmbErrorSuccess == lError )
{
std::cout << ".........[" << i << "] " << lInterfaceID << std::endl;
// compare given interface ID with current one
if( 0 == lInterfaceID.compare( aInterface ) )
{
// if interface ID matches, keep index
lFound = true;
lIndex = i;
}
}
}
// if no interface with given ID was found, return
if( false == lFound )
{
std::cout << "[F]...Given interface with ID '" << aInterface << "' was not found!" << std::endl;
FailureShutdown( );
return VmbErrorBadParameter;
}
// get interface pointer
this->mInterface = lInterfaces.at( lIndex );
if( true == SP_ISNULL(this->mInterface) )
{
std::cout << "[F]...No valid interface pointer with given index found" << std::endl;
FailureShutdown();
return VmbErrorBadParameter;
}
// check interface type
VmbInterfaceType lInterfaceType = VmbInterfaceUnknown;
lError = this->mInterface->GetType( lInterfaceType );
if( (VmbErrorSuccess != lError) || (VmbInterfaceEthernet != lInterfaceType) )
{
printf( "[F]...Selected interface is non-GigE interface!\n" );
FailureShutdown();
return VmbErrorBadParameter;
}
// open interface
lError = this->mInterface->Open();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not open interface" << std::endl;
FailureShutdown();
return lError;
}
this->mInterfaceFlag = true;
std::cout << "......Interface has been opened." << std::endl;
// determine if Action Command shall be send as uni- or broadcast
// if IP address was given, send it as unicast
VmbUint32_t lIP = 0;
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address to the selected interface
lError = this->SetFeatureValue( "GevActionDestinationIPAddress", eFeatureOwnerInterface, VmbFeatureDataInt, (void*)lIP, sizeof(lIP) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set IP address '" << aCamera << "' to Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Action Command will be send as unicast to IP '" << aCamera << "' (" << lIP << ")" << std::endl;
}
// set Action Command to the selected interface
// -device key
// -group key
// -group mask
lError = PrepareActionCommand(eFeatureOwnerInterface, &aCommand);
if (VmbErrorSuccess != lError)
{
std::cout << "[F]...Could not prepare Action Command. Reason: " << lError << std::endl;
}
#ifdef _WIN32
std::cout << "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n";
#else
std::cout << "\n<< Please enter 'a' and return to send prepared Action Command. To stop example enter 'q' and return >>\n\n";
#endif
// repeat this until user hits ESC
int lKey = 0;
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = RunCommand( "ActionCommand", eFeatureOwnerInterface );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not send Action Command. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been sent." << std::endl;
}
} while( 113 != lKey );
// close interface
lError = this->mInterface->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "Could not close interface. Reason: " << lError << std::endl;
}
this->mInterfaceFlag = false;
std::cout << "......Interface has been closed." << std::endl;
// stop streaming
lError = StopStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera();
return lError;
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,200 @@
/*=============================================================================
Copyright (C) 2017 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: ActionCommands.h
Description: This example will create an Action Command and send it to any
camera, given by parameter. The following can be set up with
parameters as well:
-send Action Command as broadcast on specific network interface
-send Action Command as broadcast to all network interfaces
-send Action Command to specific IP address (unicast)
-------------------------------------------------------------------------------
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_ACTION_COMMANDS
#define AVT_VMBAPI_EXAMPLES_ACTION_COMMANDS
#include "VimbaCPP/Include/VimbaCPP.h"
#include "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
// struct representing an Action Command
typedef struct tActionCommand
{
VmbUint32_t mDeviceKey;
VmbUint32_t mGroupKey;
VmbUint32_t mGroupMask;
} tActionCommand;
typedef enum tFeatureOwner
{
eFeatureOwnerUnknown = 0,
eFeatureOwnerSystem = 1,
eFeatureOwnerInterface = 2,
eFeatureOwnerCamera = 3
} tFeatureOwner;
class cActionCommands
{
private:
VimbaSystem& mSystem;
InterfacePtr mInterface;
CameraPtr mCamera;
cFrameObserver* mFrameObserver;
bool mSystemFlag;
bool mInterfaceFlag;
bool mCameraFlag;
bool mStreamingFlag;
public:
//
// Constructor
//
cActionCommands();
//
// Destructor
//
~cActionCommands();
//
// Helper method to read feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [out] aType Feature data type
// [in/out] aValue Buffer for feature value
// [in/out] aSize Size of buffer
//
VmbErrorType GetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType* aType, void* aValue, size_t* aSize );
//
// Helper method to write feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [in] aType Feature data type
// [in] aValue Buffer for feature value
// [in] aSize Size of buffer
//
VmbErrorType SetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType aType, void* aValue, size_t aSize );
//
// Helper method to run a Command Feature
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
//
VmbErrorType RunCommand( const char* aName, tFeatureOwner aOwner );
//
// Called when any failure occurs within the example.
// Ensures to stop streaming, close interface, close camera and shutdown Vimba
//
void FailureShutdown();
//
// Convert given string to IP address,
// using respective socket library (Winsock/Arpa)
//
// Parameters:
// [in] aString String to be converted
// [out] aIPAddress Decimal representation of given IP address string
//
VmbErrorType ConvertStringToIPAddress( std::string aString, VmbUint32_t* aIPAddress );
//
// Start Vimba and open camera with given string
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
//
VmbErrorType PrepareCamera( std::string aCamera );
//
// Close camera and shutdown Vimba
//
VmbErrorType StopCamera();
//
// Prepare trigger settings for given camera
//
VmbErrorType PrepareTrigger();
//
// Set Action Command information to given feature owner.
// This could be Vimba system, interface or the camera
//
// Parameters:
// [in] aOwner Feature owner, like System, Interface or Camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbErrorType PrepareActionCommand( tFeatureOwner aOwner, tActionCommand* aCommand );
//
// Prepare streaming settings in Vimba and the camera,
// like allocating the buffers, start capture engine, etc.
//
VmbErrorType PrepareStreaming();
//
// End streaming
//
VmbErrorType StopStreaming();
//
// Send Action Command on system level.
// This command will be broadcasted on all network interfaces.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType SendActionCommandOnAllInterfaces( std::string aCamera, tActionCommand aCommand );
//
// Send Action Command on interface level.
// This command will be broadcasted on given network interface.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aInterface The network interface on which the Action Command
// will be sent out
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType SendActionCommandOnInterface( std::string aCamera, std::string aInterface, tActionCommand aCommand );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,76 @@
/*=============================================================================
Copyright (C) 2013 - 2017 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: FrameObserver.cpp
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
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 "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
// [in] eFrameInfos Indicates how the frame will be displayed
// [in] eColorProcessing Indicates how color processing is applied
//
cFrameObserver::cFrameObserver( CameraPtr aCamera )
: IFrameObserver( aCamera )
{
this->mCamera = aCamera;
}
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
void cFrameObserver::FrameReceived( const FramePtr pFrame )
{
if(false == SP_ISNULL( pFrame ) )
{
VmbErrorType lError = VmbErrorSuccess;
VmbFrameStatusType lStatus;
lError = SP_ACCESS( pFrame)->GetReceiveStatus( lStatus);
if( (VmbErrorSuccess == lError) && (VmbFrameStatusComplete == lStatus))
{
std::cout << "......Frame has been received" << std::endl;
}
// requeue frame
this->mCamera->QueueFrame( pFrame );
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,65 @@
/*=============================================================================
Copyright (C) 2013 - 2017 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: FrameObserver.h
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
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_FRAMEOBSERVER
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class cFrameObserver : virtual public IFrameObserver
{
private:
CameraPtr mCamera;
public:
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
//
cFrameObserver( CameraPtr aCamera );
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
virtual void FrameReceived( const FramePtr aFrame );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,98 @@
/*=============================================================================
Copyright (C) 2017 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 ActionCommands example of VimbaCPP.
annotations:
-local variables are prefixed with 'l' for local
-function parameter are prefixed with 'a' for 'argument'
-structs are prefixed with 't' for 'type'
-classes are prefixed with 'c' for 'class'
-class attributes and struct members are prefixed with 'm' for members
-enum literals are prefixed with 'e' for 'enumeration'
-------------------------------------------------------------------------------
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 <string.h>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "ActionCommands.h"
// function to print out help how to use this example application
void PrintHelp()
{
printf( "Usage: ActionCommands <CameraID/IPAdress> <InterfaceID>\n\n" );
printf( "Parameters: CameraID ID of the camera to be used\n" );
printf( " IPAddress IP address of camera to react on Action Command\n" );
printf( " InterfaceID ID of network interface to send out Action Command\n" );
printf( " 'ALL' enables broadcast on all interfaces\n\n" );
}
int main( int argc, char* argv[] )
{
VmbErrorType lError = VmbErrorSuccess;
std::cout << std::endl;
std::cout << "/////////////////////////////////////////" << std::endl;
std::cout << "/// Vimba API Action Commands Example ///" << std::endl;
std::cout << "/////////////////////////////////////////" << std::endl;
std::cout << std::endl;
// check number of arguments
if( 3 == argc )
{
// create Action Command example instance
AVT::VmbAPI::Examples::cActionCommands lProgram;
// define Action Command to be set in the camera
// and used by either Vimba system or interface module
AVT::VmbAPI::Examples::tActionCommand lActionCommand;
lActionCommand.mDeviceKey = 1;
lActionCommand.mGroupKey = 1;
lActionCommand.mGroupMask = 1;
// check if interface index is '-1' to send out Action Command on all interfaces
// if not, send Action Command via given network interface
if( 0 == strcmp("ALL", argv[2]) )
{
lError = lProgram.SendActionCommandOnAllInterfaces( argv[1], lActionCommand );
}
else
{
lError = lProgram.SendActionCommandOnInterface( argv[1], argv[2], lActionCommand );
}
}
else
{
lError = VmbErrorBadParameter;
std::cout << "[F]...Invalid number of parameters given!" << std::endl;
std::cout << std::endl;
PrintHelp();
}
std::cout << std::endl;
return lError;
}