Compare commits

...

No commits in common. "main" and "master" have entirely different histories.
main ... master

838 changed files with 167955 additions and 3 deletions

2
.gitignore vendored
View File

@ -86,3 +86,5 @@ dkms.conf
*.out
*.app
归档.zip

65
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,65 @@
{
"files.associations": {
"*.log": "log",
"*.db": "db",
"*.json": "jsonl",
"gst.h": "c",
"rtsp-server.h": "c",
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
}
}

View File

@ -1,3 +0,0 @@
# Radiation-resistantCamera
耐辐照相机

10
REDME.md Normal file
View File

@ -0,0 +1,10 @@
VisionSDK_C_GCC9.3.0_armv8 文件夹是耐辐照相机的arm64版本的驱动程序
makefile里面的交叉编译器用的绝对路径请自行修改
Sample.c 文件video节点是实际生成的虚拟相机设备节点
sudo modprobe v4l2loopback 生成虚拟相机设备节点
归档文件是曹勇之前的版本,都不需要了
rknn_usb_rtsp-master/ 这是RTSP推流的代码用了rockcip硬件推流
Vimba_v6.0_ARM64.tgz 这是AVT的相机官方驱动程序示例

View File

@ -0,0 +1,605 @@
===========================================================================
Vimba for Linux ARMv8 64-bit - Release Notes
Version: 6.0
Date: January 2022
===========================================================================
--------------------------------
Components and Version Reference
--------------------------------
Vimba GenICam Transport Layer modules
-------------------------------------
CSI Transport Layer (VimbaCSITL.cti) 1.0.1*
GigE Transport Layer (VimbaGigETL.cti) 1.9.0
USB Transport Layer (VimbaUSBTL.cti) 1.4.1*
APIs
----
Vimba C API (libVimbaC.so) 1.9.1*
Vimba C++ API (libVimbaCPP.so) 1.9.0
Vimba Python API 1.2.1*
Image Transform Library (libVimbaImageTransform.so) 1.6.0
Tools
-----
Vimba Viewer (VimbaViewer) 2.5.0
Vimba Class Generator (VimbaClassGenerator) 1.0.6
Vimba Firmware Updater (VimbaFirmwareUpdater.exe) 1.2.0
Vimba Firmware Updater Console (FWUpdaterConsole.exe) 1.2.0
Third Party Libraries
---------------------
TinyXML (not shipped with Vimba) 2.6.2
Qt 4.8.5
Qwt 6.1.3
libTIFF 4.0.7
OpenCV 3.0.0
* Changed in this release of Vimba
---------------------
Hardware Requirements
---------------------
ARM board with ARMv8-compatible 64-bit processor
Allied Vision GigE cameras require a built-in Gigabit Ethernet network interface
or at least one Gigabit Ethernet network card.
Note for IP configuration:
By default, IP Configuration Mode is set to DHCP.
You can also select LLA (link-local address) if you connect just one camera.
If multiple cameras are connected at the same time, we recommend using
DHCP or Persistent IP Address to enable discovery of all cameras.
Allied Vision USB cameras require a built-in USB 3.0 controller for PCI Express bus.
------------------------
Tested Operating Systems
------------------------
Vimba was tested on NVIDIA Xavier NX with:
- JetPack 4.6 (L4T 32.6.1) - GigE and USB cameras
- JetPack 4.5.1 (L4T 32.5.1) - CSI-2 cameras
------------------------------------
Prerequisites for CSI-2 camera users
------------------------------------
The driver for Allied Vision CSI-2 is not included in the Linux kernel provided
by the manufacturer of the board.
Before installing Vimba, please install the driver, see:
https://github.com/alliedvision
--------------------------------------
Supported CSI-2 cameras and ARM boards
--------------------------------------
Supported CSI-2 camera models and ARM boards are listed in this document:
https://alliedvision.com/fileadmin/content/documents/products/software/software/embedded/Getting_started_with_GenICam_for_CSI.pdf
------------
Installation
------------
Allied Vision Vimba comes as a tarball. In order to set up Vimba, follow these steps:
- Uncompress the archive with the command tar -xf ./Vimba.tgz to a
directory you have writing privileges for like /opt. Under this directory
Vimba will be installed in its own folder. In the following, we will refer
to this path as [InstallDir].
- Go to [InstallDir]/VimbaGigETL and/or [InstallDir]/VimbaUSBTL and execute the shell
script Install.sh with super user privileges (e.g., sudo ./Install.sh). This
registers the GENICAM_GENTL32_PATH and/or the GENICAM_GENTL64_PATH environment
variable through a startup script in /etc/profile.d so that every GenICam GenTL
consumer (such as the examples that ship with Allied Vision Vimba) can access the
Allied Vision Gigabit Ethernet and USB Transport Layers. Please note that this is a
per-user setting. If transport layers are not found, follow the instructions in this document:
https://alliedvision.com/fileadmin/content/documents/products/software/software/Vimba/appnote/Vimba_installation_under_Linux.pdf
- Reboot computer
Vimba Viewer:
Vimba Viewer can be found in, for example, [InstallDir]/Tools/Viewer/Bin/x86_64bit/.
This program allows you to configure your Allied Vision cameras and capture images.
Ubuntu 18.04 LTS:
- To build Vimba Viewer, install the libcanberra-gtk-module
apt-get install libcanberra-gtk-module
Vimba includes many precompiled examples that can be found in
Vimba/VimbaC/Examples/Bin and Vimba/VimbaCPP/Examples/Bin.
If you want to compile these examples yourself, please refer to the user manual
for instructions and required packages.
For uninstalling Vimba, remove the startup scripts by running the shell scripts
Uninstall.sh as super user. This prevents any GenTL consumer from loading the
Vimba and USB Transport Layers. Then simply remove the
installation directory.
------------
Known Issues
------------
- When experiencing trouble with image acquisition, try to increase the priority
of your application with "sudo -E nice -n -20 <command>".
GigE Transport Layer:
- A change of the available camera access modes cannot be reported for cameras
in different subnets or with malconfigured IP addresses. These cameras can
be accessed in configuration mode from different hosts simultaneously.
- Not all ARM boards come with a GigE network interface. When acquiring images
with only 100 Mbit/s, make sure to set the "StreamBytesPerSecond" feature to
a reasonable small value (12 400 000). This adjustment is done automatically
when the camera is connected directly to a 100 Mbit/s interface.
Tranport layers not found (Error -16):
- Please follow the instructions in this document:
https://alliedvision.com/fileadmin/content/documents/products/software/software/Vimba/appnote/Vimba_installation_under_Linux.pdf
- Vimba Firmware Updater and FWUpdaterConsole.exe:
Mako-U cameras are not detected after updating the firmware.
To detect the camera, please reboot the board.
Camera detection:
- If multiple IP addresses are configured on one physical Ethernet adapter,
then Vimba sends GVCP discovery requests only to the last added IP address.
Therefore, the camera is detected only if its IP address was added last.
Vimba Viewer:
- If a GigE camera was opened and then closed with Vimba Viewer,
it is displayed as locked and Vimba Viewer does not open it again.
Workaround: Close and open Vimba Viewer.
- When multiple opened GigE cameras are disconnected at the same time
while no other camera stays connected to the very same NIC,
the Vimba Viewer's camera windows stay open.
- qt error: please install libpng12 if it is missing. See:
https://cdn.alliedvision.com/fileadmin/content/documents/products/software/software/Vimba/appnote/libpng-installation.pdf
- After streaming several hours, the displayed image is not updated.
Changing camera settings results in a black image. Stopping and starting image acquisition
updates the displayed image. The issue affects only the displayed image, not the image itself.
Vimba code examples
- qt error: please install libpng12 if it is missing. See:
https://cdn.alliedvision.com/fileadmin/content/documents/products/software/software/Vimba/appnote/libpng-installation.pdf
Vimba Documentation:
- Some apps and browsers currently don't support relative links from one
document to another document. We have successfully tested relative links
with Adobe Acrobat.
Vimba APIs:
- When API startup and shutdown is performed excessively within the same process,
camera initialization may fail sporadically, which may cause exceptions.
We recommend to have only one API session during one process.
CSI-2:
- Please use “alloc and announce” for best performance, see the AsynchrounousGrab example.
(C++: Program.Config.h, optional parameter /x, C: Program.c, optional parameter /x, Python:
optional parameter /x).
- Switching the camera from GenICam for CSI-2 to V4L2 or vice versa requires rebooting the board
- Exposure times greater than approx. 1 second: Stopping acquisition may cause an error. Please
close and open the camera to start streaming again.
- Executing the Device Reset GenICam command leads to camera communication failures.
- Not all ROIs work when Mono8 is applied.
- When a ROI or a different pixel format is applied and the camera is closed and opened again, image
acquisition doesnt start in some cases. To enable image acquisition again, open the camera with
Vimba Viewer (even if you set the ROI with a third-party viewer). In some cases, rebooting
the board is necessary.
- Issues that may occur occasionally:
- AGX Xavier: Camera stays in locked state after camera handle is closed
---------------------------
Changes and release history
---------------------------
Changes in Vimba 6.0.0:
-----------------------
VimbaC
- Fixed: Issue with null terminator for zipped XML files
CSITL
- First release (supported camera models and ARM boards and known issues: see above)
USBTL
- Bug fix (relevant for Windows only)
VimbaPython:
- Less restrictive C API version check
Changes in Vimba 5.1.0:
-----------------------
VimbaC
- New feature: Support for Alloc And Announce frame allocation mode
- Feature endianess related fixes (corresponding to GigE TL)
VimbaCPP
- New feature: Supports Alloc And Announce frame allocation mode
VimbaPython
- New feature: Supports Alloc And Announce frame allocation mode
Vimba Viewer
- Supports Alloc And Announce frame allocation mode
- Chinese localization
- Supports changes of GigE TL and VimbaC
- Fixed: IP labels not updated after changing the IP via GevCameraForceAddressSend
- Fixed: Auto ROI tab always resets ROI at startup
Firmware Updater
- Supports Git hash representation
Firmware Updater Console
- Supports Git hash representation
GigETL
- Changed behaviour of endianess handling (values must match host endianness in little-endian),
for better compatibility with third-party software.
Affected features that now have a changed byte order:
- Config Mode
- IP-related features including MulticastIPAddress
- Action Commands
- New feature DeviceUpdateTimeout (only applicable if GigE discovery is switched to Broadcast)
- New GVSPMaxLookBack default value (0 instead of 1) for improved packet resend handling
- Fixed: High memory usage during performance bottleneck (Nonpaged pool growing with multiple GigE cameras)
- Fixed: Action commands caused an error message in the console log
- Fixed: Multicast IP address range, better compatibility with third-party software
USB TL
- Updated 3rd-party libraries
Changes in Vimba 5.0.0:
-----------------------
GigETL
- New feature: GVSPHostReceiveBufferSize (SO_RCVBUF) replaces GVSPHostReceiveBuffers
(which is still usable in existing applications).
- Fixed for 5 GigE cameras:
- Fixed limitations of certain GVSPPacketSize values
VimbaC
- Fixed: Callbacks after stopping image acquisition caused exceptions
in the Python API.
- Fixed: ListAncillaryDataFeatures example (error "Could not queue frame")
Vimba Firmware Updater
- Prepared for CSI-2 support
Vimba Firmware Updater Console
- Prepared for CSI-2 support
Vimba Viewer
- Prepared for CSI-2 support
Changes in Vimba 4.3.0:
-----------------------
GigETL
- Prepared for use with 5 GigE Vision cameras
VimbaC
- Prepared for use with 5 GigE Vision cameras
VimbaCPP
- Preparations for use with 5 GigE Vision cameras in the underlying VimbaC API
Vimba Python
- Updated for use with new VimbaC version
- Fixed: read_memory now returns all 0_bytes
Vimba Firmware Updater
- Preparations for use with 5 GigE Vision cameras
Vimba Firmware Updater Console
- Preparations for use with 5 GigE Vision cameras
Vimba Viewer
- Preparations for use with 5 GigE Vision cameras
Changes in Vimba 4.2.0:
-----------------------
Vimba C
- Standard-compliant ForceIP features instead of Allied Vision custom features,
Updated VimbaC ForceIP example to use the standard-compliant ForceIP features
Vimba Python
- Redirected the used Vimba version to the one delivered in this package.
- Install.sh suggests compatible Python interpreter versions only
- Install.sh and Uninstall.sh: Added support of virtual environments, Added debug flag
GigETL
- Standard-compliant ForceIP features instead of Allied Vision custom features (see also Vimba C)
- Prepared for use with extended IDs
USBTL
- Increased default MaxTransferSize value for better performance with current Linux versions
- Improved camera detection on Linux systems (plugin event handling)
Vimba Viewer
- Added a dialog for enforcing IP settings to a GigE Vision camera
Changes in Vimba 4.1.0:
-----------------------
USBTL
- Solved conflicts between customers' boost version and the internally used version
- Other internal bug fixes
Changes in Vimba 4.0.0:
-----------------------
Vimba C
- Bug fixes
Vimba C++
- Bug fixes
Vimba Python
- New API
GigETL
- Improved resend handling
- By default, packet resends are enabled
- Other bug fixes
USBTL
- Improved visibility of USB camera status
- Other bug fixes
Vimba GigE Filter Driver
- Bug fixes
Vimba Viewer
- Bug fixes
Changes in Vimba 3.1.0:
-----------------------
Vimba C
- Updated for use with GenTL 1.5
Vimba C++
- Updated for use with GenTL 1.5
GigETL
- GenTL 1.5 support
USBTL
- GenTL 1.5 support
Vimba Viewer
- Bug fixes
Changes in Vimba 3.0:
-----------------------
Vimba C
- Bug fixes
Vimba C++
- Bug fixes
Vimba Viewer
- Supports Alvium USB cameras
- Fixed handling of float increments
- Fixed occasional crashes with high frame rates
- Several minor bug fixes
GigETL
- Fixed: GVSPPacketSize now updates as expected
USBTL
- Bug fixes
Changes in Vimba 2.1.3:
---------------------
Vimba C
- Added ActionCommands programming example
- Vimba C Manual: Updated documentation of Action Commands
- Prepared the API for use with GenTL 1.5
- Bug fixes
Vimba C++
- Added ActionCommands programming example
- Vimba CPP Manual: Updated documentation of Action Commands
- Prepared the underlying C API for use with GenTL 1.5
- Vimba CPP Manual: Added chapter Asynchronous image acquisition - overview
- Bug fixes
Vimba Viewer
- New plugin architecture
Vima Setup
- Removed Vimba Class Generator desktop symbol
Vimba Manual
- Integrated Vimba Features Manual
Changes in Vimba 2.1:
---------------------
Vimba C
- Added functionality for Action Commands.
- Bug fixes
Vimba C++
- Added functionality for Action Commands.
- Bug fixes
Vimba Image Transform Library
- Support for conversion from 10-bit raw source formats to 16-bit color target formats.
- Support for conversion from 12-bit raw source formats to 16-bit color target formats.
- Support for conversion from 14-bit raw source formats to 16-bit color target formats.
- Support for conversion from 10-bit mono source formats to 16-bit mono target formats.
- Support for conversion from 12-bit mono source formats to 16-bit mono target formats.
- Support for conversion from 14-bit mono source formats to 16-bit mono target formats.
Vimba Viewer
- Allows now saving of 12-bit and 16-bit images (12-bit images are saved in 16-bit containers).
- Added functionality for Action Commands.
- Camera list shows the IP address of each device.
- Bug fixes
GigE Transport Layer
- The parameter BUFFER_INFO_DELIVERED_IMAGEHEIGHT is filled correctly.
- Added functionality of Action Commands.
- Bug fixes
Changes in Vimba 2.0:
---------------------
Vimba Setup
- Added Vimba Viewer Guide document
- Improved documents, new layout
Vimba C
- Added functionality of loading and saving camera settings from / to XML
- Bug fixes
Vimba C++
- Added functionality of loading and saving camera settings from / to XML
- Bug fixes
Vimba Image Transform Library
- Support for conversion from BayerXX10,12 formats to 2 byte output formats (RGB[A], BGR[A])
- Added interface functions VmbSetImageInfoFromInputParameters and VmbSetImageInfoFromInputImage
Vimba Viewer
- Enabled making use of load / save settings functionality
- Added tabsheet widgets for Brightness, ROI, Autofunction ROI, Trigger IO, Color
- Bug fixes
USB Transport Layer
- Minor bug fixes
GigE Transport Layer
- Reworked and improved filter driver
Vimba Class Generator
- Changes for Camera Link support (affects Windows only)
Changes in Vimba 1.4.1:
-----------------------
Package for ARMv7
- Support of USB Transport Layer
Package for other Linux systems
- Support of USB Transport Layer
- Improved documentation
Vimba C
- Extended camera support (e.g. float increments)
- Stability improvements
- Improved some examples
- Bug fixes
Vimba C++
- Extended camera support (e.g. float increments, needs Vimba C 1.4)
- Improved error handling
- Improved some examples
- Added and improved examples
- Bug fixes
Vimba Image Transform Library
- Added support for PFNC 10p and 12p formats
- Improved the documentation
GigE Transport Layer
- Improved stability on high traffic networks
- Bug fixes for multi-camera usage and incomplete cleanup
- Fixed range of GevHeartbeatInterval and GevHeartbeatTimeout
Vimba Viewer
- Added open camera by ID
- Added endianness switch in direct register dialog
- Many bug fixes
Vimba Class Generator
- Small improvements
Changes in Vimba 1.3.0:
-----------------------
Package for ARMv7 (new)
- Support of Vimba C API
- Support of Vimba C++ API
- Support of GigE Transport Layer
Package for other Linux systems
- Added a Vimba Tour document and a Vimba Quickstart Guide
- Improved the other documents
- Added examples for Vimba C and C++
- Added an OpenMP version of the Vimba Image Transform Library
Vimba C 1.3.0
- Fixed feature access for ancillary data
- Made device discovery blocking
- Added system feature GeVDiscoveryAllDuration for adjustable waiting time
- Fixed issues with mixed feature names
- Bug-fixes for improving stability
Vimba C++ 1.3.0
- Fixed feature access for ancillary data
- Changes caused by bug fixes in Vimba C
Vimba Image Transform Library 1.2.0
- Allowed more input for VmbSetImageInfoFromString
- Corrected return codes
- Removed transformations to Mono10/12/14 and big-endian data
Vimba Viewer 1.1.3
- Improved handling for GigE camera list changes
- Fixed issues around saving images
- GUI usage improvements
GigE Transport Layer 1.3.1
- Fixed GenTL compliance: Changed the Device ID from the serial number
to a MAC-based ID. This changes the way all APIs (C, C++ and .Net)
identify the cameras
- Added a document for GigE camera features
- Changed the supported GenTL version to 1.3 (e.g. new feature categories
BufferHandlingMode and StreamInformation)
- Separate features for heartbeat timeout and heartbeat interval
- Adjustable device discovery waiting time
- Fixed issues with similar serial numbers
- Fixed issues with many network interfaces
Vimba Class Generator
- Minor changes to appearance and documentation
Changes in Vimba 1.2.0:
-----------------------
Vimba C 1.2.0
- Version 1.2.0 is only compatible to AVT GigE TL Version 1.2.0 onwards
- Name independent search for AVT transport layers
- Made EnumEntries' "pIsImplemented" condition equivalent to "pIsAvailable"
to mimic the behavior of GenICam reference implementation
Vimba C++ 1.2.0
- Fix for opening camera by IP address
Vimba .NET 1.2.0
- Fix for 64bit version attempting to load 32bit transport layers
- Fix for opening camera by IP address
Vimba Viewer 1.1.1
- SFNC Features directly beneath the root category get listed
- Many new pixel formats available for histogram support
GigE Transport Layer 1.2.0
- Improved performance in case of many events
- Restriction to eight cameras removed
- Corrected Heartbeat feature
- Fixed support for small packets
----------------------------------------
Allied Vision Technical Support
----------------------------------------
Contact us:
https://www.alliedvision.com/contact

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,28 @@
/*=============================================================================
This file was generated by the VimbaClassGenerator
=============================================================================*/
#include "### HEADER_FILE_NAME ###"
### CLASS_NAME ###::### CLASS_NAME ### (
const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess
)
: Camera (
pCameraID,
pCameraName,
pCameraModel,
pCameraSerialNumber,
pInterfaceID,
interfaceType)
{
}
### METHOD_IMPLEMENTATIONS ###

View File

@ -0,0 +1,34 @@
/*=============================================================================
This file was generated by the VimbaClassGenerator
=============================================================================*/
#ifndef ### HEADER_FILE_MACRO_NAME ###
#define ### HEADER_FILE_MACRO_NAME ###
#include "VimbaCPP/Include/VimbaCPP.h"
class ### CLASS_NAME ### : public AVT::VmbAPI::Camera
{
public:
typedef SP_DECL( ### CLASS_NAME ### ) Ptr;
### ENUM_DECLARATIONS ###
### CLASS_NAME ### (
const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess );
### METHOD_DECLARATIONS ###
private:
### VARIABLE_DECLARATIONS ###
};
#endif

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_

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,73 @@
PROJECT_NAME = VimbaCPP
PROJECT_DIR = ../..
VIMBASDK_DIR = $(PROJECT_DIR)/..
MAKE_INCLUDE_DIR = $(CURDIR)
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = lib$(PROJECT_NAME).so
BIN_DIR = dynamic/$(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
INCLUDE_DIRS = -I$(PROJECT_DIR)/..
LIBS = $(VIMBAC_LIBS) \
-lpthread
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/AncillaryData.o \
$(OBJ_DIR)/BaseFeature.o \
$(OBJ_DIR)/BasicLockable.o \
$(OBJ_DIR)/BoolFeature.o \
$(OBJ_DIR)/Camera.o \
$(OBJ_DIR)/Clock.o \
$(OBJ_DIR)/CommandFeature.o \
$(OBJ_DIR)/Condition.o \
$(OBJ_DIR)/ConditionHelper.o \
$(OBJ_DIR)/DefaultCameraFactory.o \
$(OBJ_DIR)/EnumEntry.o \
$(OBJ_DIR)/EnumFeature.o \
$(OBJ_DIR)/FeatureContainer.o \
$(OBJ_DIR)/Feature.o \
$(OBJ_DIR)/FileLogger.o \
$(OBJ_DIR)/FloatFeature.o \
$(OBJ_DIR)/Frame.o \
$(OBJ_DIR)/FrameHandler.o \
$(OBJ_DIR)/Interface.o \
$(OBJ_DIR)/IntFeature.o \
$(OBJ_DIR)/Mutex.o \
$(OBJ_DIR)/MutexGuard.o \
$(OBJ_DIR)/RawFeature.o \
$(OBJ_DIR)/Semaphore.o \
$(OBJ_DIR)/StringFeature.o \
$(OBJ_DIR)/VimbaSystem.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) -shared $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) dynamic -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

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

Binary file not shown.

View File

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

View File

@ -0,0 +1,985 @@
/*=============================================================================
Copyright (C) 2021 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ActionCommands.cpp
Description: see header file for description
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <string.h>
#include <ActionCommands.h>
// socket library to check IP addresses
#ifdef _WIN32
#include <conio.h>
#include <WinSock.h>
#else
#include <arpa/inet.h>
#endif
// number of frame buffers to be used by example
#define NUM_FRAMES 3
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// Constructor
//
cActionCommands::cActionCommands()
: mSystem( VimbaSystem::GetInstance() )
, mFrameObserver( NULL )
, mSystemFlag( false )
, mInterfaceFlag( false )
, mCameraFlag( false )
, mStreamingFlag( false )
{
}
//
// Destructor
//
cActionCommands::~cActionCommands()
{
}
//
// Helper method to read feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [out] aType Feature data type
// [in/out] aValue Buffer for feature value
// [in/out] aSize Size of buffer
//
VmbErrorType cActionCommands::GetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType* aType, void* aValue, size_t* aSize )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( (NULL == aName) || (NULL == aValue) )
{
return VmbErrorBadParameter;
}
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
// get feature data type
VmbFeatureDataType lType = VmbFeatureDataUnknown;
lError = lFeature->GetDataType( lType );
if( (VmbErrorSuccess == lError) && (NULL != aType) )
{
*aType = lType;
}
// proceed in case of no error
if( VmbErrorSuccess == lError )
{
// set feature value
switch( lType )
{
case VmbFeatureDataInt:
{
// get value
VmbInt64_t lValue = 0;
lError = lFeature->GetValue( lValue );
if( VmbErrorSuccess == lError )
{
memcpy( aValue, &lValue, sizeof(VmbInt64_t) );
}
// set buffer size
if( NULL != aSize )
{
*aSize = sizeof(VmbInt64_t);
}
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
}
return lError;
}
//
// Helper method to write feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [in] aType Feature data type
// [in] aValue Buffer for feature value
// [in] aSize Size of buffer
//
VmbErrorType cActionCommands::SetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType aType, void* aValue, size_t aSize )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( (NULL == aName) || (NULL == aValue) )
{
return VmbErrorBadParameter;
}
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
// check feature data type
VmbFeatureDataType lType = VmbFeatureDataUnknown;
lFeature->GetDataType( lType );
if( lType != aType )
{
return VmbErrorBadParameter;
}
// proceed in case of no error
if( VmbErrorSuccess == lError )
{
// set feature value
switch( aType )
{
case VmbFeatureDataInt:
{
// check size
if( sizeof(VmbInt64_t) >= aSize )
{
// set value
VmbInt64_t lValue = (VmbInt64_t)aValue;
lError = lFeature->SetValue( lValue );
}
break;
}
case VmbFeatureDataEnum:
{
// set value
const char* lValue = (char*)aValue;
lError = lFeature->SetValue( lValue );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
}
return lError;
}
//
// Helper method to run a Command Feature
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
//
VmbErrorType cActionCommands::RunCommand( const char* aName, tFeatureOwner aOwner )
{
VmbErrorType lError = VmbErrorSuccess;
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
lError = VmbErrorBadParameter;
}
if( VmbErrorSuccess == lError )
{
lError = lFeature->RunCommand();
}
return lError;
}
//
// Called when any failure occurs within the example.
// Ensures to stop streaming, close interface, close camera and shutdown Vimba
//
void cActionCommands::FailureShutdown()
{
VmbErrorType lError = VmbErrorSuccess;
// stop streaming
if( true == this->mStreamingFlag )
{
lError = this->mCamera->StopContinuousImageAcquisition();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not stop camera acquisition. Reason: " << lError << std::endl;
}
std::cout << "......Streaming has been stopped." << std::endl;
}
// close camera
if( true == this->mCameraFlag )
{
lError = this->mCamera->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close camera. Reason: " << lError << std::endl;
}
std::cout << "......Camera has been closed." << std::endl;
}
// close interface
if( true == this->mInterfaceFlag )
{
lError = this->mInterface->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close interface. Reason: " << lError << std::endl;
}
std::cout << "......Interface has been closed." << std::endl;
}
// shutdown Vimba
if( true == this->mSystemFlag )
{
lError = this->mSystem.Shutdown();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not shutdown Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Vimba has been stooped." << std::endl;
}
}
//
// Convert given string to IP address,
// using respective socket library (Winsock/Arpa)
//
// Parameters:
// [in] aString String to be converted
// [out] aIPAddress Decimal representation of given IP address string
//
VmbErrorType cActionCommands::ConvertStringToIPAddress( std::string aString, VmbUint32_t* aIPAddress )
{
VmbErrorType lError = VmbErrorSuccess;
VmbUint32_t lIP = 0;
// check parameter
if( (true == aString.empty()) || (NULL == aIPAddress) )
{
std::cout << "[F]...Invalid parameter given" << std::endl;
return VmbErrorBadParameter;
}
// convert given string to IP struct
lIP = inet_addr( aString.c_str() );
if( -1 == lIP )
{
lError = VmbErrorInvalidValue;
}
else
{
#ifdef _LITTLE_ENDIAN
lIP = ntohl( lIP );
#endif
*aIPAddress = lIP;
}
return lError;
}
//
// Start Vimba and open camera with given string
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
//
VmbErrorType cActionCommands::PrepareCamera( std::string aCamera )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( true == aCamera.empty() )
{
std::cout << "[F]...Invalid device ID or IP address given." << std::endl;
return VmbErrorBadParameter;
}
// start Vimba
lError = this->mSystem.Startup();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not start Vimba API. Reason: " << lError << std::endl;
return lError;
}
this->mSystemFlag = true;
std::cout << "......Vimba has been started." << std::endl;
// open camera with given string (could be device ID or IP address)
lError = this->mSystem.OpenCameraByID( aCamera.c_str(), VmbAccessModeFull, this->mCamera );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not open camera " << aCamera << ". Reason: " << lError << std::endl;
this->FailureShutdown();
return lError;
}
this->mCameraFlag = true;
std::cout << "......Camera has been opened (" << aCamera << ")." << std::endl;
return lError;
}
//
// Close camera and shutdown Vimba
//
VmbErrorType cActionCommands::StopCamera()
{
VmbErrorType lError = VmbErrorSuccess;
if( true == this->mCameraFlag )
{
// close camera
lError = this->mCamera->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close camera. Reason: " << lError << std::endl;
}
this->mCameraFlag = false;
std::cout << "......Camera has been closed." << std::endl;
}
if( true == this->mSystemFlag )
{
// shutdown Vimba
lError = this->mSystem.Shutdown();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not stop Vimba. Reason: " << lError << std::endl;
}
this->mSystemFlag = false;
std::cout << "......Vimba has been stopped." << std::endl;
}
return lError;
}
//
// Prepare trigger settings for given camera
//
VmbErrorType cActionCommands::PrepareTrigger()
{
VmbErrorType lError = VmbErrorSuccess;
FeaturePtr lFeature;
char* lTemp = "";;
// select FrameStart trigger via TriggerSelector feature
lTemp = "FrameStart";
lError = this->SetFeatureValue( "TriggerSelector", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set TriggerSelector to FrameStart. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set trigger source to Action0
lTemp = "Action0";
lError = this->SetFeatureValue( "TriggerSource", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set TriggerSource to 'Action0'. Reason: " << lError << ". Probably this camera does not support Action Commands." << std::endl;
FailureShutdown();
return lError;
}
// enable trigger
lTemp = "On";
lError = this->SetFeatureValue( "TriggerMode", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not enable TriggerMode for FrameStart. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Trigger FrameStart has been activated and set to Action0" << std::endl;
return lError;
}
//
// Set Action Command information to given feature owner.
// This could be Vimba system, interface or the camera
//
// Parameters:
// [in] aOwner Feature owner, like System, Interface or Camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbErrorType cActionCommands::PrepareActionCommand( tFeatureOwner aOwner, tActionCommand* aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( NULL == aCommand )
{
std::cout << "[F]...Invalid Action Command given." << std::endl;
FailureShutdown();
return VmbErrorBadParameter;
}
// set device key
lError = this->SetFeatureValue( "ActionDeviceKey", aOwner, VmbFeatureDataInt, (void*)(aCommand->mDeviceKey), sizeof(aCommand->mDeviceKey) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionDeviceKey. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set group key
lError = this->SetFeatureValue( "ActionGroupKey", aOwner, VmbFeatureDataInt, (void*)(aCommand->mGroupKey), sizeof(aCommand->mGroupKey) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionGroupKey. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set group mask
lError = this->SetFeatureValue( "ActionGroupMask", aOwner, VmbFeatureDataInt, (void*)(aCommand->mGroupMask), sizeof(aCommand->mGroupMask) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionGroupMask. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been set (" << aCommand->mDeviceKey << ", " << aCommand->mGroupKey << ", " << aCommand->mGroupMask << ")" << std::endl;
return lError;
}
//
// Prepare streaming settings in Vimba and the camera,
// like allocating the buffers, start capture engine, etc.
//
VmbErrorType cActionCommands::PrepareStreaming()
{
VmbErrorType lError = VmbErrorSuccess;
FeaturePtr lFeature;
// set GVSP packet size to max value (MTU)
// and wait until command is done
lError = this->mCamera->GetFeatureByName( "GVSPAdjustPacketSize", lFeature );
if( VmbErrorSuccess == lError )
{
lError = lFeature->RunCommand();
}
// check if any failure occurred
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set GVSP packet size. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// check if operation is done
bool lFlag = false;
do
{
lError = lFeature->IsCommandDone( lFlag );
if( VmbErrorSuccess != lError )
{
break;
}
} while( VmbBoolFalse == lFlag );
// get GVSP packet size, which was actually set in the camera
VmbInt64_t lGVSPSize = 0;
lError = this->GetFeatureValue( "GVSPPacketSize", eFeatureOwnerCamera, NULL, &lGVSPSize, NULL );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not get GVSP packet size. Reason: " << lError << std::endl;
}
std::cout << "......GVSP packet size has been set to maximum (" << lGVSPSize << ")" << std::endl;
// create new frame observer
this->mFrameObserver = new cFrameObserver( this->mCamera );
// start continuous image acquisition
lError = this->mCamera->StartContinuousImageAcquisition( NUM_FRAMES, IFrameObserverPtr(this->mFrameObserver) );
if( VmbErrorSuccess != lError )
{
FailureShutdown();
std::cout << "[F]...Could not start continuous image acquisition. Reason: " << lError << std::endl;
return lError;
}
this->mStreamingFlag = true;
std::cout << "......Camera acquisition has been started." << std::endl;
return lError;
}
//
// End streaming
//
VmbErrorType cActionCommands::StopStreaming()
{
VmbErrorType lError = VmbErrorSuccess;
// stop continuous image acquisition
lError = this->mCamera->StopContinuousImageAcquisition();
if( VmbErrorSuccess != lError )
{
FailureShutdown();
std::cout << "[F]...Could not stop streaming. Reason: " << lError << std::endl;
return lError;
}
this->mStreamingFlag = false;
std::cout << "......Camera acquisition has been stopped." << std::endl;
return lError;
}
//
// Send Action Command on system level.
// This command will be broadcasted on all network interfaces.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType cActionCommands::SendActionCommandOnAllInterfaces( std::string aCamera, tActionCommand aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// -start Vimba
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger();
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( eFeatureOwnerCamera, &aCommand );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -adjust GVSP packet size
// -get payload size
// -allocate memory for frame buffers
// -announce frames and move them to buffer input pool
// -start capture engine
// -move frames to capture queue (buffer output queue)
// -call start acquisition feature in the camera
lError = PrepareStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// determine if Action Command shall be send as uni- or broadcast
// if IP address was given, send it as unicast
VmbUint32_t lIP = 0;
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address to Vimba
lError = this->SetFeatureValue( "GevActionDestinationIPAddress", eFeatureOwnerSystem, VmbFeatureDataInt, (void*)lIP, sizeof(lIP) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set IP address '" << aCamera << "' to Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Action Command will be send as unicast to IP '" << aCamera << "' (" << lIP << ")" << std::endl;
}
// set Action Command to Vimba system
// -device key
// -group key
// -group mask
lError = PrepareActionCommand(eFeatureOwnerSystem, &aCommand);
if (VmbErrorSuccess != lError)
{
std::cout << "[F]...Could not prepare Action Command. Reason: " << lError << std::endl;
}
#ifdef _WIN32
std::cout << "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n";
#else
std::cout << "\n<< Please enter 'a' and return to send prepared Action Command. To stop example enter 'q' and return >>\n\n";
#endif
// repeat this until user hits ESC
int lKey = 0;
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = RunCommand( "ActionCommand", eFeatureOwnerSystem );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not send Action Command. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been sent." << std::endl;
}
} while( 113 != lKey );
// stop streaming
lError = StopStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera();
return lError;
}
//
// Send Action Command on interface level.
// This command will be broadcasted on given network interface.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aInterface The network interface on which the Action Command
// will be sent out
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType cActionCommands::SendActionCommandOnInterface( std::string aCamera, std::string aInterface, tActionCommand aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// -start Vimba
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger();
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( eFeatureOwnerCamera, &aCommand );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -adjust GVSP packet size
// -get payload size
// -allocate memory for frame buffers
// -announce frames and move them to buffer input pool
// -start capture engine
// -move frames to capture queue (buffer output queue)
// -call start acquisition feature in the camera
lError = PrepareStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// get available interfaces
InterfacePtrVector lInterfaces;
lError = this->mSystem.GetInterfaces( lInterfaces );
if( (VmbErrorSuccess != lError) || (0 == lInterfaces.size()) )
{
std::cout << "[F]...Could not retrieve interfaces" << std::endl;
FailureShutdown();
return lError;
}
// print interface list
bool lFound = false;
int lIndex = 0;
for( int i=0; i<lInterfaces.size(); ++i )
{
InterfacePtr lInterface = lInterfaces.at(i);
std::string lInterfaceID = "";
lError = lInterface->GetID( lInterfaceID );
if( VmbErrorSuccess == lError )
{
std::cout << ".........[" << i << "] " << lInterfaceID << std::endl;
// compare given interface ID with current one
if( 0 == lInterfaceID.compare( aInterface ) )
{
// if interface ID matches, keep index
lFound = true;
lIndex = i;
}
}
}
// if no interface with given ID was found, return
if( false == lFound )
{
std::cout << "[F]...Given interface with ID '" << aInterface << "' was not found!" << std::endl;
FailureShutdown( );
return VmbErrorBadParameter;
}
// get interface pointer
this->mInterface = lInterfaces.at( lIndex );
if( true == SP_ISNULL(this->mInterface) )
{
std::cout << "[F]...No valid interface pointer with given index found" << std::endl;
FailureShutdown();
return VmbErrorBadParameter;
}
// check interface type
VmbInterfaceType lInterfaceType = VmbInterfaceUnknown;
lError = this->mInterface->GetType( lInterfaceType );
if( (VmbErrorSuccess != lError) || (VmbInterfaceEthernet != lInterfaceType) )
{
printf( "[F]...Selected interface is non-GigE interface!\n" );
FailureShutdown();
return VmbErrorBadParameter;
}
// open interface
lError = this->mInterface->Open();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not open interface" << std::endl;
FailureShutdown();
return lError;
}
this->mInterfaceFlag = true;
std::cout << "......Interface has been opened." << std::endl;
// determine if Action Command shall be send as uni- or broadcast
// if IP address was given, send it as unicast
VmbUint32_t lIP = 0;
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address to the selected interface
lError = this->SetFeatureValue( "GevActionDestinationIPAddress", eFeatureOwnerInterface, VmbFeatureDataInt, (void*)lIP, sizeof(lIP) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set IP address '" << aCamera << "' to Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Action Command will be send as unicast to IP '" << aCamera << "' (" << lIP << ")" << std::endl;
}
// set Action Command to the selected interface
// -device key
// -group key
// -group mask
lError = PrepareActionCommand(eFeatureOwnerInterface, &aCommand);
if (VmbErrorSuccess != lError)
{
std::cout << "[F]...Could not prepare Action Command. Reason: " << lError << std::endl;
}
#ifdef _WIN32
std::cout << "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n";
#else
std::cout << "\n<< Please enter 'a' and return to send prepared Action Command. To stop example enter 'q' and return >>\n\n";
#endif
// repeat this until user hits ESC
int lKey = 0;
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = RunCommand( "ActionCommand", eFeatureOwnerInterface );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not send Action Command. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been sent." << std::endl;
}
} while( 113 != lKey );
// close interface
lError = this->mInterface->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "Could not close interface. Reason: " << lError << std::endl;
}
this->mInterfaceFlag = false;
std::cout << "......Interface has been closed." << std::endl;
// stop streaming
lError = StopStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera();
return lError;
}
}}} // namespace AVT::VmbAPI::Examples

View File

@ -0,0 +1,200 @@
/*=============================================================================
Copyright (C) 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ActionCommands.h
Description: This example will create an Action Command and send it to any
camera, given by parameter. The following can be set up with
parameters as well:
-send Action Command as broadcast on specific network interface
-send Action Command as broadcast to all network interfaces
-send Action Command to specific IP address (unicast)
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_ACTION_COMMANDS
#define AVT_VMBAPI_EXAMPLES_ACTION_COMMANDS
#include "VimbaCPP/Include/VimbaCPP.h"
#include "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
// struct representing an Action Command
typedef struct tActionCommand
{
VmbUint32_t mDeviceKey;
VmbUint32_t mGroupKey;
VmbUint32_t mGroupMask;
} tActionCommand;
typedef enum tFeatureOwner
{
eFeatureOwnerUnknown = 0,
eFeatureOwnerSystem = 1,
eFeatureOwnerInterface = 2,
eFeatureOwnerCamera = 3
} tFeatureOwner;
class cActionCommands
{
private:
VimbaSystem& mSystem;
InterfacePtr mInterface;
CameraPtr mCamera;
cFrameObserver* mFrameObserver;
bool mSystemFlag;
bool mInterfaceFlag;
bool mCameraFlag;
bool mStreamingFlag;
public:
//
// Constructor
//
cActionCommands();
//
// Destructor
//
~cActionCommands();
//
// Helper method to read feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [out] aType Feature data type
// [in/out] aValue Buffer for feature value
// [in/out] aSize Size of buffer
//
VmbErrorType GetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType* aType, void* aValue, size_t* aSize );
//
// Helper method to write feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [in] aType Feature data type
// [in] aValue Buffer for feature value
// [in] aSize Size of buffer
//
VmbErrorType SetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType aType, void* aValue, size_t aSize );
//
// Helper method to run a Command Feature
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
//
VmbErrorType RunCommand( const char* aName, tFeatureOwner aOwner );
//
// Called when any failure occurs within the example.
// Ensures to stop streaming, close interface, close camera and shutdown Vimba
//
void FailureShutdown();
//
// Convert given string to IP address,
// using respective socket library (Winsock/Arpa)
//
// Parameters:
// [in] aString String to be converted
// [out] aIPAddress Decimal representation of given IP address string
//
VmbErrorType ConvertStringToIPAddress( std::string aString, VmbUint32_t* aIPAddress );
//
// Start Vimba and open camera with given string
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
//
VmbErrorType PrepareCamera( std::string aCamera );
//
// Close camera and shutdown Vimba
//
VmbErrorType StopCamera();
//
// Prepare trigger settings for given camera
//
VmbErrorType PrepareTrigger();
//
// Set Action Command information to given feature owner.
// This could be Vimba system, interface or the camera
//
// Parameters:
// [in] aOwner Feature owner, like System, Interface or Camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbErrorType PrepareActionCommand( tFeatureOwner aOwner, tActionCommand* aCommand );
//
// Prepare streaming settings in Vimba and the camera,
// like allocating the buffers, start capture engine, etc.
//
VmbErrorType PrepareStreaming();
//
// End streaming
//
VmbErrorType StopStreaming();
//
// Send Action Command on system level.
// This command will be broadcasted on all network interfaces.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType SendActionCommandOnAllInterfaces( std::string aCamera, tActionCommand aCommand );
//
// Send Action Command on interface level.
// This command will be broadcasted on given network interface.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aInterface The network interface on which the Action Command
// will be sent out
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType SendActionCommandOnInterface( std::string aCamera, std::string aInterface, tActionCommand aCommand );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@ -0,0 +1,76 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.cpp
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
// [in] eFrameInfos Indicates how the frame will be displayed
// [in] eColorProcessing Indicates how color processing is applied
//
cFrameObserver::cFrameObserver( CameraPtr aCamera )
: IFrameObserver( aCamera )
{
this->mCamera = aCamera;
}
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
void cFrameObserver::FrameReceived( const FramePtr pFrame )
{
if(false == SP_ISNULL( pFrame ) )
{
VmbErrorType lError = VmbErrorSuccess;
VmbFrameStatusType lStatus;
lError = SP_ACCESS( pFrame)->GetReceiveStatus( lStatus);
if( (VmbErrorSuccess == lError) && (VmbFrameStatusComplete == lStatus))
{
std::cout << "......Frame has been received" << std::endl;
}
// requeue frame
this->mCamera->QueueFrame( pFrame );
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@ -0,0 +1,65 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.h
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class cFrameObserver : virtual public IFrameObserver
{
private:
CameraPtr mCamera;
public:
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
//
cFrameObserver( CameraPtr aCamera );
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
virtual void FrameReceived( const FramePtr aFrame );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@ -0,0 +1,98 @@
/*=============================================================================
Copyright (C) 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of ActionCommands example of VimbaCPP.
annotations:
-local variables are prefixed with 'l' for local
-function parameter are prefixed with 'a' for 'argument'
-structs are prefixed with 't' for 'type'
-classes are prefixed with 'c' for 'class'
-class attributes and struct members are prefixed with 'm' for members
-enum literals are prefixed with 'e' for 'enumeration'
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <string.h>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "ActionCommands.h"
// function to print out help how to use this example application
void PrintHelp()
{
printf( "Usage: ActionCommands <CameraID/IPAdress> <InterfaceID>\n\n" );
printf( "Parameters: CameraID ID of the camera to be used\n" );
printf( " IPAddress IP address of camera to react on Action Command\n" );
printf( " InterfaceID ID of network interface to send out Action Command\n" );
printf( " 'ALL' enables broadcast on all interfaces\n\n" );
}
int main( int argc, char* argv[] )
{
VmbErrorType lError = VmbErrorSuccess;
std::cout << std::endl;
std::cout << "/////////////////////////////////////////" << std::endl;
std::cout << "/// Vimba API Action Commands Example ///" << std::endl;
std::cout << "/////////////////////////////////////////" << std::endl;
std::cout << std::endl;
// check number of arguments
if( 3 == argc )
{
// create Action Command example instance
AVT::VmbAPI::Examples::cActionCommands lProgram;
// define Action Command to be set in the camera
// and used by either Vimba system or interface module
AVT::VmbAPI::Examples::tActionCommand lActionCommand;
lActionCommand.mDeviceKey = 1;
lActionCommand.mGroupKey = 1;
lActionCommand.mGroupMask = 1;
// check if interface index is '-1' to send out Action Command on all interfaces
// if not, send Action Command via given network interface
if( 0 == strcmp("ALL", argv[2]) )
{
lError = lProgram.SendActionCommandOnAllInterfaces( argv[1], lActionCommand );
}
else
{
lError = lProgram.SendActionCommandOnInterface( argv[1], argv[2], lActionCommand );
}
}
else
{
lError = VmbErrorBadParameter;
std::cout << "[F]...Invalid number of parameters given!" << std::endl;
std::cout << std::endl;
PrintHelp();
}
std::cout << std::endl;
return lError;
}

View File

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

View File

@ -0,0 +1,245 @@
/*=============================================================================
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: ApiController.cpp
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include <iostream>
#include "ApiController.h"
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
#define NUM_FRAMES 3
ApiController::ApiController()
// Get a reference to the Vimba singleton
: m_system ( VimbaSystem::GetInstance() )
{}
ApiController::~ApiController()
{
}
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ApiController::ErrorCodeToMessage( VmbErrorType eErr ) const
{
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
}
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartUp()
{
return m_system.Startup();
}
//
// Shuts down the API
//
void ApiController::ShutDown()
{
// Release Vimba
m_system.Shutdown();
}
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] Config A configuration struct including the camera ID and other settings
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartContinuousImageAcquisition( const ProgramConfig& Config )
{
// Open the desired camera by its ID
VmbErrorType res = m_system.OpenCameraByID( Config.getCameraID().c_str(), VmbAccessModeFull, m_pCamera );
if ( VmbErrorSuccess == res )
{
// 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)
FeaturePtr pCommandFeature;
if ( VmbErrorSuccess == m_pCamera->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ))
{
if ( VmbErrorSuccess == pCommandFeature->RunCommand() )
{
bool bIsCommandDone = false;
do
{
if ( VmbErrorSuccess != pCommandFeature->IsCommandDone( bIsCommandDone ))
{
break;
}
} while ( false == bIsCommandDone );
}
}
if ( VmbErrorSuccess == res )
{
// set camera so that transform algorithms will never fail
res = PrepareCamera();
if ( VmbErrorSuccess == res )
{
// Create a frame observer for this camera (This will be wrapped in a shared_ptr so we don't delete it)
m_pFrameObserver = new FrameObserver( m_pCamera, Config.getFrameInfos(), Config.getColorProcessing(), Config.getRGBValue() );
// Start streaming
res = m_pCamera->StartContinuousImageAcquisition( NUM_FRAMES, IFrameObserverPtr( m_pFrameObserver ), Config.getAllocAndAnnounce() ? FrameAllocation_AllocAndAnnounceFrame : FrameAllocation_AnnounceFrame );
}
}
if ( VmbErrorSuccess != res )
{
// If anything fails after opening the camera we close it
m_pCamera->Close();
}
}
return res;
}
/**setting a feature to maximum value that is a multiple of 2 and a multiple of the increment*/
VmbErrorType SetIntFeatureValueModulo2( const CameraPtr &pCamera, const char* const& Name )
{
VmbErrorType result;
FeaturePtr feature;
VmbInt64_t value_min = 0;
VmbInt64_t value_max = 0;
VmbInt64_t value_increment = 0;
result = SP_ACCESS( pCamera )->GetFeatureByName( Name, feature );
if( VmbErrorSuccess != result )
{
return result;
}
result = SP_ACCESS( feature )->GetRange( value_min, value_max );
if( VmbErrorSuccess != result )
{
return result;
}
result = SP_ACCESS( feature )->GetIncrement( value_increment );
if( VmbErrorSuccess != result )
{
return result;
}
value_max = value_max - ( value_max % value_increment);
if( value_max % 2 != 0)
{
value_max -= value_increment;
}
result = SP_ACCESS( feature )->SetValue ( value_max );
return result;
}
/**prepare camera so that the delivered image will not fail in image transform*/
VmbErrorType ApiController::PrepareCamera()
{
VmbErrorType result;
result = SetIntFeatureValueModulo2( m_pCamera, "Width" );
if( VmbErrorSuccess != result )
{
return result;
}
result = SetIntFeatureValueModulo2( m_pCamera, "Height" );
if( VmbErrorSuccess != result )
{
return result;
}
return result;
}
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StopContinuousImageAcquisition()
{
// Stop streaming
m_pCamera->StopContinuousImageAcquisition();
// Close camera
return m_pCamera->Close();
}
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector ApiController::GetCameraList() const
{
CameraPtrVector cameras;
// Get all known cameras
if ( VmbErrorSuccess == m_system.GetCameras( cameras ))
{
// And return them
return cameras;
}
return CameraPtrVector();
}
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string ApiController::GetVersion() const
{
std::ostringstream os;
os<<m_system;
return os.str();
}
}}} // namespace AVT::VmbAPI::Examples

View File

@ -0,0 +1,123 @@
/*=============================================================================
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: ApiController.h
Description: Header file for the ApiController helper class that demonstrates
how to implement an asynchronous, continuous image acquisition
with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_APICONTROLLER
#define AVT_VMBAPI_EXAMPLES_APICONTROLLER
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ApiController
{
public:
ApiController();
~ApiController();
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType StartUp();
//
// Shuts down the API
//
void ShutDown();
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] Config A configuration struct including the camera ID and other settings
//
// Returns:
// An API status code
//
VmbErrorType StartContinuousImageAcquisition( const ProgramConfig & );
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType StopContinuousImageAcquisition();
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector GetCameraList() const;
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ErrorCodeToMessage( VmbErrorType eErr ) const;
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string GetVersion() const;
private:
VmbErrorType PrepareCamera();
VimbaSystem & m_system; // A reference to our Vimba singleton
CameraPtr m_pCamera; // The currently streaming camera
FrameObserver* m_pFrameObserver; // Every camera has its own frame observer
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@ -0,0 +1,84 @@
/*=============================================================================
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: BaseException.h
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.
=============================================================================*/
#ifndef BASE_EXCEPTION_H_
#define BASE_EXCEPTION_H_
#include <exception>
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class BaseException: public std::exception
{
std::string m_Function;
std::string m_Message;
VmbErrorType m_Result;
public:
BaseException( const char* const &fun, const char* const& msg, VmbErrorType result )
: m_Result ( result )
{
try
{
if( NULL != fun)
{
m_Function = std::string( fun );
}
}
catch(...) {}
try
{
if( NULL != msg)
{
m_Message = std::string( msg );
}
}
catch(...) {}
}
~BaseException() throw()
{}
const std::string& Function() const
{
return m_Function;
}
const std::string& Message() const
{
return m_Message;
}
VmbErrorType Result() const
{
return m_Result;
}
};
}}}
#endif

View File

@ -0,0 +1,370 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.cpp
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <iomanip>
#ifdef WIN32
#include <Windows.h>
#else
#include <time.h>
#endif //WIN32
#include "FrameObserver.h"
#include "TransformImage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
// [in] eFrameInfos Indicates how the frame will be displayed
// [in] eColorProcessing Indicates how color processing is applied
//
FrameObserver::FrameObserver( CameraPtr pCamera, FrameInfos eFrameInfos, ColorProcessing eColorProcessing, bool bRGBValue )
: IFrameObserver( pCamera )
, m_eFrameInfos( eFrameInfos )
, m_bRGB( bRGBValue )
, m_eColorProcessing( eColorProcessing )
#ifdef WIN32
, m_dFrequency( 0.0 )
#endif //WIN32
{
#ifdef WIN32
LARGE_INTEGER nFrequency;
QueryPerformanceFrequency( &nFrequency );
m_dFrequency = (double)nFrequency.QuadPart;
#endif //WIN32
}
//
// Gets the current timestamp for interval measurement
//
double FrameObserver::GetTime()
{
double dTime = 0.0;
#ifdef WIN32
LARGE_INTEGER nCounter;
QueryPerformanceCounter( &nCounter );
dTime = ( (double)nCounter.QuadPart ) / m_dFrequency;
#else
//clock_t nTime = times(NULL);
//dTime = ((double)(nTime) * 10000.0) / ((double)CLOCKS_PER_SEC);
struct timespec now;
clock_gettime( CLOCK_REALTIME, &now );
dTime = ( (double)now.tv_sec ) + ( (double)now.tv_nsec ) / 1000000000.0;
#endif //WIN32
return dTime;
}
//
// Prints out frame parameters such as
// - width
// - height
// - pixel format
//
// Parameters:
// [in] pFrame The frame to work on
//
void PrintFrameInfo( const FramePtr &pFrame )
{
std::cout<<" Size:";
VmbUint32_t nWidth = 0;
VmbErrorType res;
res = pFrame->GetWidth(nWidth);
if( VmbErrorSuccess == res )
{
std::cout<<nWidth;
}
else
{
std::cout<<"?";
}
std::cout<<"x";
VmbUint32_t nHeight = 0;
res = pFrame->GetHeight(nHeight);
if( VmbErrorSuccess == res )
{
std::cout<< nHeight;
}
else
{
std::cout<<"?";
}
std::cout<<" Format:";
VmbPixelFormatType ePixelFormat = VmbPixelFormatMono8;
res = pFrame->GetPixelFormat( ePixelFormat );
if( VmbErrorSuccess == res )
{
std::cout<<"0x"<<std::hex<<ePixelFormat<<std::dec;
}
else
{
std::cout<<"?";
}
}
//
// Prints out frame status codes as readable status messages
//
// Parameters:
// [in] eFrameStatus The error code to be converted and printed out
//
void PrintFrameStatus( VmbFrameStatusType eFrameStatus )
{
switch( eFrameStatus )
{
case VmbFrameStatusComplete:
std::cout<<"Complete";
break;
case VmbFrameStatusIncomplete:
std::cout<<"Incomplete";
break;
case VmbFrameStatusTooSmall:
std::cout<<"Too small";
break;
case VmbFrameStatusInvalid:
std::cout<<"Invalid";
break;
default:
std::cout<<"unknown frame status";
break;
}
}
//
// Prints out details of a frame such as
// - ID
// - receive status
// - width, height, pixel format
// - current frames per second
//
// Parameters:
// [in] pFrame The frame to work on
//
void FrameObserver::ShowFrameInfos( const FramePtr &pFrame )
{
bool bShowFrameInfos = false;
VmbUint64_t nFrameID = 0;
bool bFrameIDValid = false;
VmbFrameStatusType eFrameStatus = VmbFrameStatusComplete;
bool bFrameStatusValid = false;
VmbErrorType res = VmbErrorSuccess;
double dFPS = 0.0;
bool bFPSValid = false;
VmbUint64_t nFramesMissing = 0;
if( FrameInfos_Show == m_eFrameInfos )
{
bShowFrameInfos = true;
}
res = pFrame->GetFrameID( nFrameID );
if( VmbErrorSuccess == res )
{
bFrameIDValid = true;
if( m_FrameID.IsValid() )
{
if( nFrameID != ( m_FrameID() + 1 ) )
{
nFramesMissing = nFrameID - m_FrameID() - 1;
if( 1 == nFramesMissing )
{
std::cout<<"1 missing frame detected\n";
}
else
{
std::cout<<nFramesMissing<<"missing frames detected\n";
}
}
}
m_FrameID( nFrameID );
double dFrameTime = GetTime();
if( ( m_FrameTime.IsValid() )
&& ( 0 == nFramesMissing ) )
{
double dTimeDiff = dFrameTime - m_FrameTime();
if( dTimeDiff > 0.0 )
{
dFPS = 1.0 / dTimeDiff;
bFPSValid = true;
}
else
{
bShowFrameInfos = true;
}
}
m_FrameTime( dFrameTime );
}
else
{
bShowFrameInfos = true;
m_FrameID.Invalidate();
m_FrameTime.Invalidate();
}
res = pFrame->GetReceiveStatus( eFrameStatus );
if( VmbErrorSuccess == res )
{
bFrameStatusValid = true;
if( VmbFrameStatusComplete != eFrameStatus )
{
bShowFrameInfos = true;
}
}
else
{
bShowFrameInfos = true;
}
if( bShowFrameInfos )
{
std::cout<<"Frame ID:";
if( bFrameIDValid )
{
std::cout<<nFrameID;
}
else
{
std::cout<<"?";
}
std::cout<<" Status:";
if( bFrameStatusValid )
{
PrintFrameStatus( eFrameStatus);
}
else
{
std::cout<<"?";
}
PrintFrameInfo( pFrame );
std::cout<<" FPS:";
if( bFPSValid )
{
std::streamsize s = std::cout.precision();
std::cout<<std::fixed<<std::setprecision(2)<<dFPS<<std::setprecision(s);
}
else
{
std::cout<<"?";
}
std::cout<<"\n";
}
else
{
std::cout<<".";
}
}
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
void FrameObserver::FrameReceived( const FramePtr pFrame )
{
if(! SP_ISNULL( pFrame ) )
{
if( FrameInfos_Off != m_eFrameInfos )
{
ShowFrameInfos( pFrame);
}
VmbFrameStatusType status;
VmbErrorType Result;
Result = SP_ACCESS( pFrame)->GetReceiveStatus( status);
if( VmbErrorSuccess == Result && VmbFrameStatusComplete == status)
{
std::vector<VmbUchar_t> TransformedData;
if ( m_bRGB )
{
switch( m_eColorProcessing )
{
default:
Result = VmbErrorBadParameter;
std::cout<<"unknown color processing parameter\n";
break;
case ColorProcessing_Off:
Result = TransformImage( pFrame, TransformedData, "RGB24" );
break;
case ColorProcessing_Matrix:
{
std::cout<<"Color Transform\n";
const VmbFloat_t Matrix[] = { 0.6f, 0.3f, 0.1f,
0.6f, 0.3f, 0.1f,
0.6f, 0.3f, 0.1f};
Result = TransformImage( pFrame, TransformedData,"BGR24", Matrix );
}
break;
}
if( VmbErrorSuccess == Result && TransformedData.size() >=3 )
{
char old_fill_char = std::cout.fill('0');
std::cout<<std::hex <<"R = 0x"<<std::setw(2)<<(int)TransformedData[0]<<" "
<<"G = 0x"<<std::setw(2)<<(int)TransformedData[1]<<" "
<<"B = 0x"<<std::setw(2)<<(int)TransformedData[2]<<std::dec<<"\n";
std::cout.fill( old_fill_char );
}
else
{
std::cout<<"Transformation failed.\n";
}
}
}
else
{
std::cout<<"frame incomplete\n";
}
}
else
{
std::cout <<" frame pointer NULL\n";
}
m_pCamera->QueueFrame( pFrame );
}
}}} // namespace AVT::VmbAPI::Examples

View File

@ -0,0 +1,113 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.h
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#include <queue>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "ProgramConfig.h"
#ifdef WIN32
#include <Windows.h>
#endif //WIN32
namespace AVT {
namespace VmbAPI {
namespace Examples {
class FrameObserver : virtual public IFrameObserver
{
public:
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
// [in] eFrameInfos Indicates how the frame will be displayed
// [in] eColorProcessing Indicates how color processing is applied
//
FrameObserver( CameraPtr pCamera, FrameInfos eFrameInfos, ColorProcessing eColorProcessing, bool bRGBValue );
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
virtual void FrameReceived( const FramePtr pFrame );
private:
void ShowFrameInfos( const FramePtr & );
double GetTime();
template <typename T>
class ValueWithState
{
private:
T m_Value;
bool m_State;
public:
ValueWithState()
: m_State( false )
{}
ValueWithState( T &value )
: m_Value ( value )
, m_State( true )
{}
const T& operator()() const
{
return m_Value;
}
void operator()( const T &value )
{
m_Value = value;
m_State = true;
}
bool IsValid() const
{
return m_State;
}
void Invalidate()
{
m_State = false;
}
};
const FrameInfos m_eFrameInfos;
const bool m_bRGB;
const ColorProcessing m_eColorProcessing;
ValueWithState<double> m_FrameTime;
ValueWithState<VmbUint64_t> m_FrameID;
#ifdef WIN32
double m_dFrequency;
#endif //WIN32
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@ -0,0 +1,246 @@
/*=============================================================================
Copyright (C) 2014 - 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: ProgrammConfig.h
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.
=============================================================================*/
#ifndef PROGRAM_CONFIG_H_
#define PROGRAM_CONFIG_H_
#include <cstring>
#include "BaseException.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ProgramConfigException: public BaseException
{
public:
ProgramConfigException( const char* const &fun, const char* const& msg, VmbErrorType result = VmbErrorOther )
: BaseException( fun, msg, result )
{
}
~ProgramConfigException() throw()
{}
};
enum FrameInfos
{
FrameInfos_Off,
FrameInfos_Show,
FrameInfos_Automatic
};
enum ColorProcessing
{
ColorProcessing_Off,
ColorProcessing_Matrix,
};
struct ProgramConfig
{
FrameInfos m_FrameInfos;
bool m_RGBValue;
ColorProcessing m_ColorProcessing;
std::string m_CameraID;
bool m_PrintHelp;
bool m_UseAllocAndAnnounce;
public:
ProgramConfig()
: m_FrameInfos( AVT::VmbAPI::Examples::FrameInfos_Off )
, m_RGBValue( false )
, m_ColorProcessing( ColorProcessing_Off )
, m_PrintHelp( false )
, m_UseAllocAndAnnounce( false )
{
}
VmbErrorType ParseCommandline( int argc, char* argv[] )
{
VmbErrorType Result = VmbErrorSuccess;
char * pParameter = NULL; // The command line parameter
for( int i = 1; i < argc; ++i )
{
pParameter = argv[i];
if( 0 >= std::strlen( pParameter ))
{
return VmbErrorBadParameter;
}
if( '/' == pParameter[0] )
{
if( 0 == std::strcmp( pParameter, "/i" ))
{
if( ( FrameInfos_Off != getFrameInfos() )
|| ( getPrintHelp() ))
{
return VmbErrorBadParameter;
}
setFrameInfos( FrameInfos_Show );
}
else if( 0 == std::strcmp( pParameter, "/a" ))
{
if( ( FrameInfos_Off != getFrameInfos() )
|| ( getPrintHelp() ))
{
return VmbErrorBadParameter;
}
setFrameInfos( FrameInfos_Automatic );
}
else if( 0 == std::strcmp( pParameter, "/h" ))
{
if( ( ! getCameraID().empty() )
|| ( getPrintHelp() )
|| ( AVT::VmbAPI::Examples::FrameInfos_Off != getFrameInfos() ))
{
return VmbErrorBadParameter;
}
setPrintHelp( true );
}
else if( 0 == std::strcmp( pParameter, "/r" ))
{
if( getPrintHelp() )
{
return VmbErrorBadParameter;
}
setRGBValue( true );
}
else if( 0 == std::strcmp( pParameter, "/c" ))
{
if( ( ColorProcessing_Off != getColorProcessing() )
|| ( getPrintHelp() ))
{
return VmbErrorBadParameter;
}
setColorProcessing( ColorProcessing_Matrix );
setRGBValue( true );
}
else if( 0 == std::strcmp( pParameter, "/x" ))
{
if( getPrintHelp() )
{
return VmbErrorBadParameter;
}
setAllocAndAnnounce( true );
}
else
{
return VmbErrorBadParameter;
}
}
else
{
if( !getCameraID().empty() )
{
return VmbErrorBadParameter;
}
setCameraID( pParameter );
}
}
return Result;
}
FrameInfos getFrameInfos() const
{
return m_FrameInfos;
}
void setFrameInfos( FrameInfos infos )
{
m_FrameInfos = infos;
}
bool getRGBValue() const
{
return m_RGBValue;
}
void setRGBValue( bool RGBValue )
{
m_RGBValue = RGBValue;
}
ColorProcessing getColorProcessing() const
{
return m_ColorProcessing;
}
void setColorProcessing( ColorProcessing processing )
{
m_ColorProcessing = processing;
}
bool getAllocAndAnnounce() const
{
return m_UseAllocAndAnnounce;
}
void setAllocAndAnnounce( bool useAllocAndAnnounce )
{
m_UseAllocAndAnnounce = useAllocAndAnnounce;
}
const std::string& getCameraID() const
{
return m_CameraID;
}
void setCameraID( const std::string &name )
{
m_CameraID = name;
}
void setCameraID( const char* const&name )
{
if( NULL != name )
{
m_CameraID = std::string( name );
}
else
{
throw ProgramConfigException(__FUNCTION__,"null pointer in name parameter", VmbErrorBadParameter);
}
}
bool getPrintHelp() const
{
return m_PrintHelp;
}
void setPrintHelp( bool state )
{
m_PrintHelp = state;
}
template <typename STREAM_TYPE>
static STREAM_TYPE& PrintHelp( STREAM_TYPE &s )
{
s<<"Usage: AsynchronousGrab [CameraID] [/i] [/h]\n";
s<<"Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
s<<" /i Show frame infos\n";
s<<" /a Automatically only show frame infos of corrupt frames\n";
s<<" /h Print out help\n";
s<<" /r Convert to RGB and show RGB values\n";
s<<" /c Color correction (includes /r)\n";
s<<" /x Use AllocAndAnnounceFrame instead of AnnounceFrame\n";
return s;
}
};
}}}
#endif

View File

@ -0,0 +1,163 @@
/*=============================================================================
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: ImageTransform.h
Description: Image transformation of Vimba images
-------------------------------------------------------------------------------
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 TRANSFORM_IMAGE_H_
#define TRANSFORM_IMAGE_H_
#include <vector>
#include <string>
#include "VmbTransform.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
VmbErrorType TransformImage( const FramePtr & SourceFrame, std::vector<VmbUchar_t> & DestinationData, const std::string &DestinationFormat )
{
if( SP_ISNULL( SourceFrame) )
{
return VmbErrorBadParameter;
}
VmbErrorType Result;
VmbPixelFormatType InputFormat;
VmbUint32_t InputWidth,InputHeight;
Result = SP_ACCESS( SourceFrame )->GetPixelFormat( InputFormat ) ;
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetWidth( InputWidth );
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetHeight( InputHeight );
if( VmbErrorSuccess != Result )
{
return Result;
}
// Prepare source image
VmbImage SourceImage;
SourceImage.Size = sizeof( SourceImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromPixelFormat( InputFormat, InputWidth, InputHeight, &SourceImage ));
if( VmbErrorSuccess != Result )
{
return Result;
}
VmbUchar_t *DataBegin = NULL;
Result = SP_ACCESS( SourceFrame )->GetBuffer( DataBegin );
if( VmbErrorSuccess != Result )
{
return Result;
}
SourceImage.Data = DataBegin;
// Prepare destination image
VmbImage DestinationImage;
DestinationImage.Size = sizeof( DestinationImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromString( DestinationFormat.c_str(), static_cast<VmbUint32_t>(DestinationFormat.size()), InputWidth, InputHeight, &DestinationImage) );
if ( VmbErrorSuccess != Result )
{
return Result;
}
const size_t ByteCount = ( DestinationImage.ImageInfo.PixelInfo.BitsPerPixel * InputWidth* InputHeight ) / 8 ;
DestinationData.resize( ByteCount );
DestinationImage.Data = &*DestinationData.begin();
// Transform data
Result = static_cast<VmbErrorType>( VmbImageTransform( &SourceImage, &DestinationImage, NULL , 0 ));
return Result;
}
VmbErrorType TransformImage( const FramePtr & SourceFrame, std::vector<VmbUchar_t> & DestinationData, const std::string &DestinationFormat, const VmbFloat_t *Matrix )
{
if( SP_ISNULL( SourceFrame ))
{
return VmbErrorBadParameter;
}
if ( NULL == Matrix )
{
return VmbErrorBadParameter;
}
VmbErrorType Result;
VmbPixelFormatType InputFormat;
VmbUint32_t InputWidth,InputHeight;
Result = SP_ACCESS( SourceFrame )->GetPixelFormat( InputFormat ) ;
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetWidth( InputWidth );
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetHeight( InputHeight );
if( VmbErrorSuccess != Result )
{
return Result;
}
// Prepare source image
VmbImage SourceImage;
SourceImage.Size = sizeof( SourceImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromPixelFormat( InputFormat, InputWidth, InputHeight, &SourceImage ));
if( VmbErrorSuccess != Result)
{
return Result;
}
VmbUchar_t *DataBegin = NULL;
Result = SP_ACCESS( SourceFrame )->GetBuffer( DataBegin );
if( VmbErrorSuccess != Result )
{
return Result;
}
SourceImage.Data = DataBegin;
// Prepare destination image
VmbImage DestinationImage;
DestinationImage.Size = sizeof( DestinationImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromString( DestinationFormat.c_str(), static_cast<VmbUint32_t>(DestinationFormat.size()), InputWidth, InputHeight, &DestinationImage ));
if ( VmbErrorSuccess != Result )
{
return Result;
}
const size_t ByteCount = ( DestinationImage.ImageInfo.PixelInfo.BitsPerPixel * InputWidth* InputHeight ) / 8 ;
DestinationData.resize( ByteCount );
DestinationImage.Data = &*DestinationData.begin();
// Setup Transform parameter
// Transform data
VmbTransformInfo TransformInfo;
Result = static_cast<VmbErrorType>( VmbSetColorCorrectionMatrix3x3( Matrix, &TransformInfo ));
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = static_cast<VmbErrorType>( VmbImageTransform( &SourceImage, &DestinationImage, &TransformInfo , 1 ));
return Result;
}
}}}
#endif

View File

@ -0,0 +1,119 @@
/*=============================================================================
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.cpp
Description: Implementation of main entry point of AsynchronousGrabConsole
example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <string>
#include <cstring>
#include <iostream>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "ApiController.h"
int main( int argc, char* argv[] )
{
VmbErrorType err = VmbErrorSuccess;
std::cout<<"///////////////////////////////////////////\n";
std::cout<<"/// Vimba API Asynchronous Grab Example ///\n";
std::cout<<"///////////////////////////////////////////\n\n";
//////////////////////
//Parse command line//
//////////////////////
AVT::VmbAPI::Examples::ProgramConfig Config;
err = Config.ParseCommandline( argc, argv);
//Write out an error if we could not parse the command line
if ( VmbErrorBadParameter == err )
{
std::cout<< "Invalid parameters!\n\n" ;
Config.setPrintHelp( true );
}
//Print out help and end program
if ( Config.getPrintHelp() )
{
Config.PrintHelp( std::cout );
}
else
{
AVT::VmbAPI::Examples::ApiController apiController;
// Print out version of Vimba
std::cout<<"Vimba C++ API Version "<<apiController.GetVersion()<<"\n";
// Startup Vimba
err = apiController.StartUp();
if ( VmbErrorSuccess == err )
{
if( Config.getCameraID().empty() )
{
AVT::VmbAPI::CameraPtrVector cameras = apiController.GetCameraList();
if( cameras.empty() )
{
err = VmbErrorNotFound;
}
else
{
std::string strCameraID;
err = cameras[0]->GetID( strCameraID );
if( VmbErrorSuccess == err )
{
Config.setCameraID( strCameraID );
}
}
}
if ( VmbErrorSuccess == err )
{
std::cout<<"Opening camera with ID: "<<Config.getCameraID()<<"\n";
err = apiController.StartContinuousImageAcquisition( Config );
if ( VmbErrorSuccess == err )
{
std::cout<< "Press <enter> to stop acquisition...\n" ;
getchar();
apiController.StopContinuousImageAcquisition();
}
}
apiController.ShutDown();
}
if ( VmbErrorSuccess == err )
{
std::cout<<"\nAcquisition stopped.\n" ;
}
else
{
std::string strError = apiController.ErrorCodeToMessage( err );
std::cout<<"\nAn error occurred: " << strError << "\n";
}
}
return err;
}

View File

@ -0,0 +1,94 @@
PROJECT_NAME = AsynchronousGrabQt
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)
# Qt 工具路径
MOC = /usr/lib/aarch64-linux-gnu/qt5/bin/moc
UIC = /usr/lib/aarch64-linux-gnu/qt5/bin/uic
RCC = /usr/lib/aarch64-linux-gnu/qt5/bin/rcc
# 使用 pkg-config 获取 Qt 编译标志
QT_CFLAGS := $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)
QT_LIBS := $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
-I$(OBJ_DIR) \
-I/usr/include/aarch64-linux-gnu/qt5 \
-I/usr/include/aarch64-linux-gnu/qt5/QtCore \
-I/usr/include/aarch64-linux-gnu/qt5/QtGui \
-I/usr/include/aarch64-linux-gnu/qt5/QtWidgets
LIBS = $(VIMBACPP_LIBS) \
$(VIMBAIMAGETRANSFORM_LIBS) \
$(QT_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS) \
$(VIMBAIMAGETRANSFORM_CFLAGS) \
$(QT_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
$(OBJ_DIR)/AsynchronousGrab.o \
$(OBJ_DIR)/CameraObserver.o \
$(OBJ_DIR)/FrameObserver.o \
$(OBJ_DIR)/main.o \
$(OBJ_DIR)/moc_AsynchronousGrab.o \
$(OBJ_DIR)/moc_CameraObserver.o \
$(OBJ_DIR)/moc_FrameObserver.o \
$(OBJ_DIR)/qrc_AsynchronousGrab.o
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousGrab.h
DEPENDENCIES = VimbaCPP \
VimbaImageTransform
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
$(MOC) -o $@ $<
$(OBJ_DIR)/ui_%.h: $(SOURCE_DIR)/res/%.ui $(OBJ_DIR)
$(UIC) -o $@ $<
$(OBJ_DIR)/qrc_%.cpp: $(SOURCE_DIR)/res/%.qrc $(OBJ_DIR)
$(RCC) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(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)
.PHONY: all clean

View File

@ -0,0 +1,94 @@
PROJECT_NAME = AsynchronousGrabQt
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)
# Qt 工具路径
MOC = /usr/lib/aarch64-linux-gnu/qt5/bin/moc
UIC = /usr/lib/aarch64-linux-gnu/qt5/bin/uic
RCC = /usr/lib/aarch64-linux-gnu/qt5/bin/rcc
# 使用 pkg-config 获取 Qt 编译标志
QT_CFLAGS := $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)
QT_LIBS := $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
-I$(OBJ_DIR) \
-I/usr/include/aarch64-linux-gnu/qt5 \
-I/usr/include/aarch64-linux-gnu/qt5/QtCore \
-I/usr/include/aarch64-linux-gnu/qt5/QtGui \
-I/usr/include/aarch64-linux-gnu/qt5/QtWidgets
LIBS = $(VIMBACPP_LIBS) \
$(VIMBAIMAGETRANSFORM_LIBS) \
$(QT_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS) \
$(VIMBAIMAGETRANSFORM_CFLAGS) \
$(QT_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
$(OBJ_DIR)/AsynchronousGrab.o \
$(OBJ_DIR)/CameraObserver.o \
$(OBJ_DIR)/FrameObserver.o \
$(OBJ_DIR)/main.o \
$(OBJ_DIR)/moc_AsynchronousGrab.o \
$(OBJ_DIR)/moc_CameraObserver.o \
$(OBJ_DIR)/moc_FrameObserver.o \
$(OBJ_DIR)/qrc_AsynchronousGrab.o
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousGrab.h
DEPENDENCIES = VimbaCPP \
VimbaImageTransform
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
$(MOC) -o $@ $<
$(OBJ_DIR)/ui_%.h: $(SOURCE_DIR)/res/%.ui $(OBJ_DIR)
$(UIC) -o $@ $<
$(OBJ_DIR)/qrc_%.cpp: $(SOURCE_DIR)/res/%.qrc $(OBJ_DIR)
$(RCC) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(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)
.PHONY: all clean

View File

@ -0,0 +1,340 @@
/*=============================================================================
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: ApiController.cpp
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <ApiController.h>
#include <sstream>
#include <iostream>
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
enum { NUM_FRAMES=3, };
ApiController::ApiController()
// Get a reference to the Vimba singleton
: m_system( VimbaSystem::GetInstance() )
{
}
ApiController::~ApiController()
{
}
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ApiController::ErrorCodeToMessage( VmbErrorType eErr ) const
{
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
}
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartUp()
{
VmbErrorType res;
// Start Vimba
res = m_system.Startup();
if( VmbErrorSuccess == res )
{
// This will be wrapped in a shared_ptr so we don't delete it
SP_SET( m_pCameraObserver , new CameraObserver() );
// Register an observer whose callback routine gets triggered whenever a camera is plugged in or out
res = m_system.RegisterCameraListObserver( m_pCameraObserver );
}
return res;
}
//
// Shuts down the API
//
void ApiController::ShutDown()
{
// Release Vimba
m_system.Shutdown();
}
/*** helper function to set image size to a value that is dividable by modulo 2 and a multiple of the increment.
\note this is needed because VimbaImageTransform does not support odd values for some input formats
*/
inline VmbErrorType SetValueIntMod2( const CameraPtr &camera, const std::string &featureName, VmbInt64_t &storage )
{
VmbErrorType res;
FeaturePtr pFeature;
VmbInt64_t minValue = 0;
VmbInt64_t maxValue = 0;
VmbInt64_t incrementValue = 0;
res = SP_ACCESS( camera )->GetFeatureByName( featureName.c_str(), pFeature );
if( VmbErrorSuccess != res )
{
return res;
}
res = SP_ACCESS( pFeature )->GetRange( minValue, maxValue );
if( VmbErrorSuccess != res )
{
return res;
}
res = SP_ACCESS( pFeature )->GetIncrement( incrementValue);
if( VmbErrorSuccess != res)
{
return res;
}
maxValue = maxValue - ( maxValue % incrementValue );
if( maxValue % 2 != 0)
{
maxValue -= incrementValue;
}
res = SP_ACCESS( pFeature )->SetValue( maxValue );
if( VmbErrorSuccess != res )
{
return res;
}
storage = maxValue;
return res;
}
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartContinuousImageAcquisition( const std::string &rStrCameraID )
{
// Open the desired camera by its ID
VmbErrorType res = m_system.OpenCameraByID( rStrCameraID.c_str(), VmbAccessModeFull, m_pCamera );
if( VmbErrorSuccess == res )
{
// 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)
FeaturePtr pCommandFeature;
if( VmbErrorSuccess == SP_ACCESS( m_pCamera )->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ) )
{
if( VmbErrorSuccess == SP_ACCESS( pCommandFeature )->RunCommand() )
{
bool bIsCommandDone = false;
do
{
if( VmbErrorSuccess != SP_ACCESS( pCommandFeature )->IsCommandDone( bIsCommandDone ) )
{
break;
}
} while( false == bIsCommandDone );
}
}
res = SetValueIntMod2( m_pCamera,"Width", m_nWidth );
if( VmbErrorSuccess == res )
{
res = SetValueIntMod2( m_pCamera, "Height", m_nHeight );
if( VmbErrorSuccess == res )
{
// Store currently selected image format
FeaturePtr pFormatFeature;
res = SP_ACCESS( m_pCamera )->GetFeatureByName( "PixelFormat", pFormatFeature );
if( VmbErrorSuccess == res )
{
res = SP_ACCESS( pFormatFeature )->GetValue( m_nPixelFormat );
if ( VmbErrorSuccess == res )
{
// Create a frame observer for this camera (This will be wrapped in a shared_ptr so we don't delete it)
SP_SET( m_pFrameObserver , new FrameObserver( m_pCamera ) );
// Start streaming
res = SP_ACCESS( m_pCamera )->StartContinuousImageAcquisition( NUM_FRAMES, m_pFrameObserver );
}
}
}
}
if ( VmbErrorSuccess != res )
{
// If anything fails after opening the camera we close it
SP_ACCESS( m_pCamera )->Close();
}
}
return res;
}
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StopContinuousImageAcquisition()
{
// Stop streaming
SP_ACCESS( m_pCamera )->StopContinuousImageAcquisition();
// Close camera
return m_pCamera->Close();
}
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector ApiController::GetCameraList()
{
CameraPtrVector cameras;
// Get all known cameras
if( VmbErrorSuccess == m_system.GetCameras( cameras ) )
{
// And return them
return cameras;
}
return CameraPtrVector();
}
//
// Gets the width of a frame
//
// Returns:
// The width as integer
//
int ApiController::GetWidth() const
{
return static_cast<int>(m_nWidth);
}
//
// Gets the height of a frame
//
// Returns:
// The height as integer
//
int ApiController::GetHeight() const
{
return static_cast<int>(m_nHeight);
}
//
// Gets the pixel format of a frame
//
// Returns:
// The pixel format as enum
//
VmbPixelFormatType ApiController::GetPixelFormat() const
{
return static_cast<VmbPixelFormatType>(m_nPixelFormat);
}
//
// Gets the oldest frame that has not been picked up yet
//
// Returns:
// A frame shared pointer
//
FramePtr ApiController::GetFrame()
{
return SP_DYN_CAST( m_pFrameObserver, FrameObserver )->GetFrame();
}
//
// Clears all remaining frames that have not been picked up
//
void ApiController::ClearFrameQueue()
{
SP_DYN_CAST( m_pFrameObserver,FrameObserver )->ClearFrameQueue();
}
//
// Queues a given frame to be filled by the API
//
// Parameters:
// [in] pFrame The frame to queue
//
// Returns:
// An API status code
//
VmbErrorType ApiController::QueueFrame( FramePtr pFrame )
{
return SP_ACCESS( m_pCamera )->QueueFrame( pFrame );
}
//
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
//
QObject* ApiController::GetCameraObserver()
{
return SP_DYN_CAST( m_pCameraObserver, CameraObserver ).get();
}
//
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
//
QObject* ApiController::GetFrameObserver()
{
return SP_DYN_CAST( m_pFrameObserver, FrameObserver ).get();
}
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string ApiController::GetVersion() const
{
std::ostringstream os;
os << m_system;
return os.str();
}
}}} // namespace AVT::VmbAPI::Examples

View File

@ -0,0 +1,191 @@
/*=============================================================================
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: ApiController.h
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_APICONTROLLER
#define AVT_VMBAPI_EXAMPLES_APICONTROLLER
#include <string>
#include <VimbaCPP/Include/VimbaCPP.h>
#include <CameraObserver.h>
#include <FrameObserver.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ApiController
{
public:
ApiController();
~ApiController();
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType StartUp();
//
// Shuts down the API
//
void ShutDown();
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
//
// Returns:
// An API status code
//
VmbErrorType StartContinuousImageAcquisition( const std::string &rStrCameraID );
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType StopContinuousImageAcquisition();
//
// Gets the width of a frame
//
// Returns:
// The width as integer
//
int GetWidth() const;
//
// Gets the height of a frame
//
// Returns:
// The height as integer
//
int GetHeight() const;
//
// Gets the pixel format of a frame
//
// Returns:
// The pixel format as enum
//
VmbPixelFormatType GetPixelFormat() const;
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector GetCameraList();
//
// Gets the oldest frame that has not been picked up yet
//
// Returns:
// A frame shared pointer
//
FramePtr GetFrame();
//
// Queues a given frame to be filled by the API
//
// Parameters:
// [in] pFrame The frame to queue
//
// Returns:
// An API status code
//
VmbErrorType QueueFrame( FramePtr pFrame );
//
// Clears all remaining frames that have not been picked up
//
void ClearFrameQueue();
//
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
//
QObject* GetCameraObserver();
//
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
//
QObject* GetFrameObserver();
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ErrorCodeToMessage( VmbErrorType eErr ) const;
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string GetVersion() const;
private:
// A reference to our Vimba singleton
VimbaSystem& m_system;
// The currently streaming camera
CameraPtr m_pCamera;
// Every camera has its own frame observer
IFrameObserverPtr m_pFrameObserver;
// Our camera observer
ICameraListObserverPtr m_pCameraObserver;
// The current pixel format
VmbInt64_t m_nPixelFormat;
// The current width
VmbInt64_t m_nWidth;
// The current height
VmbInt64_t m_nHeight;
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@ -0,0 +1,354 @@
/*=============================================================================
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.cpp
Description: Qt dialog class for the GUI of the AsynchronousGrab example of
VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include "AsynchronousGrab.h"
#include "VmbTransform.h"
#define NUM_COLORS 3
#define BIT_DEPTH 8
using AVT::VmbAPI::FramePtr;
using AVT::VmbAPI::CameraPtrVector;
AsynchronousGrab::AsynchronousGrab( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
, m_bIsStreaming( false )
{
ui.setupUi( this );
ui.m_LabelStream->setAlignment(Qt::AlignCenter );
// Connect GUI events with event handlers
QObject::connect( ui.m_ButtonStartStop, SIGNAL( clicked() ), this, SLOT( OnBnClickedButtonStartstop() ) );
// Start Vimba
VmbErrorType err = m_ApiController.StartUp();
setWindowTitle( QString( "AsynchronousGrab (Qt version) Vimba C++ API Version " )+ QString::fromStdString( m_ApiController.GetVersion() ) );
Log( "Starting Vimba", err );
if( VmbErrorSuccess == err )
{
// Connect new camera found event with event handler
QObject::connect( m_ApiController.GetCameraObserver(), SIGNAL( CameraListChangedSignal(int) ), this, SLOT( OnCameraListChanged(int) ) );
// Initially get all connected cameras
UpdateCameraListBox();
std::stringstream strMsg;
strMsg << "Cameras found..." << m_cameras.size();
Log(strMsg.str() );
}
}
AsynchronousGrab::~AsynchronousGrab()
{
// if we are streaming stop streaming
if( true == m_bIsStreaming )
{
OnBnClickedButtonStartstop();
}
// Before we close the application we stop Vimba
m_ApiController.ShutDown();
}
void AsynchronousGrab::OnBnClickedButtonStartstop()
{
VmbErrorType err;
int nRow = ui.m_ListBoxCameras->currentRow();
if( -1 < nRow )
{
if( false == m_bIsStreaming )
{
// Start acquisition
err = m_ApiController.StartContinuousImageAcquisition( m_cameras[nRow] );
// Set up Qt image
if ( VmbErrorSuccess == err )
{
m_Image = QImage( m_ApiController.GetWidth(),
m_ApiController.GetHeight(),
QImage::Format_RGB888 );
QObject::connect( m_ApiController.GetFrameObserver(), SIGNAL( FrameReceivedSignal(int) ), this, SLOT( OnFrameReady(int) ) );
}
Log( "Starting Acquisition", err );
m_bIsStreaming = VmbErrorSuccess == err;
}
else
{
m_bIsStreaming = false;
// Stop acquisition
err = m_ApiController.StopContinuousImageAcquisition();
// Clear all frames that we have not picked up so far
m_ApiController.ClearFrameQueue();
m_Image = QImage();
Log( "Stopping Acquisition", err );
}
if( false == m_bIsStreaming )
{
ui.m_ButtonStartStop->setText( QString( "Start Image Acquisition" ) );
}
else
{
ui.m_ButtonStartStop->setText( QString( "Stop Image Acquisition" ) );
}
}
}
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the frame observer
//
// Parameters:
// [in] status The frame receive status (complete, incomplete, ...)
//
void AsynchronousGrab::OnFrameReady( int status )
{
if( true == m_bIsStreaming )
{
// Pick up frame
FramePtr pFrame = m_ApiController.GetFrame();
if( SP_ISNULL( pFrame ) )
{
Log("frame pointer is NULL, late frame ready message");
return;
}
// See if it is not corrupt
if( VmbFrameStatusComplete == status )
{
VmbUchar_t *pBuffer;
VmbErrorType err = SP_ACCESS( pFrame )->GetImage( pBuffer );
if( VmbErrorSuccess == err )
{
VmbUint32_t nSize;
err = SP_ACCESS( pFrame )->GetImageSize( nSize );
if( VmbErrorSuccess == err )
{
VmbPixelFormatType ePixelFormat = m_ApiController.GetPixelFormat();
if( ! m_Image.isNull() )
{
// Copy it
// We need that because Qt might repaint the view after we have released the frame already
if( ui.m_ColorProcessingCheckBox->checkState()== Qt::Checked )
{
static const VmbFloat_t Matrix[] = { 8.0f, 0.1f, 0.1f, // this matrix just makes a quick color to mono conversion
0.1f, 0.8f, 0.1f,
0.0f, 0.0f, 1.0f };
if( VmbErrorSuccess != CopyToImage( pBuffer,ePixelFormat, m_Image, Matrix ) )
{
ui.m_ColorProcessingCheckBox->setChecked( false );
}
}
else
{
CopyToImage( pBuffer,ePixelFormat, m_Image );
}
// Display it
const QSize s = ui.m_LabelStream->size() ;
ui.m_LabelStream->setPixmap( QPixmap::fromImage( m_Image ).scaled(s,Qt::KeepAspectRatio ) );
}
}
}
}
else
{
// If we receive an incomplete image we do nothing but logging
Log( "Failure in receiving image", VmbErrorOther );
}
// And queue it to continue streaming
m_ApiController.QueueFrame( pFrame );
}
}
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the camera observer
//
// Parameters:
// [in] reason The reason why the callback of the observer was triggered (plug-in, plug-out, ...)
//
void AsynchronousGrab::OnCameraListChanged( int reason )
{
bool bUpdateList = false;
// We only react on new cameras being found and known cameras being unplugged
if( AVT::VmbAPI::UpdateTriggerPluggedIn == reason )
{
Log( "Camera list changed. A new camera was discovered by Vimba." );
bUpdateList = true;
}
else if( AVT::VmbAPI::UpdateTriggerPluggedOut == reason )
{
Log( "Camera list changed. A camera was disconnected from Vimba." );
if( true == m_bIsStreaming )
{
OnBnClickedButtonStartstop();
}
bUpdateList = true;
}
if( true == bUpdateList )
{
UpdateCameraListBox();
}
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
}
//
// Copies the content of a byte buffer to a Qt image with respect to the image's alignment
//
// Parameters:
// [in] pInbuffer The byte buffer as received from the cam
// [in] ePixelFormat The pixel format of the frame
// [out] OutImage The filled Qt image
//
VmbErrorType AsynchronousGrab::CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, QImage &pOutImage, const float *Matrix /*= NULL */ )
{
const int nHeight = m_ApiController.GetHeight();
const int nWidth = m_ApiController.GetWidth();
VmbImage SourceImage,DestImage;
VmbError_t Result;
SourceImage.Size = sizeof( SourceImage );
DestImage.Size = sizeof( DestImage );
Result = VmbSetImageInfoFromPixelFormat( ePixelFormat, nWidth, nHeight, & SourceImage );
if( VmbErrorSuccess != Result )
{
Log( "Could not set source image info", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
QString OutputFormat;
const int bytes_per_line = pOutImage.bytesPerLine();
switch( pOutImage.format() )
{
default:
Log( "unknown output format",VmbErrorBadParameter );
return VmbErrorBadParameter;
case QImage::Format_RGB888:
if( nWidth*3 != bytes_per_line )
{
Log( "image transform does not support stride",VmbErrorWrongType );
return VmbErrorWrongType;
}
OutputFormat = "RGB24";
break;
}
Result = VmbSetImageInfoFromString( OutputFormat.toStdString().c_str(), OutputFormat.length(),nWidth,nHeight, &DestImage );
if( VmbErrorSuccess != Result )
{
Log( "could not set output image info",static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
SourceImage.Data = pInBuffer;
DestImage.Data = pOutImage.bits();
// do color processing?
if( NULL != Matrix )
{
VmbTransformInfo TransformParameter;
Result = VmbSetColorCorrectionMatrix3x3( Matrix, &TransformParameter );
if( VmbErrorSuccess == Result )
{
Result = VmbImageTransform( &SourceImage, &DestImage, &TransformParameter,1 );
}
else
{
Log( "could not set matrix t o transform info ", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
}
else
{
Result = VmbImageTransform( &SourceImage, &DestImage,NULL,0 );
}
if( VmbErrorSuccess != Result )
{
Log( "could not transform image", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
return static_cast<VmbErrorType>( Result );
}
//
// Queries and lists all known camera
//
void AsynchronousGrab::UpdateCameraListBox()
{
// Get all cameras currently connected to Vimba
CameraPtrVector cameras = m_ApiController.GetCameraList();
// Simply forget about all cameras known so far
ui.m_ListBoxCameras->clear();
m_cameras.clear();
// And query the camera details again
for( CameraPtrVector::const_iterator iter = cameras.begin();
cameras.end() != iter;
++iter )
{
std::string strCameraName;
std::string strCameraID;
if( VmbErrorSuccess != (*iter)->GetName( strCameraName ) )
{
strCameraName = "[NoName]";
}
// If for any reason we cannot get the ID of a camera we skip it
if( VmbErrorSuccess == (*iter)->GetID( strCameraID ) )
{
ui.m_ListBoxCameras->addItem( QString::fromStdString( strCameraName + " " +strCameraID ) );
m_cameras.push_back( strCameraID );
}
}
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
}
//
// Prints out a given logging string, error code and the descriptive representation of that error code
//
// Parameters:
// [in] strMsg A given message to be printed out
// [in] eErr The API status code
//
void AsynchronousGrab::Log( std::string strMsg, VmbErrorType eErr )
{
strMsg += "..." + m_ApiController.ErrorCodeToMessage( eErr );
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
}
//
// Prints out a given logging string
//
// Parameters:
// [in] strMsg A given message to be printed out
//
void AsynchronousGrab::Log( std::string strMsg)
{
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
}

Some files were not shown because too many files have changed in this diff Show More