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

Binary file not shown.

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" standalone="no" ?>
<Settings>
<!--
Use this to activate logging and set filename for logging (path can be absolute or relative to API)
Default behavior if omitted: Logging is deactivated
-->
<!-- <LogFileName>VimbaC.log</LogFileName> -->
<!--
Append messages to log file or reset log file at each API restart (if logging is enabled)
True: Always append log messages
False: Reset log file at each API restart
Default behavior if omitted: Reset log file at each API restart
-->
<!-- <AppendLog>False</AppendLog> -->
</Settings>

View File

@@ -0,0 +1,58 @@
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES = -D_LITTLE_ENDIAN
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ActionCommands.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,912 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#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
//
// Frame callback, which will be called when Vimba receives a frame from the camera
//
// Parameters:
// [in] aCamera Camera handle
// [in] aFrame Received frame
//
void VMB_CALL FrameCallback( const VmbHandle_t aCamera, VmbFrame_t* aFrame )
{
VmbError_t lError = VmbErrorSuccess;
// proceed only if given pointer are valid
if( (NULL != aCamera) && (NULL != aFrame) )
{
// check if received frame is complete
if( VmbFrameStatusComplete == aFrame->receiveStatus )
{
printf( "......Frame has been received\n" );
}
// re-queue received frame (buffer) to the capture queue (output buffer queue of GigE TL)
lError = VmbCaptureFrameQueue( aCamera, aFrame, &FrameCallback );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not re-queue received buffer\n" );
}
}
}
//
// Called when any failure occurs within the example.
// Ensures to close camera and shutdown Vimba
//
// Parameters:
// [in] aCamera Camera handle
//
void FailureShutdown( VmbHandle_t aCamera )
{
VmbError_t lError = VmbErrorSuccess;
// close camera
lError = VmbCameraClose( aCamera );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not close camera. Reason: %i", lError );
}
printf( "......Camera has been closed\n" );
// shutdown Vimba
VmbShutdown();
printf( "......Vimba has been stopped\n" );
}
//
// 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
//
VmbError_t ConvertStringToIPAddress( const char* aString, VmbUint32_t* aIPAddress )
{
VmbError_t lError = VmbErrorSuccess;
VmbUint32_t lIP = 0;
// check parameter
if( (NULL == aString) || (NULL == aIPAddress) )
{
printf( "[F]...Invalid parameter given.\n" );
return VmbErrorBadParameter;
}
// convert given string to IP struct
lIP = inet_addr( aString );
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
// [out] aHandle Handle to camera, if opened successfully
//
VmbError_t PrepareCamera( const char* aCamera, VmbHandle_t* aHandle )
{
VmbError_t lError = VmbErrorSuccess;
VmbHandle_t lCameraHandle = NULL;
// check parameter
if( (NULL == aCamera) || (NULL == aHandle) )
{
printf( "[F]...Invalid parameter given.\n" );
return VmbErrorBadParameter;
}
// start Vimba
lError = VmbStartup();
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not start Vimba API. Reason: %i\n", lError );
return lError;
}
printf( "......Vimba has been started\n" );
// -check if GigE TL is present
// -set API waiting time for discovery response to 250ms
// -send discovery packet once, to all connected cameras
lError = DiscoverGigECameras();
if( VmbErrorSuccess != lError )
{
VmbShutdown();
return lError;
}
printf( "......GigE Devices have been discovered\n" );
// open camera with given string (could be device ID or IP address)
lError = VmbCameraOpen( aCamera, VmbAccessModeFull, &lCameraHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not open camera '%s'. Reason: %i\n", aCamera, lError );
VmbShutdown();
return lError;
}
printf( "......Camera has been opened (%s)\n", aCamera );
// return camera handle
*aHandle = lCameraHandle;
return lError;
}
//
// Close camera and shutdown Vimba
//
// Parameters:
// [in] aHandle Handle to camera
//
VmbError_t StopCamera( VmbHandle_t aHandle )
{
VmbError_t lError = VmbErrorSuccess;
// close camera
lError = VmbCameraClose( aHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not close camera. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
printf( "......Camera has been closed\n" );
// shutdown Vimba
VmbShutdown();
printf( "......Vimba has been stopped\n" );
return lError;
}
//
// Prepare trigger settings for given camera
//
// Parameters:
// [in] aHandle Handle to camera
//
VmbError_t PrepareTrigger( VmbHandle_t aHandle )
{
VmbError_t lError = VmbErrorSuccess;
// check parameter
if( NULL == aHandle )
{
printf( "[F]...Invalid parameter given.\n" );
return VmbErrorBadParameter;
}
// select FrameStart trigger via TriggerSelector feature
lError = VmbFeatureEnumSet( aHandle, "TriggerSelector", "FrameStart" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set TriggerSelector to FrameStart. Reason: %i", lError );
FailureShutdown( aHandle );
return lError;
}
// set trigger source to Action0
lError = VmbFeatureEnumSet( aHandle, "TriggerSource", "Action0" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set TriggerSource to 'Action0'. Reason: %i\nProbably this camera does not support Action Commands.\n", lError );
FailureShutdown( aHandle );
return lError;
}
// enable trigger
lError = VmbFeatureEnumSet( aHandle, "TriggerMode", "On" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not enable TriggerMode for FrameStart. Reason: %i", lError );
FailureShutdown( aHandle );
return lError;
}
printf( "......Trigger FrameStart has been activated and set to Action0\n" );
return lError;
}
//
// Set Action Command information to given handle.
// This could be a handle to Vimba system, interface
// or a camera handle
//
// Parameters:
// [in] aHandle Handle to either Vimba system, interface or camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbError_t PrepareActionCommand( VmbHandle_t aHandle, tActionCommand* aCommand )
{
VmbError_t lError = VmbErrorSuccess;
// check parameter
if( (NULL == aHandle) || (NULL == aCommand) )
{
printf( "[F]...Invalid parameter given.\n" );
return VmbErrorBadParameter;
}
// set device key
lError = VmbFeatureIntSet( aHandle, "ActionDeviceKey", aCommand->mDeviceKey );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set ActionDeviceKey. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
// set group key
lError = VmbFeatureIntSet( aHandle, "ActionGroupKey", aCommand->mGroupKey );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set ActionGroupKey. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
// set group mask
lError = VmbFeatureIntSet( aHandle, "ActionGroupMask", aCommand->mGroupMask );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set ActionGroupMask. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
printf( "......Action Command has been set (%i,%i,%i)\n", aCommand->mDeviceKey, aCommand->mGroupKey, aCommand->mGroupMask );
return lError;
}
//
// Prepare streaming settings in the camera,
// like allocating the buffers, start capture engine, etc.
//
// Parameters:
// [in] aHandle Handle to camera
// [in] aFrameArray Array of frames to be used for streaming
//
VmbError_t PrepareStreaming( VmbHandle_t aHandle, VmbFrame_t* aFrameArray )
{
VmbError_t lError = VmbErrorSuccess;
VmbBool_t lFlag = VmbBoolFalse;
VmbInt64_t lGVSPSize = 0;
VmbInt64_t lPayloadSize = 0;
int lIter = 0;
// check parameter
if( NULL == aHandle )
{
printf( "[F]...Invalid parameter given.\n" );
return VmbErrorBadParameter;
}
// set GVSP packet size to max value (MTU)
// and wait until command is done
lError = VmbFeatureCommandRun( aHandle, "GVSPAdjustPacketSize" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set GVSP packet size. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
else
{
do
{
// check if operation is done
lError = VmbFeatureCommandIsDone( aHandle, "GVSPAdjustPacketSize", &lFlag );
if( VmbErrorSuccess != lError )
{
break;
}
} while( VmbBoolFalse == lFlag );
}
// get GVSP packet size, which was actually set in the camera
lError = VmbFeatureIntGet( aHandle, "GVSPPacketSize", &lGVSPSize );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not get GVSP packet size. Reason: %i\n", lError );
}
printf( "......GVSP packet size has been set to maximum (%i)\n", (int)lGVSPSize );
// get camera payload size (necessary for allocating the buffer memory)
lError = VmbFeatureIntGet( aHandle, "PayloadSize", &lPayloadSize );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not get payload size. Reason: %i", lError );
FailureShutdown( aHandle );
return lError;
}
printf( "......Camera has payload size of '%i'\n", (int)lPayloadSize );
// initialize frame array with 0
memset( aFrameArray, 0, sizeof(aFrameArray) );
// allocate buffer memory for each frame
for( lIter = 0; lIter < NUM_FRAMES; ++lIter )
{
// allocate buffer
aFrameArray[lIter].buffer = (unsigned char*)malloc((VmbUint32_t)lPayloadSize);
if( NULL == aFrameArray[lIter].buffer )
{
lError = VmbErrorResources;
break;
}
// set buffer size
aFrameArray[lIter].bufferSize = (VmbUint32_t)lPayloadSize;
}
// in case any failure occured, free allocated space
if( VmbErrorSuccess != lError )
{
printf( "[F]...Failure during memory allocation for buffers (%i/%i). Reason: %i", lIter, NUM_FRAMES, lError );
for( lIter = 0; lIter < NUM_FRAMES; ++lIter )
{
free( aFrameArray[lIter].buffer );
memset( aFrameArray, 0, sizeof(aFrameArray) );
}
FailureShutdown( aHandle );
return lError;
}
printf( "......Allocated memory for frame buffers\n" );
// announce frame buffers (move them to buffer input pool of GigE TL)
for( lIter = 0; lIter < NUM_FRAMES; ++lIter )
{
lError = VmbFrameAnnounce( aHandle, &aFrameArray[lIter], sizeof(VmbFrame_t) );
if( VmbErrorSuccess != lError )
{
break;
}
}
// in case any failure occured, revoke all announced frames
if( VmbErrorSuccess != lError )
{
printf( "[F]...Failure during announcing frame buffers (%i/%i). Reason: %i", lIter, NUM_FRAMES, lError );
lError = VmbFrameRevokeAll( aHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not revoke all frame buffers. Reason: %i", lError );
}
FailureShutdown( aHandle );
return lError;
}
printf( "......Buffers have been announced and moved to input pool\n" );
// start capture engine
lError = VmbCaptureStart( aHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not start capture engine. Reason: %i", lError );
FailureShutdown( aHandle );
return lError;
}
printf( "......Capture engine has been started\n" );
// move announced frames to output buffer queue
for( lIter = 0; lIter < NUM_FRAMES; ++lIter )
{
lError = VmbCaptureFrameQueue( aHandle, &aFrameArray[lIter], &FrameCallback );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not queue frame to output buffer queue. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
}
printf( "......Buffers have been moved to output queue\n" );
// start acquisition in the camera
lError = VmbFeatureCommandRun( aHandle, "AcquisitionStart" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not start camera acquisition. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
printf( "......Camera acquisition has been started\n" );
return lError;
}
//
// End streaming
//
// Parameters:
// [in] aHandle Handle to camera
// [in] aFrameArray Array of frames to be used for streaming
//
VmbError_t StopStreaming( VmbHandle_t aHandle, VmbFrame_t* aFrameArray )
{
VmbError_t lError = VmbErrorSuccess;
int lIter = 0;
// call acquisition stop feature in camera
lError = VmbFeatureCommandRun( aHandle, "AcquisitionStop" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not run AcquisitionStop feature. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
// stop capture engine
lError = VmbCaptureEnd( aHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not stop capture engine. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
// flush buffer output queue
lError = VmbCaptureQueueFlush( aHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not flush output buffer queue. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
// revoke all announced buffers
lError = VmbFrameRevokeAll( aHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not flush input buffer pool. Reason: %i\n", lError );
FailureShutdown( aHandle );
return lError;
}
// free allocated space for buffers
for( lIter = 0; lIter < NUM_FRAMES; ++lIter )
{
free( aFrameArray[lIter].buffer );
memset( aFrameArray, 0, sizeof(aFrameArray) );
}
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 set in the camera
//
VmbError_t SendActionCommandOnAllInterfaces( const char* aCamera, tActionCommand aCommand )
{
VmbError_t lError = VmbErrorSuccess;
VmbBool_t lFlag = VmbBoolFalse;
VmbHandle_t lCameraHandle = NULL;
VmbUint32_t lIP = 0;
int lKey = 0;
VmbFrame_t lFrames[NUM_FRAMES];
// check parameter
if( NULL == aCamera )
{
printf( "[F]...Invalid parameter given!\n" );
return VmbErrorBadParameter;
}
// -start Vimba
// -discover GigE devices
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera, &lCameraHandle );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger( lCameraHandle );
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( lCameraHandle, &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( lCameraHandle, lFrames );
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
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address to Vimba
lError = VmbFeatureIntSet( gVimbaHandle, "GevActionDestinationIPAddress", lIP );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set IP address '%s' to Vimba. Reason: %i\n", aCamera, lError );
}
printf( "......Action Command will be send as unicast to IP '%s (%i)'\n", aCamera, lIP );
}
// set Action Command to Vimba system
// -device key
// -group key
// -group mask
lError = PrepareActionCommand( gVimbaHandle, &aCommand );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not prepare Action Command. Reason: %i\n", lError );
}
#ifdef _WIN32
printf( "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n" );
#else
printf( "\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
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = VmbFeatureCommandRun( gVimbaHandle, "ActionCommand" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not send Action Command. Reason: %i\n", lError );
FailureShutdown( lCameraHandle );
return lError;
}
printf( "......Action Command has been sent\n" );
}
} while( 113 != lKey );
// stop streaming
lError = StopStreaming( lCameraHandle, lFrames );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera( lCameraHandle );
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
//
VmbError_t SendActionCommandOnInterface( const char* aCamera, const char* aInterface, tActionCommand aCommand )
{
VmbError_t lError = VmbErrorSuccess;
VmbHandle_t lCameraHandle = NULL;
VmbInterfaceInfo_t* lInterfaces = NULL;
VmbUint32_t lCount = 0;
VmbHandle_t lInterfaceHandle = NULL;
VmbBool_t lFound = VmbBoolFalse;
int lInterfaceIndex = 0;
VmbUint32_t lIP = 0;
int lKey = 0;
VmbFrame_t lFrames[NUM_FRAMES];
int lIter = 0;
// check parameter
if( NULL == aCamera || NULL == aInterface )
{
printf( "[F]...Invalid parameter given!\n" );
return VmbErrorBadParameter;
}
// -start Vimba
// -discover GigE devices
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera, &lCameraHandle );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger( lCameraHandle );
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( lCameraHandle, &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( lCameraHandle, lFrames );
if( VmbErrorSuccess != lError )
{
return lError;
}
// get number of available interfaces
lError = VmbInterfacesList( NULL, lCount, &lCount, 0 );
if( (VmbErrorSuccess != lError) || (0 == lCount) )
{
printf( "[F]...Could not retrieve number of interfaces. Reason: %i\n", lError );
FailureShutdown( lCameraHandle );
return lError;
}
// allocate space for interface info list
lInterfaces = (VmbInterfaceInfo_t*)malloc( lCount * sizeof(VmbInterfaceInfo_t) );
if( NULL == lInterfaces )
{
printf( "[F]...Could not allocate space for interface info list.\n" );
FailureShutdown( lCameraHandle );
return lError;
}
// get interface info list
lError = VmbInterfacesList( lInterfaces, lCount, &lCount, sizeof(*lInterfaces) );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not retrieve interface info list. Reason: %i\n", lError );
FailureShutdown( lCameraHandle );
return lError;
}
// print interface list
printf( "......following interfaces were found:\n" );
for( lIter = 0; lIter<lCount; ++lIter )
{
printf( "..........[%i] %s\n", lIter, lInterfaces[lIter].interfaceIdString );
// compare given interface ID with current one
if( 0 == strcmp(aInterface, lInterfaces[lIter].interfaceIdString) )
{
// if interface ID matches, keep index
lFound = VmbBoolTrue;
lInterfaceIndex = lIter;
}
}
// if no interface with given ID was found, return
if( VmbBoolFalse == lFound )
{
printf( "[F]...Given interface with ID '%s' was not found!\n", aInterface );
FailureShutdown( lCameraHandle );
return VmbErrorBadParameter;
}
// check interface type
if( VmbInterfaceEthernet != lInterfaces[lInterfaceIndex].interfaceType )
{
printf( "[F]...Selected interface is non-GigE interface!\n" );
FailureShutdown( lCameraHandle );
return VmbErrorBadParameter;
}
// open network interface with given index
lError = VmbInterfaceOpen( aInterface, &lInterfaceHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not open interface with ID '%s'. Reason: %i\n", aInterface, lError );
FailureShutdown( lCameraHandle );
return lError;
}
printf( "......Interface '%s' has been opened.\n", aInterface );
// determine if Action Command shall be send as uni- or broadcast
// if IP address was given, send it as unicast
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address on the interface
lError = VmbFeatureIntSet( lInterfaceHandle, "GevActionDestinationIPAddress", lIP );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not set IP address '%s' to Vimba. Reason: %i\n", aCamera, lError );
}
printf( "......Action Command will be send as unicast to IP '%s (%i)'\n", aCamera, lIP );
}
// set Action Command to Vimba interface
// -device key
// -group key
// -group mask
lError = PrepareActionCommand( lInterfaceHandle, &aCommand );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not prepare Action Command. Reason: %i\n", lError );
}
#ifdef _WIN32
printf( "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n" );
#else
printf( "\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
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = VmbFeatureCommandRun( lInterfaceHandle, "ActionCommand" );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not send Action Command. Reason: %i\n", lError );
FailureShutdown( lCameraHandle );
return lError;
}
printf( "......Action Command has been sent\n" );
}
} while( 113 != lKey );
// close interface
lError = VmbInterfaceClose( lInterfaceHandle );
if( VmbErrorSuccess != lError )
{
printf( "[F]...Could not close interface. Reason: %i\n", lError );
FailureShutdown( lCameraHandle );
return lError;
}
// stop streaming
lError = StopStreaming( lCameraHandle, lFrames );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera( lCameraHandle );
return lError;
}

View File

@@ -0,0 +1,145 @@
/*=============================================================================
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 ACTION_COMMANDS_H_
#define ACTION_COMMANDS_H_
#include <VimbaC/Include/VimbaC.h>
#include <../../Common/DiscoverGigECameras.h>
// struct representing an Action Command
typedef struct tActionCommand
{
VmbUint32_t mDeviceKey;
VmbUint32_t mGroupKey;
VmbUint32_t mGroupMask;
} tActionCommand;
//
// Called when any failure occurs within the example.
// Ensures to close camera and shutdown Vimba
//
// Parameters:
// [in] aCamera Camera handle
//
void FailureShutdown( VmbHandle_t aCamera );
//
// 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
//
VmbError_t ConvertStringToIPAddress( const char* 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
// [out] aHandle Handle to camera, if opened successfully
//
VmbError_t PrepareCamera( const char* aCamera, VmbHandle_t* aHandle );
//
// Close camera and shutdown Vimba
//
// Parameters:
// [in] aHandle Handle to camera
//
VmbError_t StopCamera( VmbHandle_t aHandle );
//
// Prepare trigger settings for given camera
//
// Parameters:
// [in] aHandle Handle to camera
//
VmbError_t PrepareTrigger( VmbHandle_t aHandle );
//
// Set Action Command information to given handle.
// This could be a handle to Vimba system, interface
// or a camera handle
//
// Parameters:
// [in] aHandle Handle to either Vimba system, interface or camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbError_t PrepareActionCommand( VmbHandle_t aHandle, tActionCommand* aCommand );
//
// Prepare streaming settings in Vimba and the camera,
// like allocating the buffers, start capture engine, etc.
//
// Parameters:
// [in] aHandle Handle to camera
// [in] aFrameArray Array of frames to be used for streaming
//
VmbError_t PrepareStreaming( VmbHandle_t aHandle, VmbFrame_t* aFrameArray );
//
// End streaming
//
// Parameters:
// [in] aHandle Handle to camera
// [in] aFrameArray Array of frames to be used for streaming
//
VmbError_t StopStreaming( VmbHandle_t aHandle, VmbFrame_t* aFrameArray );
//
// 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
//
VmbError_t SendActionCommandOnAllInterfaces( const char* 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 send out
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbError_t SendActionCommandOnInterface( const char* aCamera, const char* aIndex, tActionCommand aCommand );
#endif

View File

@@ -0,0 +1,101 @@
/*=============================================================================
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 VimbaC.
annotations:
-local variables are prefixed with 'l' for local
-function parameter are prefixed with 'a' for 'argument'
-structs are prefixed with 't' for 'type'
-global variables are prefixed with 'g' for 'global'
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <VimbaC/Include/VimbaC.h>
#include <../../Common/PrintVimbaVersion.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[] )
{
VmbError_t lError = VmbErrorSuccess;
VmbUint32_t lIPAddress = 0;
tActionCommand lActionCommand;
printf( "\n" );
printf( "/////////////////////////////////////////\n" );
printf( "/// Vimba API Action Commands Example ///\n" );
printf( "/////////////////////////////////////////\n" );
printf( "\n" );
// show Vimba API version
PrintVimbaVersion();
printf( "\n" );
// check number of arguments
if( 3 == argc )
{
// define Action Command to be set in the camera
// and used by either Vimba system or interface module
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 = SendActionCommandOnAllInterfaces( argv[1], lActionCommand );
}
else
{
lError = SendActionCommandOnInterface( argv[1], argv[2], lActionCommand );
}
}
else
{
lError = VmbErrorBadParameter;
printf( "[F]...Invalid number of parameters given!\n\n" );
PrintHelp();
}
printf( "\n" );
return lError;
}

View File

@@ -0,0 +1,65 @@
PROJECT_NAME = AsynchronousGrab
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)/VimbaC.mk
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS) \
$(VIMBAIMAGETRANSFORM_LIBS) \
-lrt
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS) \
$(VIMBAIMAGETRANSFORM_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/AsynchronousGrab.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC \
VimbaImageTransform
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,648 @@
/*=============================================================================
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: AsynchronousGrab.c
Description: The AsynchronousGrab example will grab images asynchronously
using VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <time.h>
#include <pthread.h>
#endif
#include <VimbaC/Include/VimbaC.h>
#include "VmbTransform.h"
#include <AsynchronousGrab.h>
#include "Common/PrintVimbaVersion.h"
#include "Common/DiscoverGigECameras.h"
enum
{
NUM_FRAMES = 3
};
VmbBool_t g_bVimbaStarted = VmbBoolFalse; // Remember if Vimba is started
VmbBool_t g_bStreaming = VmbBoolFalse; // Remember if Vimba is streaming
VmbBool_t g_bAcquiring = VmbBoolFalse; // Remember if Vimba is acquiring
VmbHandle_t g_CameraHandle = NULL; // A handle to our camera
VmbFrame_t g_Frames[NUM_FRAMES]; // The frames we capture into
FrameInfos g_eFrameInfos = FrameInfos_Off; // Remember if we should print out frame infos
VmbBool_t g_bRGBValue = VmbBoolFalse; // Show RGB values
VmbBool_t g_bEnableColorProcessing = VmbBoolFalse; // Enables color processing for frames
VmbBool_t g_bUseAllocAndAnnouce = VmbBoolFalse; // Enables frame alloc and announce mode
double g_dFrameTime = 0.0; // Timestamp of last frame
VmbBool_t g_bFrameTimeValid = VmbBoolFalse; // Remember if there was a last timestamp
VmbUint64_t g_nFrameID = 0; // ID of last frame
VmbBool_t g_bFrameIDValid = VmbBoolFalse; // Remember if there was a last ID
#ifdef WIN32
double g_dFrequency = 0.0; //Frequency of tick counter in Win32
#else
#endif
#ifdef WIN32
HANDLE g_hMutex = INVALID_HANDLE_VALUE;
VmbBool_t CreateApiLock()
{
if( INVALID_HANDLE_VALUE != g_hMutex)
{
DestroyApiLock();
}
g_hMutex = CreateMutex( NULL, FALSE, NULL );
return INVALID_HANDLE_VALUE != g_hMutex;
}
void DestroyApiLock()
{
if( INVALID_HANDLE_VALUE != g_hMutex)
{
CloseHandle( g_hMutex );
}
}
VmbBool_t AquireApiLock()
{
if( WAIT_OBJECT_0 == WaitForSingleObject( g_hMutex, INFINITE ) )
{
return VmbBoolTrue;
}
return VmbBoolFalse;
}
void ReleaseApiLock()
{
ReleaseMutex( g_hMutex );
}
#else
pthread_mutex_t g_Mutex = PTHREAD_MUTEX_INITIALIZER;
VmbBool_t CreateApiLock()
{
return VmbBoolTrue;
}
void DestroyApiLock()
{
}
VmbBool_t AquireApiLock()
{
if(0 == pthread_mutex_lock( &g_Mutex ) )
{
return VmbBoolTrue;
}
return VmbBoolFalse;
}
void ReleaseApiLock()
{
pthread_mutex_unlock( &g_Mutex );
}
#endif
//
// Method: ProcessFrame
//
// Purpose: convert frames to RGB24 format and apply color processing if desired
//
// Parameters:
// [in] pFrame frame to process data might be destroyed dependent on transform function used
//
VmbError_t ProcessFrame( VmbFrame_t * pFrame)
{
VmbError_t Result = VmbErrorSuccess; // result of function
VmbUint32_t Width = 0; // will later hold the frame width
VmbUint32_t Height = 0; // will later hold the frame height
VmbImage SourceImage; // source image struct to pass to image transform
VmbImage DestinationImage; // destination image struct to pass to image transform
VmbRGB8_t* DestinationBuffer = NULL; // destination image buffer
VmbTransformInfo TransformInfo; // if desired the transform information is constructed here
VmbUint32_t TransformInfoCount = 0; // if color processing is desired this will be set
// check if we can get data
if( NULL == pFrame || NULL == pFrame->buffer )
{
printf("%s error invalid frame\n", __FUNCTION__);
return VmbErrorBadParameter;
}
// init local variables for frame width and height
Width = pFrame->width;
Height = pFrame->height;
if( g_bEnableColorProcessing == VmbBoolTrue ) // if color processing is desired set the transform matrix
{
const static VmbFloat_t matrix[9] = { 0.0, 0.0, 1.0, // matrix to swap red and blue component
0.0, 1.0, 0.0,
1.0, 0.0, 0.0 };
Result = VmbSetColorCorrectionMatrix3x3(matrix, &TransformInfo); // initialize transform info
if( VmbErrorSuccess != Result)
{
printf("%s error could not set transform matrix; Error: %d\n", __FUNCTION__, Result);
return Result;
}
TransformInfoCount = 1;
}
// set the struct size to image
SourceImage.Size = sizeof( SourceImage );
// set the image information from the frames pixel format and size
Result = VmbSetImageInfoFromPixelFormat( pFrame->pixelFormat, Width, Height, &SourceImage );
if( VmbErrorSuccess != Result)
{
printf( "%s error could not set source image info; Error: %d\n", __FUNCTION__, Result);
return Result;
}
// the frame buffer will be the images data buffer
SourceImage.Data = pFrame->buffer;
// set size for destination image
DestinationImage.Size = sizeof( DestinationImage );
// set destination image info from frame size and string for RGB8 (rgb24)
Result = VmbSetImageInfoFromString( "RGB8", 4, Width, Height, &DestinationImage );
if( VmbErrorSuccess != Result)
{
printf("%s error could not set destination image info; Error: %d\n", __FUNCTION__, Result);
return Result;
}
// allocate buffer for destination image size is width * height * size of rgb pixel
DestinationBuffer = (VmbRGB8_t*) malloc( Width*Height*sizeof( VmbRGB8_t) );
if( NULL == DestinationBuffer)
{
printf("%s error could not allocate rgb buffer for width: %d and height: %d\n", __FUNCTION__, Width, Height);
return VmbErrorResources;
}
// set the destination buffer to the data buffer of the image
DestinationImage.Data = DestinationBuffer;
// transform source to destination if color processing was enabled TransformInfoCount is 1 otherwise TransformInfo will be ignored
Result = VmbImageTransform( &SourceImage, &DestinationImage, &TransformInfo, TransformInfoCount );
// print first rgb pixel
printf("R: %d\tG: %d\tB: %d\n", DestinationBuffer->R, DestinationBuffer->G, DestinationBuffer->B);
// clean image buffer
free( DestinationBuffer );
return -Result;
}
//
// Method: GetTime
//
// Purpose: get time indicator
//
// Returns: time indicator in seconds for differential measurements
double GetTime()
{
#ifdef WIN32
LARGE_INTEGER nCounter;
QueryPerformanceCounter( &nCounter );
return ( (double)nCounter.QuadPart ) / g_dFrequency;
#else
struct timespec now;
clock_gettime( CLOCK_REALTIME, &now );
return ( (double)now.tv_sec ) + ( (double)now.tv_nsec ) / 1000000000.0;
#endif //WIN32
}
//
// Method: FrameCallback
//
// Purpose: called from Vimba if a frame is ready for user processing
//
// Parameters:
//
// [in] handle to camera that supplied the frame
// [in] pointer to frame structure that can hold valid data
//
void VMB_CALL FrameCallback( const VmbHandle_t cameraHandle, VmbFrame_t* pFrame )
{
//
// from here on the frame is under user control until returned to Vimba by re queuing it
// if you want to have smooth streaming keep the time you hold the frame short
//
VmbBool_t bShowFrameInfos = VmbBoolFalse; // showing frame infos
double dFPS = 0.0; // frames per second calculated
VmbBool_t bFPSValid = VmbBoolFalse; // indicator if fps calculation was valid
double dFrameTime = 0.0; // reference time for frames
double dTimeDiff = 0.0; // time difference between frames
VmbUint64_t nFramesMissing = 0; // number of missing frames
// Ensure that a frame callback is not interrupted by a VmbFrameRevoke during shutdown
AquireApiLock();
if( FrameInfos_Off != g_eFrameInfos )
{
if( FrameInfos_Show == g_eFrameInfos )
{
bShowFrameInfos = VmbBoolTrue;
}
if( VmbFrameFlagsFrameID & pFrame->receiveFlags )
{
if( g_bFrameIDValid )
{
if( pFrame->frameID != ( g_nFrameID + 1 ) )
{
// get difference between current frame and last received frame to calculate missing frames
nFramesMissing = pFrame->frameID - g_nFrameID - 1;
if( 1 == nFramesMissing )
{
printf("%s 1 missing frame detected\n", __FUNCTION__);
}
else
{
printf("%s error %llu missing frames detected\n",__FUNCTION__, nFramesMissing);
}
}
}
g_nFrameID = pFrame->frameID; // store current frame id to calculate missing frames in the next calls
g_bFrameIDValid = VmbBoolTrue;
dFrameTime = GetTime(); // get current time to calculate frames per second
if( ( g_bFrameTimeValid ) // only if the last time was valid
&& ( 0 == nFramesMissing ) ) // and the frame is not missing
{
dTimeDiff = dFrameTime - g_dFrameTime; // build time difference with last frames time
if( dTimeDiff > 0.0 )
{
dFPS = 1.0 / dTimeDiff;
bFPSValid = VmbBoolTrue;
}
else
{
bShowFrameInfos = VmbBoolTrue;
}
}
// store time for fps calculation in the next call
g_dFrameTime = dFrameTime;
g_bFrameTimeValid = VmbBoolTrue;
}
else
{
bShowFrameInfos = VmbBoolTrue;
g_bFrameIDValid = VmbBoolFalse;
g_bFrameTimeValid = VmbBoolFalse;
}
// test if the frame is complete
if( VmbFrameStatusComplete != pFrame->receiveStatus )
{
bShowFrameInfos = VmbBoolTrue;
}
}
if( bShowFrameInfos )
{
printf("Frame ID:");
if( VmbFrameFlagsFrameID & pFrame->receiveFlags )
{
printf( "%llu", pFrame->frameID );
}
else
{
printf( "?" );
}
printf( " Status:" );
switch( pFrame->receiveStatus )
{
case VmbFrameStatusComplete:
printf( "Complete" );
break;
case VmbFrameStatusIncomplete:
printf( "Incomplete" );
break;
case VmbFrameStatusTooSmall:
printf( "Too small" );
break;
case VmbFrameStatusInvalid:
printf( "Invalid" );
break;
default:
printf( "?" );
break;
}
printf( " Size:" );
if( VmbFrameFlagsDimension & pFrame->receiveFlags )
{
printf( "%ux%u", pFrame->width, pFrame->height );
}
else
{
printf( "?x?" );
}
printf( " Format:0x%08X", pFrame->pixelFormat );
printf( " FPS:" );
if( bFPSValid )
{
printf( "%.2f", dFPS );
}
else
{
printf( "?" );
}
printf( "\n" );
}
if ( g_bRGBValue )
{
// goto image processing
ProcessFrame( pFrame);
}
else if ( FrameInfos_Show != g_eFrameInfos )
{
// Print a dot every frame
printf( "." );
}
fflush( stdout );
// requeue the frame so it can be filled again
VmbCaptureFrameQueue( cameraHandle, pFrame, &FrameCallback );
ReleaseApiLock();
}
//
// Method StartContinuousImageAcquisition
//
// Purpose: starts image acquisition on a given camera
//
// Parameters:
//
// [in] pCameraId zero terminated C string with the camera id for the camera to be used
// [in] eFrameInfos enumeration value for the frame infos to show for received frames
// [in] bEnableColorProcessing toggle for enabling image processing, in this case just swapping red with blue
// [in] bUseAllocAndAnnounce toggle for enabling AllocAndAnnouce
//
// Note: Vimba has to be uninitialized and the camera has to allow access mode full
//
VmbError_t StartContinuousImageAcquisition( const char* pCameraID, FrameInfos eFrameInfos, VmbBool_t bEnableColorProcessing, VmbBool_t bRGBValue, VmbBool_t bUseAllocAndAnnounce )
{
VmbError_t err = VmbErrorSuccess; // The function result
VmbCameraInfo_t *pCameras = NULL; // A list of camera details
VmbUint32_t nCount = 0; // Number of found cameras
VmbUint32_t nFoundCount = 0; // Change of found cameras
VmbAccessMode_t cameraAccessMode = VmbAccessModeFull; // We open the camera with full access
VmbBool_t bIsCommandDone = VmbBoolFalse; // Has a command finished execution
VmbInt64_t nPayloadSize = 0; // The size of one frame
int i = 0; // Counting variable
#ifdef WIN32
LARGE_INTEGER nFrequency;
#endif //WIN32
if( !g_bVimbaStarted )
{
// initialize global state
g_bStreaming = VmbBoolFalse;
g_bAcquiring = VmbBoolFalse;
g_CameraHandle = NULL;
memset( g_Frames, 0, sizeof( g_Frames ));
g_dFrameTime = 0.0;
g_bFrameTimeValid = VmbBoolFalse;
g_nFrameID = 0;
g_bFrameIDValid = VmbBoolFalse;
g_eFrameInfos = eFrameInfos;
g_bRGBValue = bRGBValue;
g_bEnableColorProcessing = bEnableColorProcessing;
g_bUseAllocAndAnnouce = bUseAllocAndAnnounce;
#ifdef WIN32
QueryPerformanceFrequency( &nFrequency );
g_dFrequency = (double)nFrequency.QuadPart;
#endif //WIN32
// Startup Vimba
err = VmbStartup();
// Print the version of Vimba
PrintVimbaVersion();
if ( VmbErrorSuccess == err )
{
g_bVimbaStarted = VmbBoolTrue;
// Is Vimba connected to a GigE transport layer?
DiscoverGigECameras();
// If no camera ID was provided use the first camera found
if ( NULL == pCameraID )
{
// Get the amount of known cameras
err = VmbCamerasList( NULL, 0, &nCount, sizeof *pCameras );
if ( VmbErrorSuccess == err
&& 0 != nCount )
{
pCameras = (VmbCameraInfo_t*)malloc( nCount * sizeof( *pCameras ));
if ( NULL != pCameras )
{
// Actually query all static details of all known cameras without having to open the cameras
// If a new camera was connected since we queried the amount of cameras (nFoundCount > nCount) we can ignore that one
err = VmbCamerasList( pCameras, nCount, &nFoundCount, sizeof *pCameras );
if ( VmbErrorSuccess != err
&& VmbErrorMoreData != err )
{
printf( "%s Could not list cameras. Error code: %d\n", __FUNCTION__, err );
}
else
{
// Use the first camera
if( nFoundCount != 0)
{
pCameraID = pCameras[0].cameraIdString;
}
else
{
err = VmbErrorNotFound;
printf( "%s camera lost. Error code: %d\n", __FUNCTION__, err );
pCameraID = NULL;
}
}
free( pCameras );
pCameras = NULL;
}
else
{
printf( "%s Could not allocate camera list.\n", __FUNCTION__ );
}
}
else
{
printf( "%s Could not list cameras or no cameras present. Error code: %d\n", __FUNCTION__, err );
}
}
if ( NULL != pCameraID )
{
// Open camera
err = VmbCameraOpen( pCameraID, cameraAccessMode, &g_CameraHandle );
if ( VmbErrorSuccess == err )
{
printf("Opening camera with ID: %s\n", pCameraID);
// Set the GeV packet size to the highest possible value
// (In this example we do not test whether this cam actually is a GigE cam)
if ( VmbErrorSuccess == VmbFeatureCommandRun( g_CameraHandle, "GVSPAdjustPacketSize" ))
{
do
{
if ( VmbErrorSuccess != VmbFeatureCommandIsDone( g_CameraHandle,
"GVSPAdjustPacketSize",
&bIsCommandDone ))
{
break;
}
} while ( VmbBoolFalse == bIsCommandDone );
}
if ( VmbErrorSuccess == err )
{
// Evaluate frame size
err = VmbFeatureIntGet( g_CameraHandle, "PayloadSize", &nPayloadSize );
if ( VmbErrorSuccess == err )
{
for(i = 0; i < NUM_FRAMES; i++)
{
g_Frames[i].buffer = ( g_bUseAllocAndAnnouce ) ? NULL : (unsigned char*)malloc( (VmbUint32_t)nPayloadSize );
g_Frames[i].bufferSize = (VmbUint32_t)nPayloadSize;
// Announce Frame
err = VmbFrameAnnounce( g_CameraHandle, &g_Frames[i], (VmbUint32_t)sizeof( VmbFrame_t ));
if ( VmbErrorSuccess != err )
{
free( g_Frames[i].buffer );
memset( &g_Frames[i], 0, sizeof( VmbFrame_t ));
break;
}
}
if ( VmbErrorSuccess == err )
{
// Start Capture Engine
err = VmbCaptureStart( g_CameraHandle );
if ( VmbErrorSuccess == err )
{
g_bStreaming = VmbBoolTrue;
for( i = 0; i < NUM_FRAMES; i++ )
{
// Queue Frame
err = VmbCaptureFrameQueue( g_CameraHandle, &g_Frames[i], &FrameCallback );
if ( VmbErrorSuccess != err )
{
break;
}
}
if ( VmbErrorSuccess == err )
{
// Start Acquisition
err = VmbFeatureCommandRun( g_CameraHandle,"AcquisitionStart" );
if ( VmbErrorSuccess == err )
{
g_bAcquiring = VmbBoolTrue;
}
}
}
}
}
}
}
}
if( VmbErrorSuccess != err )
{
StopContinuousImageAcquisition();
}
}
}
else
{
err = VmbErrorOther;
}
return err;
}
//
// Method: StopContinuousImageAcquisition
//
// Purpose: stops image acquisition that was started with StartContinuousImageAcquisition
//
void StopContinuousImageAcquisition()
{
int i = 0;
if( g_bVimbaStarted )
{
if( NULL != g_CameraHandle )
{
if( g_bAcquiring )
{
// Stop Acquisition
VmbFeatureCommandRun( g_CameraHandle, "AcquisitionStop" );
g_bAcquiring = VmbBoolFalse;
}
if( g_bStreaming )
{
// Stop Capture Engine
VmbCaptureEnd( g_CameraHandle );
g_bStreaming = VmbBoolFalse;
}
// Flush the capture queue
VmbCaptureQueueFlush( g_CameraHandle );
// Ensure that revoking is not interrupted by a dangling frame callback
AquireApiLock();
for( i = 0; i < NUM_FRAMES; i++ )
{
if( NULL != g_Frames[i].buffer )
{
VmbFrameRevoke( g_CameraHandle, &g_Frames[i] );
if ( !g_bUseAllocAndAnnouce )
{
free( g_Frames[i].buffer );
memset( &g_Frames[i], 0, sizeof( VmbFrame_t ));
}
}
}
ReleaseApiLock();
// Close camera
VmbCameraClose ( g_CameraHandle );
g_CameraHandle = NULL;
}
VmbShutdown();
g_bVimbaStarted = VmbBoolFalse;
#ifdef WIN32
CloseHandle( g_hMutex );
#else
pthread_mutex_destroy(&g_Mutex);
#endif
}
}

View File

@@ -0,0 +1,50 @@
/*=============================================================================
Copyright (C) 2012 - 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: AsynchronousGrab.h
Description: The AsynchronousGrab example will grab images asynchronously
using VimbaC.
-------------------------------------------------------------------------------
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 ASYNCHRONOUS_GRAB_H_
#define ASYNCHRONOUS_GRAB_H_
#include <VimbaC/Include/VmbCommonTypes.h>
typedef enum FrameInfos
{
FrameInfos_Off,
FrameInfos_Show,
FrameInfos_Automatic
} FrameInfos;
VmbError_t StartContinuousImageAcquisition( const char* pCameraID, FrameInfos eFrameInfos, VmbBool_t bEnableColorProcessing, VmbBool_t bRGBValue, VmbBool_t bUseAllocAndAnnounce );
void StopContinuousImageAcquisition();
VmbBool_t CreateApiLock();
void DestroyApiLock();
VmbBool_t AquireApiLock();
void ReleaseApiLock();
#endif

View File

@@ -0,0 +1,214 @@
/*=============================================================================
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: program.c
Description: Implementation of main entry point of AsynchronousGrab example
of VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <string.h>
#include <AsynchronousGrab.h>
#include "Common/ErrorCodeToMessage.h"
#ifdef WIN32
#include <windows.h>
BOOL WINAPI consoleHandler( DWORD signal)
{
switch( signal)
{
case CTRL_C_EVENT:
case CTRL_CLOSE_EVENT:
AquireApiLock();
VmbShutdown();
ReleaseApiLock();
}
return TRUE;
}
#endif
int main( int argc, char* argv[] )
{
VmbError_t err = VmbErrorSuccess;
char* pCameraID = NULL; // The ID of the camera to use
FrameInfos eFrameInfos = FrameInfos_Off; // Show frame infos
VmbBool_t bRGBValue = VmbBoolFalse; // Show RGB values
VmbBool_t bEnableColorProcessing = VmbBoolFalse; // Enables color processing of frames
VmbBool_t bUseAllocAndAnnounce = VmbBoolFalse; // Enables use of AllocAndAnnounce
unsigned char bPrintHelp = 0; // Output help?
int i = 0; // Counter for some iteration
char* pParameter = NULL; // The command line parameter
CreateApiLock();
#ifdef WIN32
SetConsoleCtrlHandler(consoleHandler,TRUE);
#endif
printf( "///////////////////////////////////////////\n" );
printf( "/// Vimba API Asynchronous Grab Example ///\n" );
printf( "///////////////////////////////////////////\n\n" );
//////////////////////
//Parse command line//
//////////////////////
for( i = 1; i < argc; ++i )
{
pParameter = argv[i];
if( 0 > strlen( pParameter ))
{
err = VmbErrorBadParameter;
break;
}
if( '/' == pParameter[0] )
{
if( 0 == strcmp( pParameter, "/i" ))
{
if( ( FrameInfos_Off != eFrameInfos )
|| ( bPrintHelp ))
{
err = VmbErrorBadParameter;
break;
}
eFrameInfos = FrameInfos_Show;
}
else if( 0 == strcmp( pParameter, "/r" ))
{
if( bPrintHelp )
{
err = VmbErrorBadParameter;
break;
}
bRGBValue = VmbBoolTrue;
}
else if( 0 == strcmp( pParameter, "/c" ))
{
if ( bPrintHelp )
{
err = VmbErrorBadParameter;
break;
}
bEnableColorProcessing = VmbBoolTrue;
bRGBValue = VmbBoolTrue;
}
else if( 0 == strcmp( pParameter, "/a" ))
{
if( ( FrameInfos_Off != eFrameInfos )
|| ( bPrintHelp ))
{
err = VmbErrorBadParameter;
break;
}
eFrameInfos = FrameInfos_Automatic;
}
else if( 0 == strcmp( pParameter, "/x" ))
{
if ( bPrintHelp )
{
err = VmbErrorBadParameter;
break;
}
bUseAllocAndAnnounce = VmbBoolTrue;
}
else if( 0 == strcmp( pParameter, "/h" ))
{
if( ( NULL != pCameraID )
|| ( bPrintHelp )
|| ( VmbBoolFalse != bEnableColorProcessing )
|| ( VmbBoolFalse != bRGBValue )
|| ( FrameInfos_Off != eFrameInfos ))
{
err = VmbErrorBadParameter;
break;
}
bPrintHelp = 1;
}
else
{
err = VmbErrorBadParameter;
break;
}
}
else
{
if( NULL != pCameraID )
{
err = VmbErrorBadParameter;
break;
}
pCameraID = pParameter;
}
}
//Write out an error if we could not parse the command line
if ( VmbErrorBadParameter == err )
{
printf( "Invalid parameters!\n\n" );
bPrintHelp = 1;
}
//Print out help and end program
if ( bPrintHelp )
{
printf( "Usage: AsynchronousGrab [CameraID] [/i] [/h]\n" );
printf( "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n" );
printf( " /r Convert to RGB and show RGB values\n" );
printf( " /c Enable color processing (includes /r)\n" );
printf( " /i Show frame infos\n" );
printf( " /a Automatically only show frame infos of corrupt frames\n" );
printf( " /x Use AllocAndAnnounceFrame instead of AnnounceFrame\n" );
printf( " /h Print out help\n" );
}
else
{
err = StartContinuousImageAcquisition( pCameraID, eFrameInfos, bEnableColorProcessing, bRGBValue , bUseAllocAndAnnounce);
if ( VmbErrorSuccess == err )
{
printf( "Press <enter> to stop acquisition...\n" );
getchar();
StopContinuousImageAcquisition();
}
if ( VmbErrorSuccess == err )
{
printf( "\nAcquisition stopped.\n" );
}
else
{
printf( "\nAn error occurred: %s\n", ErrorCodeToMessage( err ) );
}
}
ReleaseApiLock();
return err;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,100 @@
UNAME = $(shell uname -m)
ifeq ($(UNAME),i386)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),i486)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),i586)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),i686)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),x86_64)
ARCH = x86
AUTOWORDSIZE = 64
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),amd64)
ARCH = x86
AUTOWORDSIZE = 64
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),armv6l)
ARCH = arm
AUTOWORDSIZE = 32
AUTOFLOATABI = soft
endif
ifeq ($(UNAME),armv7l)
ARCH = arm
AUTOWORDSIZE = 32
AUTOFLOATABI = soft
endif
ifeq ($(UNAME),aarch64)
ARCH = arm
AUTOWORDSIZE = 64
AUTOFLOATABI = hard
endif
#Possible word sizes: 32, 64
WORDSIZE = $(AUTOWORDSIZE)
#Possible float abis: soft, hard
FLOATABI = $(AUTOFLOATABI)
ifneq ($(WORDSIZE),32)
ifneq ($(WORDSIZE),64)
$(error Invalid word size set)
endif
endif
ifneq ($(FLOATABI),soft)
ifneq ($(FLOATABI),hard)
ifneq ($(FLOATABI),ignore)
$(error Invalid float abi set)
endif
endif
endif
#Common tools
PKGCFG = pkg-config
MKDIR = mkdir
RM = rm
CXX = g++
MAKE = make
CP = cp
#Set word size on x86
ifeq ($(ARCH),x86)
ARCH_CFLAGS = -m$(WORDSIZE)
endif
#Configure compiler and linker for soft or hard-float build on ARM
ifeq ($(ARCH),arm)
ifeq ($(FLOATABI),soft)
ARCH_CFLAGS = -marm -mfloat-abi=soft -march=armv4t
else ifeq ($(FLOATABI),hard)
ifeq ($(WORDSIZE),32)
ARCH_CFLAGS = -mthumb -mfloat-abi=hard -march=armv7
else ifeq ($(WORDSIZE),64)
ARCH_CFLAGS = -march=armv8-a
endif
endif
endif
ifeq ($(CONFIG),Debug)
CONFIG_CFLAGS = -O0 -g
else
CONFIG_CFLAGS = -O3
endif
COMMON_CFLAGS = $(CONFIG_CFLAGS) $(ARCH_CFLAGS) -fPIC

View File

@@ -0,0 +1,23 @@
EXAMPLES_DIR = ../..
MAKE_INCLUDE_DIR = $(CURDIR)
include $(MAKE_INCLUDE_DIR)/Common.mk
EXAMPLES = ActionCommands \
AsynchronousGrab \
ForceIP \
ListCameras \
ListFeatures \
ListAncillaryDataFeatures \
SynchronousGrab \
LoadSaveSettings
make_%: $(EXAMPLES_DIR)/%/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Build/Make
clean_%: $(EXAMPLES_DIR)/%/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Build/Make clean
all: $(foreach example,$(EXAMPLES),make_$(example))
clean: $(foreach example,$(EXAMPLES),clean_$(example))

View File

@@ -0,0 +1,14 @@
include $(MAKE_INCLUDE_DIR)/Common.mk
#Compile options needed for VimbaC
VIMBAC_CFLAGS = -I$(VIMBASDK_DIR)
#Linker options needed for VimbaC
VIMBAC_LIBS = -L$(BIN_DIR) -lVimbaC
#By default we copy libVimbaC.so next to the binary
$(BIN_DIR)/libVimbaC.so: $(BIN_DIR)
$(CP) $(VIMBASDK_DIR)/VimbaC/DynamicLib/$(ARCH)_$(WORDSIZE)bit/libVimbaC.so $(BIN_DIR)/
#Operations we have to do in order to prepare VimbaC
VimbaC: $(BIN_DIR)/libVimbaC.so

View File

@@ -0,0 +1,14 @@
include $(MAKE_INCLUDE_DIR)/Common.mk
#Compile options needed for VimbaImageTransform
VIMBAIMAGETRANSFORM_CFLAGS = -I$(VIMBASDK_DIR)/VimbaImageTransform/Include
#Compile options needed for VimbaImageTransform
VIMBAIMAGETRANSFORM_LIBS = -L$(BIN_DIR) -lVimbaImageTransform -Wl,-rpath-link,$(BIN_DIR)
#By default we copy libVimbaImageTransform.so next to the binary
$(BIN_DIR)/libVimbaImageTransform.so: $(BIN_DIR)
$(CP) $(VIMBASDK_DIR)/VimbaImageTransform/DynamicLib/$(ARCH)_$(WORDSIZE)bit/libVimbaImageTransform.so $(BIN_DIR)/
#Operations we have to do in order to prepare VimbaImageTransform
VimbaImageTransform: $(BIN_DIR)/libVimbaImageTransform.so

View File

@@ -0,0 +1,73 @@
/*=============================================================================
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: DiscoverGigECameras.c
Description: Discover GigE cameras if GigE TL is present.
-------------------------------------------------------------------------------
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 <stdio.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <VimbaC/Include/VimbaC.h>
#include "DiscoverGigECameras.h"
// Purpose: Discovers GigE cameras if GigE TL is present.
// Discovery is switched on only once so that the API can detect all currently connected cameras.
VmbError_t DiscoverGigECameras()
{
VmbError_t err = VmbErrorSuccess;
VmbBool_t isGigE = VmbBoolFalse;
err = VmbFeatureBoolGet( gVimbaHandle, "GeVTLIsPresent", &isGigE ); // Is Vimba connected to a GigE transport layer?
if ( VmbErrorSuccess == err )
{
if( VmbBoolTrue == isGigE )
{
err = VmbFeatureIntSet( gVimbaHandle, "GeVDiscoveryAllDuration", 250 ); // Set the waiting duration for discovery packets to return. If not set the default of 150 ms is used.
if( VmbErrorSuccess == err )
{
err = VmbFeatureCommandRun( gVimbaHandle, "GeVDiscoveryAllOnce" ); // Send discovery packets to GigE cameras and wait 250 ms until they are answered
if( VmbErrorSuccess != err )
{
printf( "Could not ping GigE cameras over the network. Reason: %d\n", err );
}
}
else
{
printf( "Could not set the discovery waiting duration. Reason: %d\n", err );
}
}
}
else
{
printf( "Could not query Vimba for the presence of a GigE transport layer. Reason: %d\n\n", err );
}
return err;
}

View File

@@ -0,0 +1,37 @@
/*=============================================================================
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: DiscoverGigECameras.h
Description: Discover GigE cameras if GigE TL is present.
-------------------------------------------------------------------------------
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 DISCOVER_GIGE_CAMERAS_H_
#define DISCOVER_GIGE_CAMERAS_H_
#include <VimbaC/Include/VimbaC.h>
// Purpose: Discovers GigE cameras if GigE TL is present.
// Discovery is switched on only once so that the API can detect all currently connected cameras.
VmbError_t DiscoverGigECameras();
#endif

View File

@@ -0,0 +1,66 @@
/*=============================================================================
Copyright (C) 2014 - 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: ErrorCodeToMessage.h
Description: Convert the error codes to a self-explanatory message.
-------------------------------------------------------------------------------
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 "ErrorCodeToMessage.h"
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eError The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
const char* ErrorCodeToMessage( VmbError_t eError )
{
switch(eError)
{
case VmbErrorSuccess: return "Success.";
case VmbErrorInternalFault: return "Unexpected fault in VmbApi or driver.";
case VmbErrorApiNotStarted: return "API not started.";
case VmbErrorNotFound: return "Not found.";
case VmbErrorBadHandle: return "Invalid handle ";
case VmbErrorDeviceNotOpen: return "Device not open.";
case VmbErrorInvalidAccess: return "Invalid access.";
case VmbErrorBadParameter: return "Bad parameter.";
case VmbErrorStructSize: return "Wrong DLL version.";
case VmbErrorMoreData: return "More data returned than memory provided.";
case VmbErrorWrongType: return "Wrong type.";
case VmbErrorInvalidValue: return "Invalid value.";
case VmbErrorTimeout: return "Timeout.";
case VmbErrorOther: return "TL error.";
case VmbErrorResources: return "Resource not available.";
case VmbErrorInvalidCall: return "Invalid call.";
case VmbErrorNoTL: return "TL not loaded.";
case VmbErrorNotImplemented: return "Not implemented.";
case VmbErrorNotSupported: return "Not supported.";
default: return "Unknown";
}
}

View File

@@ -0,0 +1,44 @@
/*=============================================================================
Copyright (C) 2014 - 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: ErrorCodeToMessage.h
Description: Convert the error codes to a self-explanatory message.
-------------------------------------------------------------------------------
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 ERROR_CODE_TO_MESSAGE_H_
#define ERROR_CODE_TO_MESSAGE_H_
#include "VimbaC/Include/VimbaC.h"
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eError The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
const char* ErrorCodeToMessage( VmbError_t eError );
#endif

View File

@@ -0,0 +1,49 @@
/*=============================================================================
Copyright (C) 2014 - 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: PrintVimbaVersion.h
Description: Print Vimba version.
-------------------------------------------------------------------------------
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 "PrintVimbaVersion.h"
#include <stdio.h>
#include <VimbaC/Include/VimbaC.h>
//
// Prints out the version of the Vimba API
//
void PrintVimbaVersion()
{
VmbVersionInfo_t version_info;
VmbError_t result = VmbVersionQuery( &version_info, sizeof( version_info ));
if( VmbErrorSuccess == result)
{
printf( "Vimba Version Major: %u Minor: %u Patch: %u\n", version_info.major, version_info.minor,version_info.patch );
}
else
{
printf( "VmbVersionQuery failed with Reason: %x\n", result );
}
}

View File

@@ -0,0 +1,36 @@
/*=============================================================================
Copyright (C) 2014 - 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: PrintVimbaVersion.h
Description: Print Vimba version.
-------------------------------------------------------------------------------
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 PRINT_VIMBA_VERSION_H_
#define PRINT_VIMBA_VERSION_H_
//
// Prints out the version of the Vimba API
//
void PrintVimbaVersion();
#endif

View File

@@ -0,0 +1,58 @@
PROJECT_NAME = ForceIP
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES = -D_LITTLE_ENDIAN
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ForceIP.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,232 @@
/*=============================================================================
Copyright (C) 2013 - 2020 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: ForceIP.h
Description: The ForceIP example will assign an IP address to a camera
that is identified by its MAC address. It utilizes only
GenTL features. This approach is useful when a camera has
an invalid IP configuration and cannot be accessed through
the network anymore.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <arpa/inet.h>
#endif
#include <ForceIP.h>
#include <VimbaC/Include/VimbaC.h>
#include "../../Common/PrintVimbaVersion.h"
//
// Converts a hexadecimal MAC address into its decimal representation.
// Leaves decimal addresses untouched.
//
// Parameters:
// [in] strMAC The hexadecimal (with preceding 0x) or decimal MAC
// address to be converted to decimal. As string.
//
// Returns:
// 0 in case of error
// The decimal representation of the MAC address on success as integer
//
unsigned long long mac_addr( const char* strMAC )
{
unsigned long long nMAC;
if ( sscanf( strMAC, "0x%llx", &nMAC )
|| sscanf( strMAC, "%lld", &nMAC ))
{
return nMAC;
}
else
{
return 0;
}
}
// Converts a IP address string into its decimal representation.
//
// Parameters:
// [in] strIP The string representation of the IP
//
// Returns:
// The decimal representation of the IP address as integer.
//
unsigned int ip_addr( const char* strIP )
{
unsigned long ip = inet_addr( strIP );
#ifdef _LITTLE_ENDIAN
ip = ntohl( ip );
#endif
return ip;
}
// Sleeps for the given seconds.
//
// Parameters:
// [in] seconds The number of seconds to sleep
//
void SleepForSeconds( const unsigned int seconds)
{
#ifdef WIN32
Sleep(1000 * seconds);
#else
sleep(seconds);
#endif
}
//
// Starts Vimba API
// Seeks a GigE camera by its MAC address on the network
// Sets the found camera's
// - IP address
// - subnet mask
// - gateway
//
// Parameters:
// [in] strMAC The MAC address of the camera to work on in decimal
// or hex (with preceding 0x) representation
// [in] strIP The desired IP address for the camera
// [in] strSubnet The desired subnet mask of the IP address
// [in] strGateway The desired gateway. Optional, can be 0
//
void ForceIP( char* strMAC, char* strIP, char* strSubnet, char* strGateway )
{
VmbError_t err = VmbErrorSuccess;
VmbBool_t bIsGigE = 0;
VmbHandle_t hCam = NULL;
unsigned long long nMAC = 0;
unsigned long nIP = 0;
unsigned long nSubnet = 0;
unsigned long nGateway = 0;
err = VmbStartup(); // Initialize the Vimba API
PrintVimbaVersion(); // Print Vimba Version
nMAC = mac_addr( strMAC ); // The MAC address of the camera
nIP = ip_addr( strIP ); // The future IP address of the camera
nSubnet = ip_addr( strSubnet ); // The future subnet mask of the camera
nGateway = strGateway != NULL ? ip_addr( strGateway ) : 0; // A possible gateway
if ( VmbErrorSuccess == err )
{
err = VmbFeatureBoolGet( gVimbaHandle, "GeVTLIsPresent", &bIsGigE ); // Is Vimba connected to a GigE transport layer?
if ( VmbErrorSuccess == err )
{
if( bIsGigE )
{
if ( 0 != nMAC )
{
err = VmbFeatureIntSet( gVimbaHandle, "GevDeviceForceMACAddress", nMAC ); // Send MAC address to TL
if ( VmbErrorSuccess == err )
{
err = VmbFeatureIntSet( gVimbaHandle, "GevDeviceForceIPAddress", nIP ); // Send new IP address to TL
if ( VmbErrorSuccess == err )
{
err = VmbFeatureIntSet( gVimbaHandle, "GevDeviceForceSubnetMask", nSubnet ); // Send new subnet mask to TL
if ( VmbErrorSuccess == err )
{
if( 0 != nGateway )
{
err = VmbFeatureIntSet( gVimbaHandle, "GevDeviceForceGateway", nGateway ); // Send gateway address to TL
if ( VmbErrorSuccess != err )
{
printf( "Could not prepare the gateway settings. Reason: %d\n\n", err );
}
}
if ( VmbErrorSuccess == err )
{
err = VmbFeatureCommandRun( gVimbaHandle, "GevDeviceForceIP" ); // Finally execute the command to write all settings to cam
if ( VmbErrorSuccess == err )
{
VmbBool_t isDone = 0;
unsigned int retryCount = 0;
do
{
SleepForSeconds(1);
err = VmbFeatureCommandIsDone( gVimbaHandle, "GevDeviceForceIP", &isDone); // Check if the command is accepted by the camera
}
while(retryCount++, isDone == VmbBoolFalse && err == VmbErrorSuccess && retryCount < 5);
if( isDone == VmbBoolTrue)
{
printf("ForceIP command sent successfully to the camera\n");
}
else
{
printf("ForceIP command could not be completed\n");
}
}
else
{
printf( "Could not set a new IP address. Reason: %d\n\n", err );
}
}
}
else
{
printf( "Could not prepare the subnet settings. Reason: %d\n\n", err );
}
}
else
{
printf( "Could not prepare the IP address settings. Reason: %d\n\n", err );
}
}
else
{
printf( "Could not prepare the MAC address settings. Reason: %d\n\n", err );
}
}
else
{
printf( "Malformed MAC address.\n\n" );
}
}
else
{
printf( "No GigE transport layer present.\n\n" );
}
}
else
{
printf( "Could not query Vimba for the presence of a GigE transport layer. Reason: %d\n\n", err );
}
VmbShutdown(); // Close Vimba
}
else
{
printf( "Could not start system. Error code: %d\n\n", err );
}
}

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (C) 2013 - 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: ForceIP.h
Description: The ForceIP example will assign an IP address to a camera
that is identified by its MAC address. It utilizes only
GenTL features. This approach is useful when a camera has
an invalid IP configuration and cannot be accessed through
the network anymore.
-------------------------------------------------------------------------------
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 FORCE_IP_H_
#define FORCE_IP_H_
//
// Starts Vimba API
// Seeks a GigE camera by its MAC address on the network
// Sets the found camera's
// - IP address
// - subnet mask
// - gateway
//
// Parameters:
// [in] strMAC The MAC address of the camera to work on in decimal
// or hex (with preceding 0x) representation
// [in] strIP The desired IP address for the camera
// [in] strSubnet The desired subnet mask of the IP address
// [in] strGateway The desired gateway. Optional, can be 0
//
void ForceIP( char* strMAC, char* strIP, char* strSubnet, char* strGateway );
#endif

View File

@@ -0,0 +1,67 @@
/*=============================================================================
Copyright (C) 2020 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 ForceIP example of VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <string.h>
#ifndef WIN32
#include <arpa/inet.h>
#else
#include <windows.h>
#endif
#include <ForceIP.h>
int main( int argc, char* argv[] )
{
printf( "\n//////////////////////////////////\n" );
printf( "/// Vimba API Force IP Example ///\n" );
printf( "//////////////////////////////////\n\n" );
if( 4 > argc
|| 5 < argc )
{
printf( "Usage: ForceIP MAC IP Subnet [Gateway]\n\n" );
printf( "Parameters:\n" );
printf( "MAC The MAC address of the camera whose IP address shall be changed.\n" );
printf( " Either hexadecimal with preceding 0x or decimal.\n" );
printf( "IP The new IPv4 address of the camera in numbers and dots notation.\n" );
printf( "Subnet The new network mask of the camera in numbers and dots notation.\n" );
printf( "Gateway The address of a possible gateway if the camera is not connected\n" );
printf( " to the host PC directly.\n\n" );
printf( "For example to change the IP address of a camera with the MAC address 0x0F3101D540\nto 169.254.1.1 in a class B network call:\n\n" );
printf( "ForceIP 0x0F3101D540 169.254.1.1 255.255.0.0\n\n" );
#ifndef WIN32
printf( "To alter cameras in foreign subnets run the program with sudo -E / su -m. \n\n" );
#endif
}
else
{
ForceIP( argv[1], argv[2], argv[3], argc == 5 ? argv[4] : NULL );
}
return 0;
}

View File

@@ -0,0 +1,58 @@
PROJECT_NAME = ListAncillaryDataFeatures
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ListAncillaryDataFeatures.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,389 @@
/*=============================================================================
Copyright (C) 2014 - 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: ListAncillaryDataFeatures.c
Description: The ListAncillaryDataFeatures example will list all available
features of the ancillary data that are found by VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
#include <ListAncillaryDataFeatures.h>
#include <VimbaC/Include/VimbaC.h>
#include <../../Common/PrintVimbaVersion.h>
#include <../../Common/DiscoverGigECameras.h>
// Purpose: Fetches features from the ancillary data. Ancillary data is part of a frame,
// therefore we need to capture a single frame beforehand.
// If no camera ID string was passed we use the first camera found.
//
// Parameter:
// [in ] const char* pStrID The ID of the camera to use. May be NULL.
void ListAncillaryDataFeatures( const char* pStrID )
{
VmbError_t err = VmbErrorSuccess;
VmbHandle_t cameraHandle = NULL; // A handle to our camera
VmbHandle_t ancillaryDataHandle = NULL; // A handle to ancillary data
VmbCameraInfo_t* pCameras = NULL; // A list of camera infos
VmbUint32_t count = 0; // The number of found cameras
VmbFeatureInfo_t* pFeatures = NULL; // A list of ancillary data features
VmbFrame_t frame; // A single frame
VmbInt64_t pls = 0; // The payload size of a frame
VmbCameraInfo_t info; // The name and other information of our camera
VmbBool_t bIsCommandDone = VmbBoolFalse; // Has a command finished execution
// The volatile value of a feature
double doubleValue = 0.0; // A float value
char* pStringValue = NULL; // A string value
VmbBool_t boolValue = VmbBoolFalse; // A bool value
VmbInt64_t intValue = 0; // An int value
VmbUint32_t i = 0;
err = VmbStartup(); // Initialize the Vimba API
PrintVimbaVersion(); // Print Vimba Version
if (VmbErrorSuccess == err)
{
DiscoverGigECameras(); // Seek for GigE cameras on the network
if( NULL == pStrID ) // If no ID was provided use the first camera
{
err = VmbCamerasList ( NULL, // Get the amount of known cameras
0,
&count,
sizeof *pCameras );
if( VmbErrorSuccess == err
&& 0 < count )
{
pCameras = (VmbCameraInfo_t*)malloc( count * sizeof *pCameras );
if( NULL != pCameras )
{
err = VmbCamerasList( pCameras, // Get all known cameras
count,
&count,
sizeof *pCameras );
if( VmbErrorSuccess == err
|| VmbErrorMoreData == err ) // If a new camera was connected since we queried
{ // for the amount of cameras, we can ignore that one
if( 0 < count )
{
info = pCameras[0]; // Copy the camera info of the camera we will use
err = VmbCameraOpen( pCameras[0].cameraIdString, // Finally open the first one
VmbAccessModeFull,
&cameraHandle );
}
else
{
printf( "Camera lost. Error code: %d\n", err );
}
}
else
{
printf( "Could not list cameras. Error code: %d\n", err );
}
free( pCameras );
pCameras = NULL;
}
else
{
printf( "Could not allocate camera list.\n" );
}
}
else
{
printf( "Could not list cameras or no cameras present. Error code: %d\n", err );
}
}
else
{
err = VmbCameraOpen( pStrID, // Open the camera with the given ID
VmbAccessModeFull,
&cameraHandle );
}
if ( NULL != cameraHandle )
{
if( VmbErrorSuccess == err )
{
if ( NULL != pStrID )
{
err = VmbCameraInfoQuery( pStrID, &info, sizeof( VmbCameraInfo_t ) ); // If we haven't queried the camera info yet, we do it now to display the camera name
}
if ( VmbErrorSuccess == err )
{
printf( "Using camera %s\n", info.cameraName );
err = VmbFeatureBoolSet( cameraHandle, "ChunkModeActive", VmbBoolTrue ); // Enable ancillary data
if( VmbErrorSuccess == err )
{
// Set the GeV packet size to the highest possible value
// (In this example we do not test whether this cam actually is a GigE cam)
if ( VmbErrorSuccess == VmbFeatureCommandRun( cameraHandle, "GVSPAdjustPacketSize" ))
{
printf( "Adjusting packet size " ); // Set the highest possible packet size
do
{
if ( VmbErrorSuccess != VmbFeatureCommandIsDone( cameraHandle,
"GVSPAdjustPacketSize",
&bIsCommandDone ))
{
break;
}
#ifdef WIN32
Sleep(200);
#else
usleep(200000);
#endif
printf( "." );
} while ( VmbBoolFalse == bIsCommandDone );
}
printf( "\nCapture a single frame\n" ); // In order to fill the ancillary data we need to fill a frame
err = VmbFeatureIntGet( cameraHandle, "PayloadSize", &pls );
if( VmbErrorSuccess == err )
{
frame.bufferSize = (VmbUint32_t)pls;
frame.buffer = malloc( (VmbUint32_t)pls * sizeof(unsigned char) );
if ( NULL != frame.buffer )
{
err = VmbFrameAnnounce( cameraHandle, &frame, sizeof(VmbFrame_t));
if( VmbErrorSuccess == err)
{
err = VmbCaptureStart ( cameraHandle );
if( VmbErrorSuccess == err )
{
err = VmbCaptureFrameQueue( cameraHandle, &frame, NULL );
if( VmbErrorSuccess == err )
{
err = VmbFeatureCommandRun( cameraHandle, "AcquisitionStart" );
if( VmbErrorSuccess == err )
{
err = VmbCaptureFrameWait( cameraHandle, &frame, 1000 );
if( VmbErrorSuccess == err )
{
if( VmbFrameStatusComplete == frame.receiveStatus )
{
err = VmbAncillaryDataOpen( &frame, &ancillaryDataHandle );
if( VmbErrorSuccess == err )
{
// Query all static details as well as the value of all fetched ancillary data features and print them out.
err = VmbFeaturesList( ancillaryDataHandle, // Get the amount of features
NULL,
0,
&count,
sizeof *pFeatures );
if ( VmbErrorSuccess == err
&& 0 < count )
{
pFeatures = (VmbFeatureInfo_t *)malloc( count * sizeof *pFeatures );
if( NULL != pFeatures )
{
err = VmbFeaturesList( ancillaryDataHandle, // Get the features
pFeatures,
count,
&count,
sizeof *pFeatures );
if( VmbErrorSuccess == err )
{
for( i=0; i<count; ++i )
{
printf( "/// Feature Name: %s\n", ( NULL == pFeatures[i].name ? "" : pFeatures[i].name ));
printf( "/// Display Name: %s\n", ( NULL == pFeatures[i].displayName ? "" : pFeatures[i].displayName ));
printf( "/// Tooltip: %s\n", ( NULL == pFeatures[i].tooltip ? "" : pFeatures[i].tooltip ));
printf( "/// Description: %s\n", ( NULL == pFeatures[i].description ? "" : pFeatures[i].description ));
printf( "/// SNFC Namespace: %s\n", ( NULL == pFeatures[i].sfncNamespace ? "" : pFeatures[i].sfncNamespace ));
printf( "/// Value: " );
switch( pFeatures[i].featureDataType )
{
case VmbFeatureDataBool:
err = VmbFeatureBoolGet( ancillaryDataHandle, pFeatures[i].name, &boolValue );
if( VmbErrorSuccess == err )
{
printf( "%d\n", boolValue );
}
break;
case VmbFeatureDataEnum:
err = VmbFeatureEnumGet( ancillaryDataHandle, pFeatures[i].name, (const char**)&pStringValue );
if ( VmbErrorSuccess == err )
{
printf( "%s\n", pStringValue );
}
break;
case VmbFeatureDataFloat:
err = VmbFeatureFloatGet( ancillaryDataHandle, pFeatures[i].name, &doubleValue );
{
printf( "%f\n", doubleValue );
}
break;
case VmbFeatureDataInt:
err = VmbFeatureIntGet( ancillaryDataHandle, pFeatures[i].name, &intValue );
{
printf( "%lld\n", intValue );
}
break;
case VmbFeatureDataString:
{
VmbUint32_t size = 0;
err = VmbFeatureStringGet( ancillaryDataHandle, pFeatures[i].name, NULL, 0, &size );
if( VmbErrorSuccess == err
&& 0 < size )
{
pStringValue = (char*)malloc( sizeof *pStringValue * (VmbUint32_t)intValue );
if( NULL != pStringValue )
{
err = VmbFeatureStringGet( ancillaryDataHandle, pFeatures[i].name, pStringValue, size, &size );
if( VmbErrorSuccess == err )
{
printf( "%s\n", pStringValue );
}
free( pStringValue );
pStringValue = NULL;
}
else
{
printf( "Could not allocate string.\n" );
}
}
}
break;
case VmbFeatureDataCommand:
default:
printf( "[None]\n" );
break;
}
if( VmbErrorSuccess != err )
{
printf( "Could not get feature value. Error code: %d\n", err );
}
printf ( "\n" );
}
}
else
{
printf( "Could not get features. Error code: %d\n", err );
}
free( pFeatures );
pFeatures = NULL;
}
else
{
printf( "Could not allocate feature list.\n" );
}
}
else
{
printf( "Could not get features or the ancillary data does not provide any. Error code: %d\n", err );
}
}
else
{
printf( "Could not open ancillary data. Error code: %d\n", err );
}
}
else
{
printf( "Captured frame is not complete. Cannot access ancillary data. Frame status: %d.\n(GigE: Are jumbo packets enabled?)\n", frame.receiveStatus );
}
}
else
{
printf( "Could not capture frame. Error code: %d\n", err );
}
free( frame.buffer );
frame.buffer = NULL;
}
else
{
printf( "Could not start acquisition on the camera. Error code: %d\n", err );
}
}
else
{
printf( "Could not queue frame. Error code: %d\n", err );
}
}
else
{
printf( "Could not start capture engine on the host. Error code: %d\n", err );
}
}
else
{
printf( "Could not announce frame. Error code: %d\n", err );
}
}
else
{
printf( "Could not allocate image buffer.\n" );
}
}
else
{
printf( "Could not get payload size. Cannot acquire frame. Error code: %d\n", err );
}
}
else if( VmbErrorNotFound == err )
{
printf( "The camera does not provide ancillary data. Error code: %d\n", err );
}
else
{
printf( "Could not query for the presence of ancillary data. Error code: %d\n", err );
}
}
else
{
printf( "Could not query the camera's name. Error code: %d\n", err );
}
VmbCameraClose( cameraHandle ); // Close the camera
}
else
{
printf( "Could not open camera. Error code: %d\n", err );
}
}
else
{
printf( "No cameras present.\n" );
}
VmbShutdown(); // Close Vimba
}
else
{
printf( "Could not start system. Error code: %d\n", err );
}
}

View File

@@ -0,0 +1,40 @@
/*=============================================================================
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: ListAncillaryDataFeatures.h
Description: The ListAncillaryDataFeatures example will list all available
features of a camera that are found by VimbaC.
-------------------------------------------------------------------------------
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 LIST_ANCILLARY_DATA_FEATURES_H_
#define LIST_ANCILLARY_DATA_FEATURES_H_
// Purpose: Fetches features from the ancillary data. Ancillary data is part of a frame,
// therefore we need to capture a single frame beforehand.
// If no camera ID string was passed we use the first camera found.
//
// Parameter:
// [in ] const char* pStrID The ID of the camera to use. May be NULL.
void ListAncillaryDataFeatures( const char* pStrID );
#endif

View File

@@ -0,0 +1,55 @@
/*=============================================================================
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.c
Description: Main entry point of ListAncillaryDataFeatures example of VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <ListAncillaryDataFeatures.h>
int main( int argc, char* argv[] )
{
printf( "\n" );
printf( "//////////////////////////////////////////////////////\n" );
printf( "/// Vimba API List Ancillary Data Features Example ///\n" );
printf( "//////////////////////////////////////////////////////\n" );
printf( "\n" );
if( 2 < argc )
{
printf( "Usage: ListAncillaryDataFeatures [CameraID]\n\n" );
printf( "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n" );
}
else if( 2 == argc )
{
ListAncillaryDataFeatures( (const char*)argv[1] );
}
else
{
ListAncillaryDataFeatures( NULL );
}
printf( "\n" );
}

View File

@@ -0,0 +1,58 @@
PROJECT_NAME = ListCameras
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ListCameras.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,109 @@
/*=============================================================================
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: ListCameras.c
Description: The ListCameras example will list all available cameras that
are found by VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#include <ListCameras.h>
#include <VimbaC/Include/VimbaC.h>
#include <../../Common/PrintVimbaVersion.h>
#include <../../Common/DiscoverGigECameras.h>
//
// Starts Vimba
// Gets all connected cameras
// And prints out information about the camera name, model name, serial number, ID and the corresponding interface ID
//
void ListCameras()
{
VmbError_t err = VmbErrorSuccess;
VmbCameraInfo_t * pCameras = NULL;
VmbUint32_t i = 0;
VmbUint32_t nCount = 0;
VmbUint32_t nFoundCount = 0;
err = VmbStartup(); // Initialize the Vimba API
PrintVimbaVersion(); // Print Vimba Version
if ( VmbErrorSuccess == err )
{
DiscoverGigECameras();
err = VmbCamerasList( NULL, 0, &nCount, sizeof *pCameras ); // Get the amount of known cameras
if ( VmbErrorSuccess == err
&& nCount != 0 )
{
printf( "Cameras found: %d\n\n", nCount );
pCameras = (VmbCameraInfo_t*)malloc( sizeof *pCameras * nCount );
if ( NULL != pCameras )
{
err = VmbCamerasList( pCameras, nCount, &nFoundCount, sizeof *pCameras ); // Query all static details of all known cameras
// Without having to open the cameras
if( VmbErrorSuccess == err
|| VmbErrorMoreData == err )
{
if( nFoundCount < nCount) // If a new camera was connected since we queried
{ // the amount of cameras, we can ignore that one
nCount = nFoundCount;
}
for ( i=0; i<nCount; ++i ) // And print them out
{
printf( "/// Camera Name: %s\n/// Model Name: %s\n/// Camera ID: %s\n/// Serial Number: %s\n/// @ Interface ID: %s\n\n\n",
pCameras[i].cameraName,
pCameras[i].modelName,
pCameras[i].cameraIdString,
pCameras[i].serialString,
pCameras[i].interfaceIdString );
}
}
else
{
printf( "Could not retrieve camera list. Error code: %d\n", err );
}
free( pCameras );
pCameras = NULL;
}
else
{
printf( "Could not allocate camera list.\n" );
}
}
else
{
printf( "Could not list cameras or no cameras present. Error code: %d\n", err );
}
VmbShutdown(); // Close Vimba
}
else
{
printf( "Could not start system. Error code: %d\n", err );
}
}

View File

@@ -0,0 +1,39 @@
/*=============================================================================
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: ListCameras.h
Description: The ListCameras example will list all available cameras that
are found by VimbaC.
-------------------------------------------------------------------------------
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 LIST_CAMERAS_H_
#define LIST_CAMERAS_H_
//
// Starts Vimba
// Gets all connected cameras
// And prints out information about the camera name, model name, serial number, ID and the corresponding interface ID
//
void ListCameras();
#endif

View File

@@ -0,0 +1,46 @@
/*=============================================================================
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 ListCameras example of VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <ListCameras.h>
int main( int argc, char* argv[] )
{
printf( "//////////////////////////////////////\n" );
printf( "/// Vimba API List Cameras Example ///\n" );
printf( "//////////////////////////////////////\n\n" );
if ( 1 < argc )
{
printf( "No parameters expected. Execution will not be affected by the provided parameter(s).\n\n" );
}
ListCameras();
return 0;
}

View File

@@ -0,0 +1,58 @@
PROJECT_NAME = ListFeatures
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ListFeatures.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,250 @@
/*=============================================================================
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: ListFeatures.cpp
Description: The ListFeatures example will list all available features of a
camera that are found by VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#include <ListFeatures.h>
#include <VimbaC/Include/VimbaC.h>
#include <../../Common/PrintVimbaVersion.h>
#include <../../Common/DiscoverGigECameras.h>
//
// Prints out all features and their values and details of a given camera.
// If no camera ID is provided, the first camera will be used.
// Starts and stops the API
// Opens and closes the camera
//
// Parameters:
// [in] pStrID The ID of the camera to work
//
void ListFeatures( const char *pStrID )
{
VmbError_t err = VmbErrorSuccess;
VmbHandle_t hCamera = NULL; // A handle to our camera
VmbCameraInfo_t* pCameras = NULL; // A list of camera infos
VmbUint32_t nCount = 0; // The number of found cameras
VmbFeatureInfo_t *pFeatures = NULL; // A list of static details of camera features
// The changeable value of a feature
VmbInt64_t nValue = 0; // An int value
double fValue = 0.0; // A float value
char *pStrValue = NULL; // A string value
VmbBool_t bValue = VmbBoolFalse; // A bool value
VmbUint32_t i = 0;
err = VmbStartup(); // Initialize the Vimba API
PrintVimbaVersion(); // Print Vimba Version
if ( VmbErrorSuccess == err )
{
DiscoverGigECameras();
if ( NULL == pStrID ) // If no ID was provided use the first camera
{
err = VmbCamerasList( NULL, // Get the amount of known cameras
0,
&nCount,
sizeof *pCameras );
if ( VmbErrorSuccess == err
&& 0 < nCount )
{
pCameras = (VmbCameraInfo_t*)malloc( nCount * sizeof *pCameras );
if ( NULL != pCameras )
{
err = VmbCamerasList( pCameras, // Get all known cameras
nCount,
&nCount,
sizeof *pCameras );
if ( VmbErrorSuccess == err
|| VmbErrorMoreData == err ) // If a new camera was connected since we queried
{ // for the amount of cameras, we can ignore that one
if( 0 < nCount )
{
err = VmbCameraOpen( pCameras[0].cameraIdString, // Finally open the first one
VmbAccessModeFull,
&hCamera );
}
else
{
printf( "Camera lost.\n" );
}
}
else
{
printf( "Could not list cameras. Error code: %d\n", err );
}
free( pCameras );
pCameras = NULL;
}
else
{
printf( "Could not allocate camera list.\n" );
}
}
else
{
printf( "Could not list cameras or no cameras present. Error code: %d\n", err );
}
}
else
{
err = VmbCameraOpen( pStrID, // Open the camera with the given ID
VmbAccessModeFull,
&hCamera );
}
// Query all static details as well as the value of all fetched features and print them out.
if ( VmbErrorSuccess == err )
{
err = VmbFeaturesList( hCamera, // Get the amount of features
NULL,
0,
&nCount,
sizeof *pFeatures );
if ( VmbErrorSuccess == err
&& 0 < nCount )
{
pFeatures = (VmbFeatureInfo_t *)malloc( nCount * sizeof *pFeatures );
if ( NULL != pFeatures )
{
err = VmbFeaturesList( hCamera, // Get the features
pFeatures,
nCount,
&nCount,
sizeof *pFeatures );
if ( VmbErrorSuccess == err )
{
for ( i=0; i<nCount; ++i )
{
printf( "/// Feature Name: %s\n", ( NULL == pFeatures[i].name ? "" : pFeatures[i].name ));
printf( "/// Display Name: %s\n", ( NULL == pFeatures[i].displayName ? "" : pFeatures[i].displayName ));
printf( "/// Tooltip: %s\n", ( NULL == pFeatures[i].tooltip ? "" : pFeatures[i].tooltip ));
printf( "/// Description: %s\n", ( NULL == pFeatures[i].description ? "" : pFeatures[i].description ));
printf( "/// SNFC Namespace: %s\n", ( NULL == pFeatures[i].sfncNamespace ? "" : pFeatures[i].sfncNamespace ));
printf( "/// Value: " );
switch ( pFeatures[i].featureDataType )
{
case VmbFeatureDataBool:
err = VmbFeatureBoolGet( hCamera, pFeatures[i].name, &bValue );
if ( VmbErrorSuccess == err )
{
printf( "%d\n", bValue );
}
break;
case VmbFeatureDataEnum:
err = VmbFeatureEnumGet( hCamera, pFeatures[i].name, (const char**)&pStrValue );
if ( VmbErrorSuccess == err )
{
printf( "%s\n", pStrValue );
}
break;
case VmbFeatureDataFloat:
err = VmbFeatureFloatGet( hCamera, pFeatures[i].name, &fValue );
{
printf( "%f\n", fValue );
}
break;
case VmbFeatureDataInt:
err = VmbFeatureIntGet( hCamera, pFeatures[i].name, &nValue );
{
printf( "%lld\n", nValue );
}
break;
case VmbFeatureDataString:
{
VmbUint32_t nSize = 0;
err = VmbFeatureStringGet( hCamera, pFeatures[i].name, NULL, 0, &nSize );
if ( VmbErrorSuccess == err
&& 0 < nSize )
{
pStrValue = (char*)malloc( sizeof *pStrValue * nSize );
if ( NULL != pStrValue )
{
err = VmbFeatureStringGet( hCamera, pFeatures[i].name, pStrValue, nSize, &nSize );
if ( VmbErrorSuccess == err )
{
printf( "%s\n", pStrValue );
}
free( pStrValue );
pStrValue = NULL;
}
else
{
printf( "Could not allocate string.\n" );
}
}
}
break;
case VmbFeatureDataCommand:
default:
printf( "[None]\n" );
break;
}
if ( VmbErrorSuccess != err )
{
printf( "Could not get feature value. Error code: %d\n", err );
}
printf( "\n" );
}
}
else
{
printf( "Could not get features. Error code: %d\n", err );
}
free(pFeatures);
pFeatures = NULL;
}
else
{
printf( "Could not allocate feature list.\n" );
}
}
else
{
printf( "Could not get features or the camera does not provide any. Error code: %d\n", err );
}
VmbCameraClose( hCamera ); // Close the camera
}
else
{
printf( "Could not open camera. Error code: %d\n", err );
}
VmbShutdown(); // Close Vimba
}
else
{
printf( "Could not start system. Error code: %d\n", err );
}
}

View File

@@ -0,0 +1,43 @@
/*=============================================================================
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: ListFeatures.h
Description: The ListFeatures example will list all available features of a
camera that are found by VimbaC.
-------------------------------------------------------------------------------
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 LIST_FEATURES_H_
#define LIST_FEATURES_H_
//
// Prints out all features and their values and details of a given camera.
// If no camera ID is provided, the first camera will be used.
// Starts and stops the API
// Opens and closes the camera
//
// Parameters:
// [in] pStrID The ID of the camera to work
//
void ListFeatures( const char *pStrID );
#endif

View File

@@ -0,0 +1,55 @@
/*=============================================================================
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 ListFeatures example of VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <ListFeatures.h>
int main( int argc, char* argv[] )
{
printf( "\n" );
printf( "///////////////////////////////////////\n" );
printf( "/// Vimba API List Features Example ///\n" );
printf( "///////////////////////////////////////\n" );
printf( "\n" );
if( 2 < argc )
{
printf( "Usage: ListFeatures [CameraID]\n\n" );
printf( "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n" );
}
else if ( 2 == argc )
{
ListFeatures( (const char*)argv[1] );
}
else
{
ListFeatures( NULL );
}
printf( "\n" );
}

View File

@@ -0,0 +1,56 @@
PROJECT_NAME = LoadSaveSettings
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,73 @@
/*=============================================================================
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: DiscoverGigECameras.c
Description: Discover GigE cameras if GigE TL is present.
-------------------------------------------------------------------------------
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 <stdio.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <VimbaC/Include/VimbaC.h>
#include "DiscoverGigECameras.h"
// Purpose: Discovers GigE cameras if GigE TL is present.
// Discovery is switched on only once so that the API can detect all currently connected cameras.
VmbError_t DiscoverGigECameras()
{
VmbError_t err = VmbErrorSuccess;
VmbBool_t isGigE = VmbBoolFalse;
err = VmbFeatureBoolGet( gVimbaHandle, "GeVTLIsPresent", &isGigE ); // Is Vimba connected to a GigE transport layer?
if ( VmbErrorSuccess == err )
{
if( VmbBoolTrue == isGigE )
{
err = VmbFeatureIntSet( gVimbaHandle, "GeVDiscoveryAllDuration", 250 ); // Set the waiting duration for discovery packets to return. If not set the default of 150 ms is used.
if( VmbErrorSuccess == err )
{
err = VmbFeatureCommandRun( gVimbaHandle, "GeVDiscoveryAllOnce" ); // Send discovery packets to GigE cameras and wait 250 ms until they are answered
if( VmbErrorSuccess != err )
{
printf( "Could not ping GigE cameras over the network. Reason: %d\n", err );
}
}
else
{
printf( "Could not set the discovery waiting duration. Reason: %d\n", err );
}
}
}
else
{
printf( "Could not query Vimba for the presence of a GigE transport layer. Reason: %d\n\n", err );
}
return err;
}

View File

@@ -0,0 +1,37 @@
/*=============================================================================
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: DiscoverGigECameras.h
Description: Discover GigE cameras if GigE TL is present.
-------------------------------------------------------------------------------
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 DISCOVER_GIGE_CAMERAS_H_
#define DISCOVER_GIGE_CAMERAS_H_
#include <VimbaC/Include/VimbaC.h>
// Purpose: Discovers GigE cameras if GigE TL is present.
// Discovery is switched on only once so that the API can detect all currently connected cameras.
VmbError_t DiscoverGigECameras();
#endif

View File

@@ -0,0 +1,47 @@
/*=============================================================================
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: PrintVimbaVersion.h
Description: Print Vimba version.
-------------------------------------------------------------------------------
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 "PrintVimbaVersion.h"
#include <stdio.h>
#include <VimbaC/Include/VimbaC.h>
// Purpose: Prints the Vimba version information.
void PrintVimbaVersion()
{
VmbVersionInfo_t version_info;
VmbError_t result = VmbVersionQuery( &version_info, sizeof( version_info ));
if( VmbErrorSuccess == result)
{
printf( "Vimba Version Major: %u Minor: %u Patch: %u\n", version_info.major, version_info.minor,version_info.patch );
}
else
{
printf( "VmbVersionQuery failed with Reason: %x", result );
}
}

View File

@@ -0,0 +1,34 @@
/*=============================================================================
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: PrintVimbaVersion.h
Description: Print Vimba version.
-------------------------------------------------------------------------------
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 PRINT_VIMBA_VERSION_H_
#define PRINT_VIMBA_VERSION_H_
// Purpose: Prints the Vimba version information.
void PrintVimbaVersion();
#endif

View File

@@ -0,0 +1,213 @@
/*=============================================================================
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.c
Description: Main entry point of LoadSaveSettings example of VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#include <VimbaC/Include/VimbaC.h>
#include <DiscoverGigECameras.h>
int main( int argc, char *argv[] )
{
VmbError_t err = VmbErrorSuccess;
VmbUint32_t nCount = 0;
VmbCameraInfo_t *pCameras = NULL;
VmbHandle_t handle = NULL;
const char *fileName = "current_settings.xml";
const char *cameraId = NULL;
// prepare settings struct to determine behaviour
// during loading or saving operation
// (This is optional. Passing NULL triggers default settings)
VmbFeaturePersistSettings_t settings;
settings.loggingLevel = 4; // full loggin details (trace, debug, warning, error and info messages)
settings.maxIterations = 5; // how many iterations during loading shall be performed at max
// (comparing desired with device value. in case of difference new iteration will be executed)
settings.persistType = VmbFeaturePersistNoLUT; // determines which features shall be considered
// NoLUT means: all features except for lookUp table features
printf( "\n" );
printf( "////////////////////////////////////////////\n" );
printf( "/// Vimba API Load/Save Settings Example ///\n" );
printf( "////////////////////////////////////////////\n" );
printf( "\n" );
// start VimbaC API
err = VmbStartup();
if( VmbErrorSuccess != err )
{
printf( "Could not start Vimba [error code: %i]\n", err );
return err;
}
printf( "--> VimbaC has been started\n" );
// check for GigE cameras
err = DiscoverGigECameras();
if( VmbErrorSuccess != err )
{
VmbShutdown();
printf( "Could discover GigE cameras [error code: %i]\n", err );
return err;
}
// get amount of connected cameras
err = VmbCamerasList( NULL, 0, &nCount, sizeof(*pCameras) );
if( VmbErrorSuccess != err )
{
VmbShutdown();
printf( "Could not retrieve number of cameras [error code: %i]\n", err );
return err;
}
// in case no camera is connected
if( 0 == nCount )
{
VmbShutdown();
printf( "No Camera found [error code: %i]\n", err );
return err;
}
// allocate space for camera list
pCameras = (VmbCameraInfo_t *) malloc( nCount * sizeof(*pCameras) );
if( NULL == pCameras )
{
VmbShutdown();
printf( "No Camera found [error code: %i]\n", err );
return VmbErrorOther;
}
// retrieve camera list from Vimba
err = VmbCamerasList( pCameras, nCount, &nCount, sizeof(*pCameras) );
if( VmbErrorSuccess != err )
{
VmbShutdown();
printf( "Could not retrieve info pointers for connected cameras [error code: %i]\n", err );
return err;
}
// get camera id string
cameraId = pCameras[0].cameraIdString;
if( NULL == cameraId )
{
VmbShutdown();
printf( "Could not retrieve camera id [error code: %i]\n", VmbErrorOther );
return err;
}
// open camera (first in list)
err = VmbCameraOpen( cameraId, VmbAccessModeFull, &handle );
if( VmbErrorSuccess != err )
{
VmbShutdown();
printf( "Could not open camera in Full Access mode [error code: %i]\n", err );
return err;
}
printf( "--> Camera with id '%s' has been opened\n", cameraId );
// save current camera feature values
err = VmbCameraSettingsSave( handle, fileName, NULL, 0 );
if( VmbErrorSuccess != err )
{
printf( "Could not save feature values to given XML file '%s' [error code: %i]\n", fileName, err );
err = VmbCameraClose( handle );
if( VmbErrorSuccess != err )
{
printf( "Could not close camera [error code: %i]\n", err );
}
VmbShutdown();
return err;
}
printf( "--> Camera settings have been saved\n" );
// set all feature values to factory default
err = VmbFeatureEnumSet( handle, "UserSetSelector", "Default" );
if( VmbErrorSuccess != err )
{
printf( "Could not set feature value 'UserSetSelector' to 'Default' [error code: %i]\n", err );
err = VmbCameraClose( handle );
if( VmbErrorSuccess != err )
{
printf( "Could not close camera [error code: %i]\n", err );
}
VmbShutdown();
return err;
}
err = VmbFeatureCommandRun( handle, "UserSetLoad" );
if( VmbErrorSuccess != err )
{
printf( "Could not run 'UserSetLoad' command [error code: %i]\n", err );
err = VmbCameraClose( handle );
if( VmbErrorSuccess != err )
{
printf( "Could not close camera [error code: %i]\n", err );
}
VmbShutdown();
return err;
}
printf( "--> All feature values have been restored to default\n" );
// load feature values to selected camera from xml file
err = VmbCameraSettingsLoad( handle, fileName, &settings, sizeof(settings) );
if( VmbErrorSuccess != err )
{
printf( "Could not load feature values from given XML file '%s' [error code: %i]\n", fileName, err );
err = VmbCameraClose( handle );
if( VmbErrorSuccess != err )
{
printf( "Could not close camera [error code: %i]\n", err );
}
VmbShutdown();
return err;
}
printf( "--> Feature values have been loaded from given XML file\n" );
// close camera
err = VmbCameraClose( handle );
if( VmbErrorSuccess != err )
{
printf( "Could not close camera [error code: %i]\n", err );
VmbShutdown();
return err;
}
printf( "--> Camera has been closed\n" );
// shutdown VimbaC API
VmbShutdown();
printf( "--> VimbaC has been stopped\n" );
// free allocated space for camera list
free( pCameras );
pCameras = NULL;
return 0;
}

View File

@@ -0,0 +1,59 @@
PROJECT_NAME = SynchronousGrab
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/Bitmap.o \
$(OBJ_DIR)/SynchronousGrab.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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,267 @@
/*=============================================================================
Copyright (C) 2013 - 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: Bitmap.c
Description: The bitmap class represents a MS(R) Windows(TM) bitmap version 3
-------------------------------------------------------------------------------
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Bitmap.h>
#define THREE_CHANNEL 0xC
#define BMP_HEADER_SIZE 54
#define ALIGNMENT_SIZE 4
//
// Creates a MS Windows bitmap with header and color palette.
// Fills it with the content of the given byte buffer
//
// Parameters:
// [out] pBitmap A pointer to an AVTBitmap that will get filled
// [in] pBuffer The buffer that will be used to fill the created bitmap
//
// Returns:
// 0 in case of error
// 1 in case of success
//
unsigned char AVTCreateBitmap( AVTBitmap * const pBitmap, const void* pBuffer )
{
unsigned char nNumColors = 0; // Number of colors of our image
unsigned char nPadLength = 0; // The padding we need to align the bitmap ALIGNMENT_SIZE
unsigned long nPaletteSize = 0; // The size of the bitmap's palette
unsigned long nHeaderSize = 0; // The size of the bitmap's header
unsigned long nFileSize = 0; // The size of the bitmap file
unsigned char* pBitmapBuffer = 0; // A buffer we use for creating the bitmap
unsigned char* pCurBitmapBuf = 0; // A cursor to move over "pBitmapBuffer"
unsigned char* pCurSrc = 0; // A cursor to move over the given buffer "pBuffer"
unsigned long px = 0; // A single pixel for storing transformed color information
unsigned long x = 0; // The horizontal position within our image
unsigned long y = 0; // The vertical position within our image
unsigned long i = 0; // Counter for some iteration
// The bitmap header
char fileHeader[14] = { 'B','M', // Default
0,0,0,0, // File size
0,0,0,0, // Reserved
0,0,0,0 }; // Offset to image content
char infoHeader[40] = { 40,0,0,0, // Size of info header
0,0,0,0, // Width
0,0,0,0, // Height
1,0, // Default
0, 0 }; // bpp
if ( NULL == pBitmap
|| 0 == pBitmap->bufferSize
|| 0 == pBitmap->width
|| 0 == pBitmap->height )
{
return 0;
}
if ( pBitmap->colorCode == ( pBitmap->colorCode & THREE_CHANNEL ))
{
nNumColors = 3;
}
else
{
nNumColors = 1;
}
// Bitmap padding always is a multiple of four Bytes. If data is not we need to pad with zeros.
nPadLength = ( pBitmap->width * nNumColors ) % ALIGNMENT_SIZE;
if ( 0 != nPadLength )
{
nPadLength = ALIGNMENT_SIZE - nPadLength;
}
if ( ColorCodeRGB24 != pBitmap->colorCode )
{
nPaletteSize = 256;
}
nHeaderSize = BMP_HEADER_SIZE + nPaletteSize * 4;
pBitmapBuffer = (unsigned char*)malloc( nHeaderSize + pBitmap->bufferSize + (nPadLength * pBitmap->height ));
nFileSize = nHeaderSize + pBitmap->bufferSize + ( nPadLength * pBitmap->height );
// File size
fileHeader[ 2] = (char)( nFileSize );
fileHeader[ 3] = (char)( nFileSize >> 8 );
fileHeader[ 4] = (char)( nFileSize >> 16 );
fileHeader[ 5] = (char)( nFileSize >> 24 );
// Offset to image content
fileHeader[10] = (char)( nHeaderSize );
fileHeader[11] = (char)( nHeaderSize >> 8 );
fileHeader[12] = (char)( nHeaderSize >> 16 );
fileHeader[13] = (char)( nHeaderSize >> 24 );
// Width
infoHeader[ 4] = (char)( pBitmap->width );
infoHeader[ 5] = (char)( pBitmap->width >> 8 );
infoHeader[ 6] = (char)( pBitmap->width >> 16 );
infoHeader[ 7] = (char)( pBitmap->width >> 24 );
// Height (has to be negative for a top down image)
infoHeader[ 8] = (char)( -(long)pBitmap->height );
infoHeader[ 9] = (char)( -(long)pBitmap->height >> 8 );
infoHeader[10] = (char)( -(long)pBitmap->height >> 16 );
infoHeader[11] = (char)( -(long)pBitmap->height >> 24 );
// bpp
infoHeader[14] = 8 * nNumColors;
// Image size
infoHeader[20] = (char)( pBitmap->bufferSize );
infoHeader[21] = (char)( pBitmap->bufferSize >> 8 );
infoHeader[22] = (char)( pBitmap->bufferSize >> 16 );
infoHeader[23] = (char)( pBitmap->bufferSize >> 24 );
// Palette size
infoHeader[32] = (char)( nPaletteSize );
infoHeader[33] = (char)( nPaletteSize >> 8 );
infoHeader[34] = (char)( nPaletteSize >> 16 );
infoHeader[35] = (char)( nPaletteSize >> 24 );
// Used colors
infoHeader[36] = (char)( nPaletteSize );
infoHeader[37] = (char)( nPaletteSize >> 8 );
infoHeader[38] = (char)( nPaletteSize >> 16 );
infoHeader[39] = (char)( nPaletteSize >> 24 );
// Write header
pCurBitmapBuf = pBitmapBuffer;
memcpy( pCurBitmapBuf, fileHeader, 14 );
pCurBitmapBuf += 14;
memcpy( pCurBitmapBuf, infoHeader, 40 );
pCurBitmapBuf += 40;
for( i = 0; i < nPaletteSize; ++i )
{
pCurBitmapBuf[0] = (char)(i);
pCurBitmapBuf[1] = (char)(i);
pCurBitmapBuf[2] = (char)(i);
pCurBitmapBuf[3] = 0;
pCurBitmapBuf += 4;
}
// RGB -> BGR (a Windows bitmap is BGR)
if ( ColorCodeRGB24 == pBitmap->colorCode )
{
pCurSrc = (unsigned char*)pBuffer;
for ( y=0; y<pBitmap->height; ++y, pCurBitmapBuf+=nPadLength )
{
for ( x = 0;
x < pBitmap->width;
++x,
pCurSrc += 3,
pCurBitmapBuf += 3 )
{
px = 0;
// Create a 4 Byte structure to store ARGB (we don't use A)
px = px | ( pCurSrc[0] << 16 ) | ( pCurSrc[1] << 8 ) | pCurSrc[2];
// Due to endianess ARGB is stored as BGRA
// and we only have to write the first three Bytes
memcpy( pCurBitmapBuf, &px, 3 );
}
// Add padding at the end of each row
memset( pCurBitmapBuf, 0, nPadLength );
}
pBitmap->colorCode = ColorCodeBGR24;
}
// Mono8
else
{
if ( 0 == nPadLength )
{
memcpy( pCurBitmapBuf, pBuffer, pBitmap->bufferSize );
}
else
{
pCurSrc = (unsigned char*)pBuffer;
for ( y=0;
y<pBitmap->height;
++y,
pCurSrc += pBitmap->width * nNumColors )
{
// Write a single row of colored pixels
memcpy( pCurBitmapBuf, pCurSrc, pBitmap->width * nNumColors );
pCurBitmapBuf += pBitmap->width * nNumColors;
// Write padding pixels
memset( pCurBitmapBuf, 0, nPadLength );
pCurBitmapBuf += nPadLength;
}
}
}
pBitmap->buffer = pBitmapBuffer;
pBitmap->bufferSize = nFileSize;
return 1;
}
//
// Releases (frees) a given bitmap
//
// Parameters:
// [in, out] pBitmap The bitmap whose memory will be freed
//
// Returns:
// 0 in case of error
// 1 in case of success
//
unsigned char AVTReleaseBitmap( AVTBitmap * const pBitmap )
{
if ( NULL != pBitmap
&& NULL != pBitmap->buffer
&& 0 < pBitmap->bufferSize )
{
free( pBitmap->buffer );
pBitmap->buffer = NULL;
return 1;
}
return 0;
}
//
// Writes a given bitmap to file
//
// Parameters:
// [in] pBitmap The AVTBitmap to write to file
// [in] pFileName The destination (complete path) where to write the bitmap to
//
// Returns:
// 0 in case of error
// 1 in case of success
//
unsigned char AVTWriteBitmapToFile( AVTBitmap const * const pBitmap, char const * const pFileName )
{
FILE *file;
if ( NULL != pBitmap
&& NULL != pBitmap->buffer
&& NULL != pFileName )
{
file = fopen( pFileName, "wb" );
fwrite( pBitmap->buffer, 1, pBitmap->bufferSize, file );
fclose( file );
return 1;
}
return 0;
}

View File

@@ -0,0 +1,87 @@
/*=============================================================================
Copyright (C) 2013 - 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: Bitmap.h
Description: The bitmap class represents a MS(R) Windows(TM) bitmap version 3
-------------------------------------------------------------------------------
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_BITMAP_H_
#define AVT_BITMAP_H_
typedef enum
{
ColorCodeMono8 = 1,
ColorCodeMono16 = 2,
ColorCodeBGR24 = 4,
ColorCodeRGB24 = 8
} ColorCode;
typedef struct
{
void* buffer;
unsigned long bufferSize;
unsigned long width;
unsigned long height;
ColorCode colorCode;
} AVTBitmap;
//
// Creates a MS Windows bitmap with header and color palette.
// Fills it with the content of the given byte buffer
//
// Parameters:
// [out] pBitmap A pointer to an AVTBitmap that will get filled
// [in] pBuffer The buffer that will be used to fill the created bitmap
//
// Returns:
// 0 in case of error
// 1 in case of success
//
unsigned char AVTCreateBitmap( AVTBitmap * const pBitmap, const void* pBuffer );
//
// Releases (frees) a given bitmap
//
// Parameters:
// [in, out] pBitmap The bitmap whose memory will be freed
//
// Returns:
// 0 in case of error
// 1 in case of success
//
unsigned char AVTReleaseBitmap( AVTBitmap * const pBitmap );
//
// Writes a given bitmap to file
//
// Parameters:
// [in] pBitmap The AVTBitmap to write to file
// [in] pFileName The destination (complete path) where to write the bitmap to
//
// Returns:
// 0 in case of error
// 1 in case of success
//
unsigned char AVTWriteBitmapToFile( AVTBitmap const * const pBitmap, char const * const pFileName );
#endif

View File

@@ -0,0 +1,318 @@
/*=============================================================================
Copyright (C) 2012 - 2013 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: SynchronousGrab.cpp
Description: The SynchronousGrab example will grab a single image
synchronously and save it to a file using VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <VimbaC/Include/VimbaC.h>
#include "../../Common/PrintVimbaVersion.h"
#include "../../Common/DiscoverGigECameras.h"
#include <SynchronousGrab.h>
#include <Bitmap.h>
//
// Starts Vimba API
// Opens the given camera, if no camera ID was provided, the first camera found will be used
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Acquires one image synchronously
// Writes the image as bitmap to file
// Closes the camera in case of failure
//
// Parameters:
// [in] pCameraID The ID of the camera to work on. Can be NULL.
// [in] pFileName The path of the bitmap where the image is saved to
//
// Returns:
// An API status code
//
VmbError_t SynchronousGrab( const char* pCameraID, const char* pFileName )
{
VmbError_t err = VmbStartup(); // Initialize the Vimba API
VmbCameraInfo_t *pCameras = NULL; // A list of camera details
VmbUint32_t nCount = 0; // Number of found cameras
VmbUint32_t nFoundCount = 0; // Change of found cameras
const VmbUint32_t nTimeout = 2000; // Timeout for Grab
VmbAccessMode_t cameraAccessMode = VmbAccessModeFull;// We open the camera with full access
VmbHandle_t cameraHandle = NULL; // A handle to our camera
VmbBool_t bIsCommandDone = VmbBoolFalse; // Has a command finished execution
VmbFrame_t frame; // The frame we capture
const char* pPixelFormat = NULL; // The pixel format we use for acquisition
VmbInt64_t nPayloadSize = 0; // The size of one frame
AVTBitmap bitmap; // The bitmap we create
PrintVimbaVersion();
if ( VmbErrorSuccess == err )
{
// Is Vimba connected to a GigE transport layer?
DiscoverGigECameras();
// If no camera ID was provided use the first camera found
if ( NULL == pCameraID )
{
// Get the amount of known cameras
err = VmbCamerasList( NULL, 0, &nCount, sizeof *pCameras );
if ( VmbErrorSuccess == err
&& 0 < nCount )
{
pCameras = (VmbCameraInfo_t*)malloc( nCount * sizeof( *pCameras ));
if ( NULL != pCameras )
{
// Actually query all static details of all known cameras without having to open the cameras
// If a new camera was connected since we queried the amount of cameras (nFoundCount > nCount) we can ignore that one
err = VmbCamerasList( pCameras, nCount, &nFoundCount, sizeof *pCameras );
if ( VmbErrorSuccess != err
&& VmbErrorMoreData != err )
{
printf( "Could not list cameras. Error code: %d\n", err );
}
else
{
// Use the first camera
if( nFoundCount != 0)
{
pCameraID = pCameras[0].cameraIdString;
}
else
{
pCameraID = NULL;
err = VmbErrorNotFound;
printf( "Camera lost.\n" );
}
}
free( pCameras );
pCameras = NULL;
}
else
{
printf( "Could not allocate camera list.\n" );
}
}
else
{
printf( "Could not list cameras or no cameras present. Error code: %d\n", err );
}
}
if ( NULL != pCameraID )
{
// Open camera
err = VmbCameraOpen( pCameraID, cameraAccessMode, &cameraHandle );
if ( VmbErrorSuccess == err )
{
printf( "Camera ID: %s\n\n", pCameraID );
// Set the GeV packet size to the highest possible value
// (In this example we do not test whether this cam actually is a GigE cam)
if ( VmbErrorSuccess == VmbFeatureCommandRun( cameraHandle, "GVSPAdjustPacketSize" ))
{
do
{
if ( VmbErrorSuccess != VmbFeatureCommandIsDone( cameraHandle,
"GVSPAdjustPacketSize",
&bIsCommandDone ))
{
break;
}
} while ( VmbBoolFalse == bIsCommandDone );
}
if ( VmbErrorSuccess == err )
{
// Set pixel format. For the sake of simplicity we only support Mono and RGB in this example.
err = VmbFeatureEnumSet( cameraHandle, "PixelFormat", "RGB8Packed" );
if ( VmbErrorSuccess != err )
{
// Fall back to Mono
err = VmbFeatureEnumSet( cameraHandle, "PixelFormat", "Mono8" );
}
// Read back pixel format
VmbFeatureEnumGet( cameraHandle, "PixelFormat", &pPixelFormat );
if ( VmbErrorSuccess == err )
{
// Evaluate frame size
err = VmbFeatureIntGet( cameraHandle, "PayloadSize", &nPayloadSize );
if ( VmbErrorSuccess == err )
{
frame.buffer = (unsigned char*)malloc( (VmbUint32_t)nPayloadSize );
frame.bufferSize = (VmbUint32_t)nPayloadSize;
// Announce Frame
err = VmbFrameAnnounce( cameraHandle, &frame, (VmbUint32_t)sizeof( VmbFrame_t ));
if ( VmbErrorSuccess == err )
{
// Start Capture Engine
err = VmbCaptureStart( cameraHandle );
if ( VmbErrorSuccess == err )
{
// Queue Frame
err = VmbCaptureFrameQueue( cameraHandle, &frame, NULL );
if ( VmbErrorSuccess == err )
{
// Start Acquisition
err = VmbFeatureCommandRun( cameraHandle,"AcquisitionStart" );
if ( VmbErrorSuccess == err )
{
// Capture one frame synchronously
err = VmbCaptureFrameWait( cameraHandle, &frame, nTimeout );
if ( VmbErrorSuccess == err )
{
// Convert the captured frame to a bitmap and save to disk
if ( VmbFrameStatusComplete == frame.receiveStatus )
{
bitmap.bufferSize = frame.imageSize;
bitmap.width = frame.width;
bitmap.height = frame.height;
// We only support Mono and RGB in this example
if ( 0 == strcmp( "RGB8Packed", pPixelFormat ))
{
bitmap.colorCode = ColorCodeRGB24;
}
else
{
bitmap.colorCode = ColorCodeMono8;
}
// Create the bitmap
if ( 0 == AVTCreateBitmap( &bitmap, frame.buffer ))
{
printf( "Could not create bitmap.\n" );
}
else
{
// Save the bitmap
if ( 0 == AVTWriteBitmapToFile( &bitmap, pFileName ))
{
printf( "Could not write bitmap to file.\n" );
}
else
{
printf( "Bitmap successfully written to file \"%s\"\n", pFileName );
// Release the bitmap's buffer
if ( 0 == AVTReleaseBitmap( &bitmap ))
{
printf( "Could not release the bitmap.\n" );
}
}
}
}
else
{
printf( "Frame not successfully received. Error code: %d\n", frame.receiveStatus );
}
}
else
{
printf( "Could not capture frame. Error code: %d\n", err );
}
// Stop Acquisition
err = VmbFeatureCommandRun( cameraHandle,"AcquisitionStop" );
if ( VmbErrorSuccess != err )
{
printf( "Could not stop acquisition. Error code: %d\n", err );
}
}
else
{
printf( "Could not start acquisition. Error code: %d\n", err );
}
}
else
{
printf( "Could not queue frame. Error code: %d\n", err );
}
// Stop Capture Engine
err = VmbCaptureEnd( cameraHandle );
if ( VmbErrorSuccess != err )
{
printf( "Could not end capture. Error code: %d\n", err );
}
}
else
{
printf( "Could not start capture. Error code: %d\n", err );
}
// Revoke frame
err = VmbFrameRevoke( cameraHandle, &frame );
if ( VmbErrorSuccess != err )
{
printf( "Could not revoke frame. Error code: %d\n", err );
}
}
else
{
printf( "Could not announce frame. Error code: %d\n", err );
}
free( frame.buffer );
frame.buffer = NULL;
}
}
else
{
printf( "Could not set pixel format to either RGB or Mono. Error code: %d\n", err );
}
}
else
{
printf( "Could not adjust packet size. Error code: %d\n", err );
}
err = VmbCameraClose ( cameraHandle );
if ( VmbErrorSuccess != err )
{
printf( "Could not close camera. Error code: %d\n", err );
}
}
else
{
printf( "Could not open camera. Error code: %d\n", err );
}
}
VmbShutdown();
}
else
{
printf( "Could not start system. Error code: %d\n", err );
}
return err;
}

View File

@@ -0,0 +1,52 @@
/*=============================================================================
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: SynchronousGrab.h
Description: The SynchronousGrab example will grab a single image
synchronously and save it to a file using VimbaC.
-------------------------------------------------------------------------------
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 SYNCHRONOUS_GRAB_H_
#define SYNCHRONOUS_GRAB_H_
#include <VimbaC/Include/VmbCommonTypes.h>
//
// Starts Vimba API
// Opens the given camera, if no camera ID was provided, the first camera found will be used
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Acquires one image synchronously
// Writes the image as bitmap to file
// Closes the camera in case of failure
//
// Parameters:
// [in] pCameraID The ID of the camera to work on. Can be NULL.
// [in] pFileName The path of the bitmap where the image is saved to
//
// Returns:
// An API status code
//
VmbError_t SynchronousGrab ( const char* pCameraID, const char* pFileName );
#endif

View File

@@ -0,0 +1,159 @@
/*=============================================================================
Copyright (C) 2012 - 2013 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: Implementation of main entry point of SynchronousGrab example of
VimbaC.
-------------------------------------------------------------------------------
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 <stdio.h>
#include <string.h>
#include <SynchronousGrab.h>
unsigned char StartsWith(const char *pString, const char *pStart)
{
if(NULL == pString)
{
return 0;
}
if(NULL == pStart)
{
return 0;
}
if(strlen(pString) < strlen(pStart))
{
return 0;
}
if(memcmp(pString, pStart, strlen(pStart)) != 0)
{
return 0;
}
return 1;
}
int main( int argc, char* argv[] )
{
VmbError_t err = VmbErrorSuccess;
char* pCameraID = NULL; // The ID of the camera to use
const char* pFileName = NULL; // The filename for the bitmap to save
unsigned char bPrintHelp = 0; // Output help?
int i = 0; // Counter for some iteration
char* pParameter = 0; // The command line parameter
printf( "//////////////////////////////////////////\n" );
printf( "/// Vimba API Synchronous Grab Example ///\n" );
printf( "//////////////////////////////////////////\n\n" );
//////////////////////
//Parse command line//
//////////////////////
for( i = 1; i < argc; ++i )
{
pParameter = argv[i];
if( 0 > strlen( pParameter ))
{
err = VmbErrorBadParameter;
break;
}
if( '/' == pParameter[0] )
{
if( StartsWith( pParameter, "/f:" ))
{
if( NULL != pFileName )
{
err = VmbErrorBadParameter;
break;
}
pFileName = pParameter + 3;
if( 0 >= strlen( pFileName ))
{
err = VmbErrorBadParameter;
break;
}
}
else if( 0 == strcmp( pParameter, "/h" ))
{
if( ( NULL != pCameraID )
|| ( NULL != pFileName )
|| ( bPrintHelp ))
{
err = VmbErrorBadParameter;
break;
}
bPrintHelp = 1;
}
else
{
err = VmbErrorBadParameter;
break;
}
}
else
{
if( NULL != pCameraID )
{
err = VmbErrorBadParameter;
break;
}
pCameraID = pParameter;
}
}
//Write out an error if we could not parse the command line
if ( VmbErrorBadParameter == err )
{
printf( "Invalid parameters!\n\n" );
bPrintHelp = 1;
}
//Print out help and end program
if ( bPrintHelp )
{
printf( "Usage: SynchronousGrab [CameraID] [/h] [/f:FileName]\n" );
printf( "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n" );
printf( " /h Print out help\n" );
printf( " /f:FileName File name for operation\n" );
printf( " (default \"SynchronousGrab.bmp/.dat\" if not specified)\n" );
}
else
{
if ( NULL == pFileName )
{
pFileName = "SynchronousGrab.bmp";
}
err = SynchronousGrab( pCameraID, pFileName );
}
return err;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,251 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this header file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: VmbCommonTypes.h
Description: Main header file for the common types of the Vimba APIs.
-------------------------------------------------------------------------------
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 VMBCOMMONTYPES_H_INCLUDE_
#define VMBCOMMONTYPES_H_INCLUDE_
#ifdef __cplusplus
extern "C" {
#endif
// This file describes all necessary definitions for types used within
// Allied Vision's Vimba APIs. These type definitions are designed to be
// portable from other languages and other operating systems.
#if defined (_MSC_VER)
// 8 bit signed integer on Microsoft systems
typedef __int8 VmbInt8_t;
// 8 bit unsigned integer on Microsoft systems
typedef unsigned __int8 VmbUint8_t;
// 16 bit signed integer on Microsoft systems
typedef __int16 VmbInt16_t;
// 16 bit unsigned integer on Microsoft systems
typedef unsigned __int16 VmbUint16_t;
// 32 bit signed integer on Microsoft systems
typedef __int32 VmbInt32_t;
// 32 bit unsigned integer on Microsoft systems
typedef unsigned __int32 VmbUint32_t;
// 64 bit signed integer on Microsoft systems
typedef __int64 VmbInt64_t;
// 64 bit unsigned integer on Microsoft systems
typedef unsigned __int64 VmbUint64_t;
#else // for non MS or GNU compilers without any warranty for the size
//#pragma message("Compatibility warning: typedefs in " __FILE__ " may not have the correct number of bits")
// 8 bit signed integer on non-Microsoft systems
typedef signed char VmbInt8_t;
// 8 bit unsigned integer on non-Microsoft systems
typedef unsigned char VmbUint8_t;
// 16 bit signed integer on non-Microsoft systems
typedef short VmbInt16_t;
// 16 bit unsigned integer on non-Microsoft systems
typedef unsigned short VmbUint16_t;
// 32 bit signed integer on non-Microsoft systems
typedef int VmbInt32_t;
// 32 bit signed integer on non-Microsoft systems
typedef unsigned int VmbUint32_t;
// 64 bit signed integer on non-Microsoft systems
typedef long long VmbInt64_t;
// 64 bit unsigned integer on non-Microsoft systems
typedef unsigned long long VmbUint64_t;
#endif
// Handle; e.g. for a camera
typedef void* VmbHandle_t;
// Standard type for boolean values
#if defined(__cplusplus) || defined(__bool_true_false_are_defined)
typedef bool VmbBool_t;
#else
// Boolean type (equivalent to char)
typedef char VmbBool_t; // 1 means true and 0 means false
#endif
//
// enum for bool values
//
typedef enum VmbBoolVal
{
VmbBoolTrue = 1,
VmbBoolFalse = 0,
} VmbBoolVal;
// char type
typedef unsigned char VmbUchar_t;
//
// Error codes, returned by most functions: (not yet complete)
//
typedef enum VmbErrorType
{
VmbErrorSuccess = 0, // No error
VmbErrorInternalFault = -1, // Unexpected fault in VimbaC or driver
VmbErrorApiNotStarted = -2, // VmbStartup() was not called before the current command
VmbErrorNotFound = -3, // The designated instance (camera, feature etc.) cannot be found
VmbErrorBadHandle = -4, // The given handle is not valid
VmbErrorDeviceNotOpen = -5, // Device was not opened for usage
VmbErrorInvalidAccess = -6, // Operation is invalid with the current access mode
VmbErrorBadParameter = -7, // One of the parameters is invalid (usually an illegal pointer)
VmbErrorStructSize = -8, // The given struct size is not valid for this version of the API
VmbErrorMoreData = -9, // More data available in a string/list than space is provided
VmbErrorWrongType = -10, // Wrong feature type for this access function
VmbErrorInvalidValue = -11, // The value is not valid; either out of bounds or not an increment of the minimum
VmbErrorTimeout = -12, // Timeout during wait
VmbErrorOther = -13, // Other error
VmbErrorResources = -14, // Resources not available (e.g. memory)
VmbErrorInvalidCall = -15, // Call is invalid in the current context (e.g. callback)
VmbErrorNoTL = -16, // No transport layers are found
VmbErrorNotImplemented = -17, // API feature is not implemented
VmbErrorNotSupported = -18, // API feature is not supported
VmbErrorIncomplete = -19, // The current operation was not completed (e.g. a multiple registers read or write)
VmbErrorIO = -20, // Low level IO error in transport layer
} VmbErrorType;
typedef VmbInt32_t VmbError_t; // Type for an error returned by API methods; for values see VmbErrorType
//
// Version information
//
typedef struct
{
VmbUint32_t major; // Major version number
VmbUint32_t minor; // Minor version number
VmbUint32_t patch; // Patch version number
} VmbVersionInfo_t;
//
// Indicate if pixel is monochrome or RGB.
//
typedef enum VmbPixelType
{
VmbPixelMono = 0x01000000, // Monochrome pixel
VmbPixelColor = 0x02000000 // Pixel bearing color information
} VmbPixelType;
//
// Indicate number of bits for a pixel. Needed for building values of VmbPixelFormatType
//
typedef enum VmbPixelOccupyType
{
VmbPixelOccupy8Bit = 0x00080000, // Pixel effectively occupies 8 bits
VmbPixelOccupy10Bit = 0x000A0000, // Pixel effectively occupies 10 bits
VmbPixelOccupy12Bit = 0x000C0000, // Pixel effectively occupies 12 bits
VmbPixelOccupy14Bit = 0x000E0000, // Pixel effectively occupies 14 bits
VmbPixelOccupy16Bit = 0x00100000, // Pixel effectively occupies 16 bits
VmbPixelOccupy24Bit = 0x00180000, // Pixel effectively occupies 24 bits
VmbPixelOccupy32Bit = 0x00200000, // Pixel effectively occupies 32 bits
VmbPixelOccupy48Bit = 0x00300000, // Pixel effectively occupies 48 bits
VmbPixelOccupy64Bit = 0x00400000, // Pixel effectively occupies 48 bits
} VmbPixelOccupyType;
//
// Pixel format types.
// As far as possible, the Pixel Format Naming Convention (PFNC) has been followed, allowing a few deviations.
// If data spans more than one byte, it is always LSB aligned, except if stated differently.
//
typedef enum VmbPixelFormatType
{
// Mono formats
VmbPixelFormatMono8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0001, // Monochrome, 8 bits (PFNC:Mono8)
VmbPixelFormatMono10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0003, // Monochrome, 10 bits in 16 bits (PFNC:Mono10)
VmbPixelFormatMono10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0046, // Monochrome, 4x10 bits continuously packed in 40 bits (PFNC:Mono10p)
VmbPixelFormatMono12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0005, // Monochrome, 12 bits in 16 bits (PFNC:Mono12)
VmbPixelFormatMono12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x0006, // Monochrome, 2x12 bits in 24 bits (GEV:Mono12Packed)
VmbPixelFormatMono12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0047, // Monochrome, 2x12 bits continuously packed in 24 bits (PFNC:Mono12p)
VmbPixelFormatMono14 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0025, // Monochrome, 14 bits in 16 bits (PFNC:Mono14)
VmbPixelFormatMono16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0007, // Monochrome, 16 bits (PFNC:Mono16)
// Bayer formats
VmbPixelFormatBayerGR8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0008, // Bayer-color, 8 bits, starting with GR line (PFNC:BayerGR8)
VmbPixelFormatBayerRG8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x0009, // Bayer-color, 8 bits, starting with RG line (PFNC:BayerRG8)
VmbPixelFormatBayerGB8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x000A, // Bayer-color, 8 bits, starting with GB line (PFNC:BayerGB8)
VmbPixelFormatBayerBG8 = VmbPixelMono | VmbPixelOccupy8Bit | 0x000B, // Bayer-color, 8 bits, starting with BG line (PFNC:BayerBG8)
VmbPixelFormatBayerGR10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000C, // Bayer-color, 10 bits in 16 bits, starting with GR line (PFNC:BayerGR10)
VmbPixelFormatBayerRG10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000D, // Bayer-color, 10 bits in 16 bits, starting with RG line (PFNC:BayerRG10)
VmbPixelFormatBayerGB10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000E, // Bayer-color, 10 bits in 16 bits, starting with GB line (PFNC:BayerGB10)
VmbPixelFormatBayerBG10 = VmbPixelMono | VmbPixelOccupy16Bit | 0x000F, // Bayer-color, 10 bits in 16 bits, starting with BG line (PFNC:BayerBG10)
VmbPixelFormatBayerGR12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0010, // Bayer-color, 12 bits in 16 bits, starting with GR line (PFNC:BayerGR12)
VmbPixelFormatBayerRG12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0011, // Bayer-color, 12 bits in 16 bits, starting with RG line (PFNC:BayerRG12)
VmbPixelFormatBayerGB12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0012, // Bayer-color, 12 bits in 16 bits, starting with GB line (PFNC:BayerGB12)
VmbPixelFormatBayerBG12 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0013, // Bayer-color, 12 bits in 16 bits, starting with BG line (PFNC:BayerBG12)
VmbPixelFormatBayerGR12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002A, // Bayer-color, 2x12 bits in 24 bits, starting with GR line (GEV:BayerGR12Packed)
VmbPixelFormatBayerRG12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002B, // Bayer-color, 2x12 bits in 24 bits, starting with RG line (GEV:BayerRG12Packed)
VmbPixelFormatBayerGB12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002C, // Bayer-color, 2x12 bits in 24 bits, starting with GB line (GEV:BayerGB12Packed)
VmbPixelFormatBayerBG12Packed = VmbPixelMono | VmbPixelOccupy12Bit | 0x002D, // Bayer-color, 2x12 bits in 24 bits, starting with BG line (GEV:BayerBG12Packed)
VmbPixelFormatBayerGR10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0056, // Bayer-color, 4x10 bits continuously packed in 40 bits, starting with GR line (PFNC:BayerGR10p)
VmbPixelFormatBayerRG10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0058, // Bayer-color, 4x10 bits continuously packed in 40 bits, starting with RG line (PFNC:BayerRG10p)
VmbPixelFormatBayerGB10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0054, // Bayer-color, 4x10 bits continuously packed in 40 bits, starting with GB line (PFNC:BayerGB10p)
VmbPixelFormatBayerBG10p = VmbPixelMono | VmbPixelOccupy10Bit | 0x0052, // Bayer-color, 4x10 bits continuously packed in 40 bits, starting with BG line (PFNC:BayerBG10p)
VmbPixelFormatBayerGR12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0057, // Bayer-color, 2x12 bits continuously packed in 24 bits, starting with GR line (PFNC:BayerGR12p)
VmbPixelFormatBayerRG12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0059, // Bayer-color, 2x12 bits continuously packed in 24 bits, starting with RG line (PFNC:BayerRG12p)
VmbPixelFormatBayerGB12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0055, // Bayer-color, 2x12 bits continuously packed in 24 bits, starting with GB line (PFNC:BayerGB12p)
VmbPixelFormatBayerBG12p = VmbPixelMono | VmbPixelOccupy12Bit | 0x0053, // Bayer-color, 2x12 bits continuously packed in 24 bits, starting with BG line (PFNC:BayerBG12p)
VmbPixelFormatBayerGR16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x002E, // Bayer-color, 16 bits, starting with GR line (PFNC:BayerGR16)
VmbPixelFormatBayerRG16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x002F, // Bayer-color, 16 bits, starting with RG line (PFNC:BayerRG16)
VmbPixelFormatBayerGB16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0030, // Bayer-color, 16 bits, starting with GB line (PFNC:BayerGB16)
VmbPixelFormatBayerBG16 = VmbPixelMono | VmbPixelOccupy16Bit | 0x0031, // Bayer-color, 16 bits, starting with BG line (PFNC:BayerBG16)
// RGB formats
VmbPixelFormatRgb8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0014, // RGB, 8 bits x 3 (PFNC:RGB8)
VmbPixelFormatBgr8 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0015, // BGR, 8 bits x 3 (PFNC:Bgr8)
VmbPixelFormatRgb10 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0018, // RGB, 10 bits in 16 bits x 3 (PFNC:RGB10)
VmbPixelFormatBgr10 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0019, // BGR, 10 bits in 16 bits x 3 (PFNC:BGR10)
VmbPixelFormatRgb12 = VmbPixelColor | VmbPixelOccupy48Bit | 0x001A, // RGB, 12 bits in 16 bits x 3 (PFNC:RGB12)
VmbPixelFormatBgr12 = VmbPixelColor | VmbPixelOccupy48Bit | 0x001B, // BGR, 12 bits in 16 bits x 3 (PFNC:BGR12)
VmbPixelFormatRgb14 = VmbPixelColor | VmbPixelOccupy48Bit | 0x005E, // RGB, 14 bits in 16 bits x 3 (PFNC:RGB14)
VmbPixelFormatBgr14 = VmbPixelColor | VmbPixelOccupy48Bit | 0x004A, // BGR, 14 bits in 16 bits x 3 (PFNC:BGR14)
VmbPixelFormatRgb16 = VmbPixelColor | VmbPixelOccupy48Bit | 0x0033, // RGB, 16 bits x 3 (PFNC:RGB16)
VmbPixelFormatBgr16 = VmbPixelColor | VmbPixelOccupy48Bit | 0x004B, // BGR, 16 bits x 3 (PFNC:BGR16)
// RGBA formats
VmbPixelFormatArgb8 = VmbPixelColor | VmbPixelOccupy32Bit | 0x0016, // ARGB, 8 bits x 4 (PFNC:RGBa8)
VmbPixelFormatRgba8 = VmbPixelFormatArgb8, // RGBA, 8 bits x 4, legacy name
VmbPixelFormatBgra8 = VmbPixelColor | VmbPixelOccupy32Bit | 0x0017, // BGRA, 8 bits x 4 (PFNC:BGRa8)
VmbPixelFormatRgba10 = VmbPixelColor | VmbPixelOccupy64Bit | 0x005F, // RGBA, 10 bits in 16 bits x 4
VmbPixelFormatBgra10 = VmbPixelColor | VmbPixelOccupy64Bit | 0x004C, // BGRA, 10 bits in 16 bits x 4
VmbPixelFormatRgba12 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0061, // RGBA, 12 bits in 16 bits x 4
VmbPixelFormatBgra12 = VmbPixelColor | VmbPixelOccupy64Bit | 0x004E, // BGRA, 12 bits in 16 bits x 4
VmbPixelFormatRgba14 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0063, // RGBA, 14 bits in 16 bits x 4
VmbPixelFormatBgra14 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0050, // BGRA, 14 bits in 16 bits x 4
VmbPixelFormatRgba16 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0064, // RGBA, 16 bits x 4
VmbPixelFormatBgra16 = VmbPixelColor | VmbPixelOccupy64Bit | 0x0051, // BGRA, 16 bits x 4
// YUV/YCbCr formats
VmbPixelFormatYuv411 = VmbPixelColor | VmbPixelOccupy12Bit | 0x001E, // YUV 411 with 8 bits (GEV:YUV411Packed)
VmbPixelFormatYuv422 = VmbPixelColor | VmbPixelOccupy16Bit | 0x001F, // YUV 422 with 8 bits (GEV:YUV422Packed)
VmbPixelFormatYuv444 = VmbPixelColor | VmbPixelOccupy24Bit | 0x0020, // YUV 444 with 8 bits (GEV:YUV444Packed)
VmbPixelFormatYCbCr411_8_CbYYCrYY = VmbPixelColor | VmbPixelOccupy12Bit | 0x003C, // Y<>CbCr 411 with 8 bits (PFNC:YCbCr411_8_CbYYCrYY) - identical to VmbPixelFormatYuv411
VmbPixelFormatYCbCr422_8_CbYCrY = VmbPixelColor | VmbPixelOccupy16Bit | 0x0043, // Y<>CbCr 422 with 8 bits (PFNC:YCbCr422_8_CbYCrY) - identical to VmbPixelFormatYuv422
VmbPixelFormatYCbCr8_CbYCr = VmbPixelColor | VmbPixelOccupy24Bit | 0x003A, // Y<>CbCr 444 with 8 bits (PFNC:YCbCr8_CbYCr) - identical to VmbPixelFormatYuv444
VmbPixelFormatLast,
} VmbPixelFormatType;
typedef VmbUint32_t VmbPixelFormat_t; // Type for the pixel format; for values see VmbPixelFormatType
#ifdef __cplusplus
}
#endif
#endif // VMBCOMMONTYPES_H_INCLUDE_