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 = EventHandling
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)/EventHandling.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/EventObserver.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,288 @@
/*=============================================================================
Copyright (C) 2014 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: EventHandling.cpp
Description: The EventHandling example will register observer on all
'EventData' features and turn on camera notification for
'AcquisitionStart' events.
-------------------------------------------------------------------------------
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 <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <EventHandling.h>
#include <EventObserver.h>
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
// Purpose: Example execution.
//
// Parameter:
// [in ] std::string cameraID Use camera with this ID for the example.
void EventHandling::RunExample( std::string cameraID )
{
VimbaSystem& sys = VimbaSystem::GetInstance(); // Get a reference to the VimbaSystem singleton
std::cout << "Vimba C++ API Version " << sys << "\n\n"; // Print out version of Vimba
VmbErrorType err = sys.Startup(); // Initialize the Vimba API
CameraPtr pCamera = CameraPtr(); // Our camera
if( VmbErrorSuccess == err )
{
if( cameraID.empty() ) // If no ID was provided use the first camera
{
CameraPtrVector cameras;
err = sys.GetCameras( cameras );
if( VmbErrorSuccess == err
&& !cameras.empty() )
{
err = cameras[0]->Open( VmbAccessModeFull ); // Open the camera
if( VmbErrorSuccess == err )
{
pCamera = cameras[0];
err = pCamera->GetID( cameraID );
}
}
}
else
{
err = sys.OpenCameraByID( cameraID.c_str(), VmbAccessModeFull, pCamera ); // Open the camera
}
if( NULL != pCamera )
{
VmbInterfaceType interfaceType;
pCamera->GetInterfaceType( interfaceType );
if( VmbErrorSuccess == err )
{
switch ( interfaceType )
{
case VmbInterfaceEthernet:
{
if( VmbErrorSuccess == err )
{
err = DeactivateAllCameraNotifications( pCamera );
if( VmbErrorSuccess == err )
{
err = ActivateNotification( pCamera, "AcquisitionStart" );
if( VmbErrorSuccess == err )
{
err = RegisterEventObserver( pCamera );
if( VmbErrorSuccess == err )
{
std::cout << "Acquire image to trigger event.\n";
std::cout << "\n----------- Events -----------\n\n";
FramePtr pFrame;
VmbInt32_t exampleTimeoutValue = 2000;
pCamera->AcquireSingleImage( pFrame, exampleTimeoutValue ); // Trigger the event
}
}
}
}
break;
}
default:
std::cout << "Interface type of camera not supported by this example.: " << cameraID << "\n";
}
}
else
{
std::cout << "Could not get interface type. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
pCamera->Close();
}
else
{
std::cout << "Could not open camera or no camera available. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
sys.Shutdown();
}
else
{
std::cout << "Could not start system. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
// Purpose: Deactivate all camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType EventHandling::DeactivateAllCameraNotifications( CameraPtr pCamera )
{
std::cout << "Deactivate notifications.\n";
FeaturePtr pFeatureEventSelector;
VmbErrorType err = pCamera->GetFeatureByName( "EventSelector", pFeatureEventSelector );
if( VmbErrorSuccess == err )
{
EnumEntryVector eventSelectorEntrys;
err = pFeatureEventSelector->GetEntries( eventSelectorEntrys );
if( VmbErrorSuccess == err )
{
FeaturePtr pFeatureEnumEntry;
for( size_t i = 0; i < eventSelectorEntrys.size(); i++ )
{
std::string entryValue = "";
err = eventSelectorEntrys[i].GetName( entryValue );
if( VmbErrorSuccess == err )
{
bool isCurrentEntryAvailable = false;
err = pFeatureEventSelector->IsValueAvailable( entryValue.c_str(), isCurrentEntryAvailable );
if ( VmbErrorSuccess == err )
{
if ( isCurrentEntryAvailable )
{
err = pFeatureEventSelector->SetValue( entryValue.c_str() );
if( VmbErrorSuccess == err )
{
err = pCamera->GetFeatureByName( "EventNotification", pFeatureEnumEntry );
if( VmbErrorSuccess == err )
{
err = pFeatureEnumEntry->SetValue( "Off" );
if( VmbErrorSuccess != err )
{
std::cout << "Could not set notification 'Off'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventNotification'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not set 'EventSelector' value to '" << entryValue << "'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}
else
{
std::cout << "Could not check if entry is currently available. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get entry value. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}
else
{
std::cout << "Could not get 'EventSelector' entry's. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventSelector'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
return err;
}
// Purpose: Create for each 'Camera->EventData' feature an observer and register it.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType EventHandling::RegisterEventObserver( CameraPtr pCamera )
{
FeaturePtrVector features;
VmbErrorType err = pCamera->GetFeatures( features );
if( VmbErrorSuccess == err )
{
for( size_t i = 0; i < features.size(); i++ )
{
std::string category;
err = features[i]->GetCategory( category );
if( 0 == category.compare( "/EventControl/EventData" ) && VmbErrorSuccess == err )
{
IFeatureObserverPtr pObserver;
SP_SET( pObserver, new EventObserver( pCamera ) );
err = features[i]->RegisterObserver( pObserver );
if( VmbErrorSuccess != err )
{
std::cout << "Could not register observer. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}
}
else
{
std::cout << "Could not get features. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
return err;
}
// Purpose: Activate camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
// [in ] std::string eventName Name of event to activate.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType EventHandling::ActivateNotification( CameraPtr pCamera, std::string eventName )
{
std::cout << "Activate notification for '" << eventName << "' events.\n";
FeaturePtr feature;
VmbErrorType err = pCamera->GetFeatureByName( "EventSelector", feature );
if( VmbErrorSuccess == err )
{
err = feature->SetValue( eventName.c_str() );
if( VmbErrorSuccess == err )
{
err = pCamera->GetFeatureByName( "EventNotification", feature );
if( VmbErrorSuccess == err )
{
err = feature->SetValue( "On" );
if( VmbErrorSuccess != err )
{
std::cout << "Could not set notification 'On'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventNotification'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get selector '" << eventName << "'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventSelector'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
return err;
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,83 @@
/*=============================================================================
Copyright (C) 2014 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: EventHandling.h
Description: The EventHandling example will register observer on all
'EventData' features and turn on camera notification for
'AcquisitionStart' events.
-------------------------------------------------------------------------------
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_EVENT_HANDLING
#define AVT_VMBAPI_EXAMPLES_EVENT_HANDLING
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class EventHandling
{
public:
// Purpose: Example execution.
//
// Parameter:
// [in ] std::string cameraID Use camera with this ID for the example.
void RunExample( std::string cameraID );
private:
// Purpose: Deactivate all camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType DeactivateAllCameraNotifications( CameraPtr pCamera );
// Purpose: Create for each 'Camera->EventData' feature an observer and register it.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType RegisterEventObserver( CameraPtr pCamera );
// Purpose: Activate camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
// [in ] std::string eventName Name of event to activate.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType ActivateNotification( CameraPtr pCamera, std::string eventName );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,71 @@
/*=============================================================================
Copyright (C) 2014 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: EventObserver.h
Description: The EventObserver can be attached to a camera feature. On Feature
changing the function FeatureChanged() is called.
-------------------------------------------------------------------------------
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 "EventObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
EventObserver::EventObserver( AVT::VmbAPI::CameraPtr pCam )
: m_pCam( pCam )
{
}
// Purpose: This function will be called when the observed feature is changing.
//
// Parameter:
// [in ] const AVT::VmbAPI::FeaturePtr &feature changed feature
//
void EventObserver::FeatureChanged( const AVT::VmbAPI::FeaturePtr &feature )
{
if( feature != NULL )
{
std::string featureName;
if ( !feature->GetName( featureName ) )
{
std::cout << featureName << " (Event) has changed to ";
AVT::VmbAPI::FeaturePtr pFeature;
VmbInt64_t nID;
if ( !( m_pCam->GetFeatureByName( featureName.c_str(), pFeature ) )
&& !( pFeature->GetValue( nID ) ) )
{
std::cout << nID << std::endl;
}
}
else
{
std::cout << "An error occurred" << std::endl;
}
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,58 @@
/*=============================================================================
Copyright (C) 2014 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: EventObserver.h
Description: The EventObserver can be attached to a camera feature. On Feature
changing the function FeatureChanged() is called.
-------------------------------------------------------------------------------
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_EVENT_OBSERVER_H
#define AVT_VMBAPI_EXAMPLES_EVENT_OBSERVER_H
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class EventObserver : public AVT::VmbAPI::IFeatureObserver
{
private:
AVT::VmbAPI::CameraPtr m_pCam;
public:
// Purpose: This function will be called when the observed feature is changing.
//
// Parameter:
// [in ] const AVT::VmbAPI::FeaturePtr &feature changed feature
//
virtual void FeatureChanged( const AVT::VmbAPI::FeaturePtr &feature );
EventObserver( AVT::VmbAPI::CameraPtr pCam );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (C) 2014 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 EventHandling 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 "EventHandling.h"
int main( int argc, char* argv[] )
{
std::cout << "\n";
std::cout << "////////////////////////////////////////\n";
std::cout << "/// Vimba API Event Handling Example ///\n";
std::cout << "////////////////////////////////////////\n\n";
if( 2 < argc )
{
std::cout << "Usage: EventHandling [CameraID]\n\n";
std::cout << "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
}
else if( 2 == argc )
{
AVT::VmbAPI::Examples::EventHandling eventHandler;
eventHandler.RunExample( argv[1] );
}
else
{
AVT::VmbAPI::Examples::EventHandling eventHandler;
eventHandler.RunExample( "" );
}
std::cout <<"\n";
}