Baumer-GAPI2 SDK Programmer's Guide - Site ftp Elvitec
Baumer-GAPI2 SDK Programmer's Guide - Site ftp Elvitec
Baumer-GAPI2 SDK Programmer's Guide - Site ftp Elvitec
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Baumer</strong>-<strong>GAPI2</strong> <strong>SDK</strong><br />
Programmer‘s <strong>Guide</strong>
Table of Contents<br />
1. Introduction .............................................................................................................. 5<br />
2. <strong>Baumer</strong>-<strong>GAPI2</strong> .......................................................................................................... 5<br />
2.1 <strong>Baumer</strong>-<strong>GAPI2</strong> Stack Components ........................................................................ 5<br />
2.1.1 Hardware ......................................................................................................... 5<br />
2.1.2 <strong>Baumer</strong> GenICam-API...................................................................................... 5<br />
2.2 Software Components ............................................................................................ 6<br />
2.2.1 <strong>Baumer</strong>-<strong>GAPI2</strong> Modules .................................................................................. 6<br />
2.3 Gerneral System Requirements .............................................................................. 6<br />
3. Central Idea Behind B<strong>GAPI2</strong> ................................................................................... 8<br />
3.1 Interface Classes ................................................................................................... 9<br />
3.1.1 INode, NodeMap, Node .................................................................................... 9<br />
3.1.2 EventControl ................................................................................................... 12<br />
3.2 Main Classes ........................................................................................................ 14<br />
3.2.1 System............................................................................................................ 14<br />
3.2.2 Interface.......................................................................................................... 15<br />
3.2.3 Device............................................................................................................. 15<br />
3.2.4 DataStream .................................................................................................... 16<br />
3.2.5 Buffer .............................................................................................................. 17<br />
3.3 List Classes ........................................................................................................... 18<br />
3.3.1 SystemList ...................................................................................................... 19<br />
3.3.2 InterfaceList .................................................................................................... 19<br />
3.3.3 DeviceList ....................................................................................................... 19<br />
3.3.4 DataStreamList ............................................................................................... 19<br />
3.3.5 BufferList ........................................................................................................ 20<br />
3.4 Additional Classes ................................................................................................. 22<br />
3.4.1 Image.............................................................................................................. 22<br />
3.4.2 Image Processor ............................................................................................ 23<br />
3.4.3 Trace............................................................................................................... 24<br />
3.5 IException ............................................................................................................ 25<br />
4. Programming Basics in <strong>Baumer</strong>-<strong>GAPI2</strong> ............................................................... 26<br />
4.1 Setting System variables ...................................................................................... 27<br />
4.2 Implementation ..................................................................................................... 28<br />
4.2.1 Implementation C++ ....................................................................................... 28<br />
4.2.2 Implementation in C# ..................................................................................... 30<br />
5. Application development with <strong>Baumer</strong>-GAPI ..................................................... 33<br />
5.1 First steps ............................................................................................................. 33<br />
5.1.1 Preparation ..................................................................................................... 34<br />
5.1.2 SystemList ...................................................................................................... 35<br />
5.1.3 Open a System ............................................................................................... 35<br />
5.1.4 Get the InterfaceList and fill it ......................................................................... 36<br />
5.1.5 Open an Interface ........................................................................................... 36<br />
5.1.6 Get the DeviceList and fill it ............................................................................ 36<br />
5.1.7 Open a Device ................................................................................................ 37<br />
5.1.8 Get DataStreamList and fill it .......................................................................... 37<br />
5.1.9 Open a DataStream ....................................................................................... 38<br />
5.1.10 Create the BufferList and allocate Buffer memory ........................................ 38<br />
5.1.11 Allocate Image Buffer to the DataStream ..................................................... 39<br />
5.1.12 Start Camera and fill the Image Buffer ......................................................... 40<br />
5.1.13 Releasing the resources ............................................................................... 41<br />
3
Application (image processing interface written by the customer)<br />
Customer<br />
C# module<br />
C# Component<br />
Framework (OS module)<br />
Operating<br />
system<br />
Framework:<br />
<strong>Baumer</strong>-GAPI 2 is tested<br />
with Windows ® : .NET<br />
4.0<br />
Image Library<br />
Image<br />
process ng<br />
Co or<br />
management<br />
Algorithms<br />
C++ API<br />
<strong>Baumer</strong> <strong>GAPI2</strong> Library<br />
<strong>Baumer</strong>-<strong>GAPI2</strong><br />
GenTL Consumer<br />
interface X<br />
Plug in<br />
Gigabit Ethernet<br />
Plug in<br />
USB 3 0<br />
Plug in<br />
GenTL Producer<br />
TCP/IP<br />
stack<br />
<strong>Baumer</strong><br />
Driver X<br />
<strong>Baumer</strong> Filter Driver<br />
(optional)<br />
<strong>Baumer</strong> USB 3 0<br />
Device Driver<br />
Hardware<br />
Driver X<br />
Hardware<br />
Driver NIC<br />
Bus Driver<br />
Hardware Driver<br />
Figure 1 ►<br />
BGAPI 2 stack<br />
Hardware X<br />
Network Inte face<br />
Card (NIC)<br />
USB 3 0 Host Con roller<br />
Hardware<br />
4
1. Introduction<br />
This programmer’s guide is addressed to programmers who need to integrate <strong>Baumer</strong><br />
cameras into their own software. It corresponds to the GenICam API of <strong>Baumer</strong>-<strong>GAPI2</strong><br />
and the use of Microsoft ® Visual Studio ® from version 2005 (C++) and version 2010 (C#).<br />
2. <strong>Baumer</strong>-<strong>GAPI2</strong><br />
<strong>Baumer</strong>-<strong>GAPI2</strong> is the abbreviation for <strong>Baumer</strong> “Generic Application Programming Interface”<br />
in version 2. With this API <strong>Baumer</strong> provides an interface for optimal integration and<br />
control of <strong>Baumer</strong> cameras.<br />
The fundamental basis for B<strong>GAPI2</strong> is the GenICam (Generic Interface for Cameras) standard<br />
and the employment of GenTL as standardized interface.<br />
B<strong>GAPI2</strong> provides interfaces to several programming languages as C++ and to the .NET<br />
Framework on Windows ® operating systems, which in turn allow the use of other languages<br />
such as C# or VB.NET.<br />
2.1 <strong>Baumer</strong>-<strong>GAPI2</strong> Stack Components<br />
2.1.1<br />
Hardware<br />
2.1.1.1 Gigabit Ethernet<br />
Working with <strong>Baumer</strong> Gigabit Ethernet cameras requires the installation of appropriate<br />
hardware – such as a NIC (Network Interface Card) on your PC.<br />
Notice<br />
For Gigabit Ethernet <strong>Baumer</strong> recommends the employment of NICs with an Intel ® chipset.<br />
The hardware is delivered with a hardware driver which is required in order to establish<br />
communications between hardware and software.<br />
Installation:<br />
For further information on<br />
installing the <strong>Baumer</strong>-GAPI<br />
<strong>SDK</strong> refer to the appropriate<br />
Installation <strong>Guide</strong> for<br />
your operating system and<br />
hardware interface.<br />
API:<br />
API stands for “Application<br />
Programming Interface”.<br />
An API is a software<br />
interface between two<br />
programs, usually between<br />
operating system and an<br />
application.<br />
GenICam:<br />
GenICam stands for<br />
Generic Interface for<br />
Cameras and is a generic<br />
programming interface<br />
for industrial cameras. It’s<br />
goal is to decouple industrial<br />
camera interfaces<br />
from the user application<br />
programming interface<br />
(API).<br />
2.1.2<br />
<strong>Baumer</strong> GenICam-API<br />
Programmer<br />
2.1.2.1<br />
Producer<br />
Within the GenICam Producer a complete camera system is mapped to the software. The<br />
Producer provides the 5 main classes that are used in any B<strong>GAPI2</strong> application.<br />
2.1.2.2<br />
Consumer<br />
CameraL nk®<br />
GigE Vis on®<br />
(GEV)<br />
USB3Vision<br />
▲ Figure 2<br />
The GenICam vision<br />
The consumer is the counterpart of the producer mentioned above. Here all the available<br />
producers are managed (loading, opening, closing).<br />
Furthermore the consumer provides all additional classes and enables the exception handling.<br />
2.1.2.3<br />
Framework<br />
A Framework represents a software platform, which provides a runtime environment, an<br />
API and several services to the programmer. It is required, for example, when programming<br />
in C# or VB.NET.<br />
5
2.2<br />
Software Components<br />
The B<strong>GAPI2</strong> is package of several libraries in form of dynamic link libraries (dll's). Thereat<br />
previously mentioned GenTL producer represents an exception. The producer is delivered<br />
as a common transport interface (.cti-file).<br />
2.2.1 <strong>Baumer</strong>-<strong>GAPI2</strong> Modules<br />
The <strong>Baumer</strong>-<strong>GAPI2</strong> is partitioned into several modules. Depending on your chosen programming<br />
language, either more or fewer of these may be used.<br />
2.2.1.1 <strong>Baumer</strong>-<strong>GAPI2</strong> Library<br />
As previously stated, <strong>Baumer</strong>-<strong>GAPI2</strong> supports several programming languages to create<br />
an application. Therefore the <strong>Baumer</strong>-<strong>GAPI2</strong> Library represents a uniform API for the<br />
cross-interface camera control. Here, global camera control functions are defined.<br />
2.2.1.2 Image Library<br />
This library includes several functions for image processing and image editing.<br />
2.2.1.3<br />
Programming Languages<br />
This means that the C++ API and C# API resorts directly to the B<strong>GAPI2</strong> library.<br />
2.3<br />
Gerneral System Requirements<br />
Single-camera system<br />
Recommended<br />
Multi-camera system<br />
Recommended<br />
CPU DUAL-Core, Intel ® Xeon ® W3503 DUAL-Core, Intel ® Xeon ® W3503<br />
Clock 2.4 GHz 2.4 GHz<br />
RAM 4 GB 4 GB<br />
Operating<br />
system<br />
(OS)<br />
Compiler<br />
As shown in Figure 1, the implementation of C++ and C# is partially realized hierarchically.<br />
Framework<br />
(optional)<br />
Microsoft ® Windows ® 7 32 / 64 bit systems (required for USB 3.0)<br />
Microsoft ® Windows ® 8 32 / 64 bit systems (required for USB 3.0)<br />
Microsoft Compiler only<br />
(included in Microsoft ® Visual Studio)<br />
Windows ® OS: .NET Framework 4.0 or higher for C# implementation<br />
6
Namespace: B<strong>GAPI2</strong><br />
INODE<br />
NODEMAP<br />
Interface<br />
Classes<br />
NODE<br />
Main<br />
Classes<br />
List<br />
Classes<br />
SystemList<br />
Additional<br />
Classes<br />
Image<br />
Namespace: Exceptions<br />
Exception<br />
Classes<br />
ErrorException<br />
NotInitializedException<br />
NotImplementedException<br />
Classes of B<strong>GAPI2</strong><br />
Namespace: Events<br />
EventControl<br />
Interface<br />
EventControl<br />
Device<br />
EventControl<br />
DataStream<br />
EventControl<br />
PnPEvent DeviceEvent<br />
System Interface Device DataStream Buffer<br />
InterfaceList<br />
DeviceList DataStreamList BufferList<br />
Image<br />
Processor<br />
Trace<br />
IException<br />
ResourceInUseException<br />
InvalidIdException<br />
IOException<br />
NotAvailableException<br />
AccessDeniedException<br />
NoDataException<br />
AbortException<br />
SysVarMissingException<br />
InvalidHandleException<br />
InvalidParameterException<br />
InvalidBufferException<br />
▲ Figure 3<br />
Classes of B<strong>GAPI2</strong><br />
7
3. Central Idea Behind B<strong>GAPI2</strong><br />
The fundamental idea behind the <strong>Baumer</strong> <strong>SDK</strong> was to free the programmer from need of<br />
defining and instantiating all the required and usable objects and to transfer these tasks<br />
to the B<strong>GAPI2</strong>.<br />
The API bases on five main classes (System, Interface, Device, DataStream, Buffer) and<br />
the use of the GenTL interface.<br />
On B<strong>GAPI2</strong> there are two entry points for the user. On one hand, application programming<br />
can be started by using the system list. On the other hand B<strong>GAPI2</strong> offers the possibility<br />
to use the image processor separately.<br />
B<strong>GAPI2</strong><br />
Entry point<br />
Programmer<br />
GenAPI<br />
GenTL<br />
Third Party To ols<br />
Consumer<br />
Producer 1<br />
Producer 2<br />
e g GigE S andard e g bgapi gige<br />
Producer<br />
Customer<br />
Application<br />
Consumer<br />
Producer 3<br />
e g bgapi2 usb c i<br />
<strong>Baumer</strong><br />
GenICam API<br />
SystemList<br />
System 0<br />
System 1<br />
...<br />
NodeList<br />
NodeTree<br />
Node 0<br />
Node 1<br />
...<br />
Node n<br />
System<br />
InterfaceList<br />
Interface 0<br />
Interface 1<br />
...<br />
Interface n<br />
Image<br />
Processor<br />
Image<br />
▲ Figure 3<br />
Fundamental Approach<br />
of GenAPI and GenTL<br />
NodeList<br />
NodeTree<br />
Node 0<br />
Node 1<br />
...<br />
Node n<br />
Interface<br />
DeviceList<br />
Device 0<br />
Device 1<br />
...<br />
Device n<br />
(Remote-)<br />
NodeList<br />
(Remote-)<br />
NodeTree<br />
Node 0<br />
Node 1<br />
...<br />
Node n<br />
Device<br />
DataStreamList<br />
Data Stream 0<br />
Data Stream 1<br />
...<br />
Data Stream n<br />
DataStream<br />
NodeList<br />
NodeTree<br />
Node 0<br />
Node 1<br />
...<br />
Node n<br />
BufferList<br />
Buffer 0<br />
Buffer 1<br />
...<br />
Buffer n<br />
Buffer<br />
NodeList<br />
NodeTree<br />
Figure 4 ►<br />
Interaction diagram<br />
Node 0<br />
Node 1<br />
...<br />
Node n<br />
8
3.1<br />
Interface Classes<br />
The major part of the functionality of B<strong>GAPI2</strong> is provided by the two interface classes<br />
NodeInterface and EventInterface. For instance the main classes inhertit functionalities<br />
from INode.<br />
3.1.1<br />
INode, NodeMap, Node<br />
INode<br />
The INode class allows the direct access to all components<br />
of the xml-file.<br />
Parent class for:<br />
System<br />
Interface<br />
Device DataStream<br />
Buffer<br />
Functions of the class INode<br />
B<strong>GAPI2</strong>::INode:: ...<br />
GetNode(String name);<br />
GetNodeTree();<br />
GetNodeList();<br />
Returns a pointer to a specified object of the Node<br />
class.<br />
Returns the tree view of all nodes of the XML file.<br />
Returns a one-dimensional list of the nodes of the XML<br />
file.<br />
NodeMap<br />
NodeMap is the collection class for nodes.<br />
Member of INode<br />
Functions of the class NodeMap<br />
B<strong>GAPI2</strong>::NodeMap:: ...<br />
GetNode(String name);<br />
GetNodeTree();<br />
GetNodeList();<br />
Returns a pointer to a specified object of the Node<br />
class.<br />
Returns the tree view of all nodes of the XML file<br />
Returns a one-dimensional list of the nodes of the XML<br />
file.<br />
9
NODE<br />
Member of INode<br />
A Node presents one feature from the XML description<br />
file.<br />
Functions of the class Node<br />
B<strong>GAPI2</strong>::Node:: ...<br />
10<br />
GetInterface();<br />
GetExtension();<br />
GetToolTip();<br />
GetDescription();<br />
GetName();<br />
GetDisplayName();<br />
GetVisibility();<br />
GetImplemented();<br />
GetAvailable();<br />
GetLocked();<br />
GetImposedAccessMode();<br />
GetCurrentAccessMode();<br />
GetAlias();<br />
GetRepresentation();<br />
GetUnit();<br />
HasUnit();<br />
GetEventID();<br />
Enumeration value<br />
GetEnumNodeList();<br />
Returns the inferface of the respective Node.<br />
Returns custom specific data from the XML-file.<br />
Returns a Tool-Tip.<br />
Returns the the description of the feature.<br />
Returns the name of the feature.<br />
Returns a meaningful for displaying in Graphical User<br />
Inferfaces (GUI).<br />
Returns the visibility of the node (Invisible, Beginner,<br />
Expert, Guru).<br />
Returns the status of implementation of the feature.<br />
Returns the availability of the feature.<br />
Returns information whether the feature is locked<br />
(read only) or not.<br />
Returns the the startup behavior of the feature<br />
Returns the current access mode<br />
Returns the name of another node which decribes the<br />
same feature in a different manner<br />
Gives a hint how to display the feature within the application<br />
(GUI).<br />
Returns the unit of the feature [e.g. ms, Hz].<br />
Query whether the feature has a unit.<br />
Returns the ID of an event.<br />
Returns a list of Enum Entries of the feature.<br />
Set value in string format (General purpose function)<br />
GetValue();<br />
Retrieving values as a converted string.<br />
SetValue( String<br />
Value );<br />
Setting a value as string, regardless of the interface<br />
type (it will be converted from string).<br />
Integer functions (only for Integer Interface)<br />
GetInt();<br />
Retrieving of values.<br />
SetInt( bo_int64<br />
Setting values as an integer.<br />
value );<br />
GetIntMin();<br />
Returns the minimum value.<br />
GetIntMax();<br />
Returns the maximum value.<br />
GetIntInc();<br />
Returns the step size for setting a value.<br />
Float functions (only for Float Interface)<br />
GetDouble();<br />
Retrieving of value.<br />
SetDouble( bo_double Setting values as an float.<br />
value );<br />
GetDoubleMin();<br />
Returns the minimum value.<br />
GetDoubleMax();<br />
Returns the maximum value.<br />
String functions (only for String interface)
GetMaxStringLength(); Retrieving the maximum length of the string.<br />
GetString();<br />
Retrieving of values.<br />
SetString( String Setting values as an string.<br />
value );<br />
Command value (only for Command Interface)<br />
Execute();<br />
One-time exexution of a command.<br />
IsDone();<br />
Query, whether the command has been executed.<br />
Boolean value (only for Bool Interface)<br />
GetBool();<br />
Retrieving of the values (true / false).<br />
SetBool( bo_bool value Setting boolean values.<br />
);<br />
Access type (only for Category interface)<br />
GetNodeTree();<br />
Returns the tree view of all nodes.<br />
GetNodeList();<br />
Returns a one-dimensional list of the nodes.<br />
Selectors<br />
IsSelector();<br />
Query, whether the feature is a selector.<br />
GetSelectedNodeList(); Returns a list of features that are influenced by the<br />
Selector.<br />
Register access (only for Register Interface)<br />
getLength();<br />
Read a length of an address.<br />
getAdress();<br />
Read an address.<br />
get( void *pBuffer, Read a register.<br />
bo_unint64 len);<br />
set(void *pBuffer, Write a register.<br />
bo_uint64 len);<br />
11
3.1.2<br />
EventControl<br />
This class provides access to custom events as well as the event node.<br />
3.1.2.1<br />
InterfaceEventControl<br />
Interface EventControl<br />
Inherits from:<br />
EventControl<br />
InterfaceEventControl provides the Plug´n Play<br />
event.<br />
Parent class for:<br />
Interface<br />
Functions of the class InterfaceEventControl<br />
B<strong>GAPI2</strong>::InterfaceEventControl:: ...<br />
RegisterPnPEvent(EventMode<br />
eventMode);<br />
UnregisterPnPEvent();<br />
GetPnPEvent(PnPEvent * pPnPEvent,<br />
bo_using64 iTimeout);<br />
Enables the P´n´P Eventhandling.<br />
Disables the P´n´P Eventhandling.<br />
Polling function for the P´n´P Events.<br />
3.1.2.2<br />
DeviceEventControl<br />
Device EventControl<br />
This class provides access to standard events.<br />
Inherits from:<br />
Eventcontrol<br />
Parent class for:<br />
Device<br />
Functions of the class Device EventControl<br />
B<strong>GAPI2</strong>::DeviceEventControl:: ...<br />
RegisterDeviceEvent(Event<br />
eventMode);<br />
UnregisterDeviceEvent();<br />
GetDeviceEvent(DeviceEvent<br />
* pDeviceEvent, bo_uint64<br />
iTimeout);<br />
Enables standard compliant device events, specified<br />
within the xml description file.<br />
Disable standard compliant device events, specified<br />
within the xml description file.<br />
Polling function for event devices.<br />
12
3.1.2.3<br />
DataStreamEventControl<br />
DataStreamEventControl<br />
Inherits from:<br />
EventControl<br />
DataStreamEventControl provices "new Bufferevent",<br />
which is used a image notification.<br />
Parent class for:<br />
DataStream<br />
Functions of the class DataStream EventControl<br />
B<strong>GAPI2</strong>::DataStreamEventControl:: ...<br />
RegisterNewBufferEvent();<br />
UnregisterNewBuffer-<br />
Event();<br />
GetFilledBuffer(bo_uint64<br />
iTimeout);<br />
CancelGetFilledBuffer();<br />
Enables standard compliant buffer events specified<br />
within the xml description file.<br />
Disables tandard compliant buffer events specified<br />
within the xml description file.<br />
Polling with timeout.<br />
Cancellation routine for GetfilledBuffer.<br />
13
3.2<br />
Main Classes<br />
The main classes represent the fundamental logical and physical components of the image<br />
processing system.<br />
The main classes are: System, Interface, Device, DataStream and Buffer.<br />
3.2.1<br />
System<br />
System<br />
Inherits from:<br />
EventControl<br />
INode<br />
The System is the abstraction of the Producer and previously<br />
mentioned producer.<br />
Functions of the class System<br />
B<strong>GAPI2</strong>::System:: ...<br />
System(String filepath);<br />
Open();<br />
Close();<br />
GetInterfaces();<br />
GetID();<br />
GetVendor();<br />
GetModel();<br />
GetVersion();<br />
Setting the path to the producer file.<br />
Open a System (producer file).<br />
Close the System (producer file).<br />
Returns a list of all available interfaces (InterfaceList).<br />
Returns the unique string identifier of the System, which is<br />
used in the SystemList.<br />
Returns the name of the producer vendor.<br />
Returns the model name of the producer.<br />
Returns the version number of system file.<br />
GetTLType(); Returns type of System (GEV, USB3, ...) .<br />
GetName();<br />
GetPathName();<br />
GetDisplayName();<br />
Returns the name of system file.<br />
Retrieving the filepath.<br />
Returns a meaningful name of the System for display only.<br />
14
3.2.2<br />
Interface<br />
Interface<br />
Inherits from:<br />
Interface EventControl<br />
INode<br />
The class Interface represents a physical interface, e.g.<br />
GEV or a logical interface, such as USB.<br />
Functions of the class Interface<br />
B<strong>GAPI2</strong>::Interface:: ...<br />
Open();<br />
Close();<br />
GetDevices();<br />
GetID();<br />
GetDisplayName();<br />
Open an Interface.<br />
Close the Interface.<br />
Returns the list of available devices for this interface (DeviceList).<br />
Returns the unique string ID which is used in InterfaceList.<br />
Returns a meaningful name of the Interface for display only.<br />
GetTLType(); Returns interface type (GEV, USB, ...).<br />
3.2.3<br />
Device<br />
Device<br />
Inherits from:<br />
Device EventControl<br />
INode<br />
The main class Device is used to retrieve information<br />
(e.g. model, manufacturer, access modes) of the device<br />
(camera) and also to control the device.<br />
Functions of the class Device<br />
B<strong>GAPI2</strong>::Device:: ...<br />
OpenReadOnly();<br />
Open();<br />
OpenExclusive();<br />
Close();<br />
IsOpen();<br />
StartStacking();<br />
WriteStack();<br />
GetDataStreams();<br />
GetID();<br />
GetVendor();<br />
Open as read only, no parameters can be changed.<br />
Open a device with read and write access.<br />
Open a device exclusively with read and write access, the<br />
device is blocked for other software tools.<br />
Close the device.<br />
Open a device with read only access, changing parameters<br />
is denied.<br />
Start command for parameter stacking (parameters will be<br />
queued).<br />
Single write command to transmit all stacked parameters<br />
at once.<br />
Returns a list of available DataStreams.<br />
Returns the unique string ID of device (such as MAC address<br />
on GEV).<br />
Returns the vendor of the camera.<br />
15
GetModel();<br />
GetTLType();<br />
GetDisplayName();<br />
GetAccessStatus();<br />
GetPayloadSize();<br />
GetRemoteNode<br />
(String name);<br />
GetRemoteNode-<br />
Tree();<br />
GetRemoteNodeList();<br />
GetRemoteConfigurationFile();<br />
Returns the camera model (e.g. MXGC20c).<br />
Returns the device type of system (such as GEV,<br />
USB3, ...).<br />
Returns a meaningful name, for display only.<br />
Returns how the device is / can be opened:<br />
Open();<br />
OpenReadOnly();<br />
OpenExclusive();<br />
Returns the Payloadsize.<br />
Returns a pointer to a specified object of the connected<br />
device.<br />
Returns the tree view of all nodes of the XML file of the<br />
connected device.<br />
Returns a one-dimensional list of the nodes of the XML file<br />
of the connected devices.<br />
Returns the XML description file of the connected device.<br />
3.2.4<br />
DataStream<br />
DataStream<br />
This class is responsable for the buffer handling.<br />
Inherits from:<br />
DataStream EventControl<br />
Node<br />
Functions of the class DataStream<br />
B<strong>GAPI2</strong>::DataStream:: ...<br />
Open();<br />
Close();<br />
GetBufferList();<br />
GetID();<br />
GetPayloadSize();<br />
GetDefinesPayload-<br />
Size();<br />
GetIsGrabbing();<br />
GetTLType();<br />
StartAcquisition<br />
(bo_uint64<br />
iNumToAcquire);<br />
StopAcquisition();<br />
AbortAcquisition();<br />
Open a DataStream.<br />
Close the DataStream.<br />
Returns a list of already created buffers (BufferList).<br />
Returns the unique string identifier of the DataStream.<br />
Returns the size Payloadsize.<br />
Checks if Datastream can provide Payloadsize.<br />
Returns whether the DataStream is already started or not.<br />
Returns the type of the DataStream.<br />
Starts the acquisition of a specified number of images.<br />
Stops the image acquisition.<br />
Aborts the image acquisition immediately.<br />
16
3.2.5<br />
Buffer<br />
Buffer<br />
Inherits from:<br />
EventControl<br />
This class realizes the data access to the memory. It contains<br />
information about the received data (e.g. image size,<br />
pixel format) too.<br />
The Buffer module encapsulates a single memory buffer.<br />
Its purpose is to act as the target for the image acquisition.<br />
Buffers can be allocated automatically by the producer or<br />
by the user.<br />
Notice<br />
On activated Chunk mode, there is no access to some<br />
features of the buffer object (e.g. GetHeight, GetWidth<br />
or GetPixelFormat). Please use the GetChunkNodeTree<br />
function instead.<br />
Functions of the class Buffer<br />
B<strong>GAPI2</strong>::Buffer:: ...<br />
Buffer();<br />
Buffer( void * pUserObj<br />
);<br />
Buffer( void *pUserBuffer,<br />
bo_uint64<br />
uUserBufferSize,<br />
void *pUserObj);<br />
GetID();<br />
QueueBuffer();<br />
GetMemPtr();<br />
GetMemSize();<br />
GetUserObj();<br />
GetTimestamp();<br />
GetNewData();<br />
GetIsQueued();<br />
Creates a buffer object.<br />
Creates a buffer object including user specific data.<br />
Creates a buffer object with using user allocated memory.<br />
Returns the unique ID of buffer (e.g. Buffer_01f94fb), not<br />
the memory address of the buffer.<br />
Allocates the buffer to the input queue of a DataStream.<br />
Returns the memory address of the buffer.<br />
Returns the memory size of the buffer.<br />
Returns the user specific data of the buffer.<br />
Returns the buffer´s timestamp.<br />
Returns "true" if the buffer is filled until GetFilledBuffer is<br />
performed.<br />
Returns "true" as long as the buffer is allocated to the input<br />
queue of a DataStream.<br />
Returns "true", if buffer being filled.<br />
Returns "true" on defect image data.<br />
GetIsAcquiring();<br />
GetIsIncomplete();<br />
GetTLType(); Returns the type of buffer (GEV, USB3, ...).<br />
GetSizeFilled(); Returns the current fill level of the buffer [Bytes].<br />
GetWidth();<br />
Returns the image width.<br />
GetHeight();<br />
Returns the image height.<br />
GetXOffset(); Returns the offset in x-direction.<br />
GetYOffset(); Returns the offset in y-direction.<br />
GetFrameID(); Returns a hardware generated counter (1...65535).<br />
GetImagePresent(); Returns the availability of the image within the buffer.<br />
GetImageOffset(); Returns the position of the first byte of image data within<br />
the buffer.<br />
GetPayloadType(); Returns whether the payload is chunck or image data .<br />
GetPixelFormat(); Returns the pixel format of the image.<br />
17
GetDeliveredImage-<br />
Height();<br />
GetDelivered-<br />
ChunkPayloadSize();<br />
GetChunkLayoutID();<br />
GetChunkNodeTree();<br />
Returns the number of lines of a transmitted image.<br />
Returns the delivered chunk payload size.<br />
Returns the ID of the layout.<br />
Returns the tree view of all chunk nodes.<br />
3.3<br />
List Classes<br />
This classes aim to the discovery and listing of the main objects.<br />
The list classes are: SystemList, InterfaceList, DeviceList, DataStreamList and Buffer-<br />
List.<br />
In any list class there are three different ways to handle the objects within a list. The first<br />
of them is the iterator, which can be used for interating through the lists using begin<br />
and end functions.<br />
The second approach is the access by using the subscript operator. And the third way of<br />
object handling is realized by the find function.<br />
Each list entry consists of an ID, which is used as key value and a pointer to an object of<br />
the main classes.<br />
This functions are availalble for all List Classes.<br />
B<strong>GAPI2</strong>::[respective List Class]:: ...<br />
iterator<br />
begin();<br />
end();<br />
Refresh(bo_uint64 iTimeout);<br />
size();<br />
operator[](const String& val)<br />
find(const String& _keyval);<br />
erase(iterator& _where);<br />
erase(const String& _keyval);<br />
clear();<br />
This is the iterator class.<br />
Retrieving the iterator that points to the first<br />
list entry.<br />
Retrieving the iterator that points to the last<br />
list entry (+1).<br />
Refresh with timout.<br />
(not available for the BufferList)<br />
Returns the number of found list entries.<br />
This is the subscript operator for the access<br />
to a free selectable point of a list.<br />
Returns the iterator for the desired list entry,<br />
that is defined by the unique ...<br />
Erases a list entry, using the iterator.<br />
Erases a list entry, using the unique string<br />
identifier.<br />
Clears the list.<br />
18
3.3.1<br />
SystemList<br />
SystemList<br />
This class is used to list objects of the System class.<br />
Special feature of the SystemList: This object is a Singleton.<br />
It is not possible to create other objects of this class. It always<br />
accesses to the same object. Therefore, a release function is necessary.<br />
Functions of the class SystemList<br />
B<strong>GAPI2</strong>::SystemList:: ...<br />
GetInstance();<br />
ReleaseInstance();<br />
CreateInstanceFromPath (String<br />
producerpath);<br />
Add(System * pSystem);<br />
Refresh();<br />
Create the instance of the SystemList.<br />
Release the instance of the SystemList.<br />
Forces the usage of only one producer for<br />
the listing.<br />
Adds a producer to the list.<br />
Refreshes the SystemList.<br />
3.3.2<br />
InterfaceList<br />
InterfaceList<br />
This class is used to list objects of the Interface class.<br />
3.3.3<br />
DeviceList<br />
DeviceList<br />
This class is used to list objects of the Device class.<br />
3.3.4<br />
DataStreamList<br />
DataStreamList<br />
This class is used to list objects of the DataStream class.<br />
19
3.3.5<br />
BufferList<br />
BufferList<br />
This class is used to list objects of the Buffer class.<br />
Special feature of the BufferList: With this list class the programmer<br />
can add buffers to the buffer list. Therefore there is no<br />
refresh function.<br />
Functions of the class BufferList<br />
B<strong>GAPI2</strong>::BufferList:: ...<br />
Add(Buffer *pBuffer);<br />
RevokeBuffer(Buffer<br />
*pBuffer);<br />
FlushInputToOutput-<br />
Queue();<br />
FlushAllToInputQueue();<br />
FlushUnqueuedToInput-<br />
Queue();<br />
DiscardOutputBuffers();<br />
DiscardAllBuffers();<br />
GetDeliveredCount();<br />
GetUnderrunCount();<br />
GetAnnouncedCount();<br />
GetQueuedCount();<br />
GetAwaitDeliveryCount();<br />
Adds a new Butter to the BufferList.<br />
Revokes the buffer from the BufferList.<br />
Flushing all buffers form the input queue to the output<br />
queue.<br />
Flushing all available buffers to the input queue.<br />
Flushing all announced buffer to the input queue.<br />
Discarding all buffers from the output queue to announced<br />
status.<br />
Discarding all buffers form any queue to announced<br />
status.<br />
Returns the number of buffers that are retrieved from<br />
the output queue by using GetFilledBuffer.<br />
Returns the number of buffer underruns.<br />
Returns the number of announced buffers.<br />
Returns the number of queued buffer (input queue).<br />
Returns the number of queued buffer (output<br />
queue).<br />
20
Memory<br />
delete & free<br />
create & allocate<br />
Buffer<br />
RevokeBuffer<br />
Add<br />
Announce<br />
DiscardAllBuffers<br />
QueueBuffer/<br />
FlushAllToInputQueue<br />
GetFilledBuffer/<br />
DiscardAllBuffers/<br />
DiscardOutputBuffers<br />
Queued<br />
------------<br />
Inpuf Buffer<br />
Pool<br />
FlushInputToOutputQueue<br />
FlushAllToInputQueue<br />
Pending<br />
------------<br />
Output Buffer<br />
Pool<br />
Start of new Frame<br />
Frame Acquisition complete<br />
Fill<br />
◄ Figure 6<br />
Buffer handling<br />
21
3.4<br />
Additional Classes<br />
Beside the previously mentioned classes, the B<strong>GAPI2</strong> also contains three additional<br />
classes.<br />
The first two of them (Image & ImageProcessor) are used for image handling and manipulation<br />
and are encapsulated in the bgapi2_img.dll. The third class (Trace) aims to<br />
the tracing functionality.<br />
3.4.1<br />
Image<br />
Image<br />
This class provides the ability of image transformation.<br />
Functions of the class Image<br />
B<strong>GAPI2</strong>::Image:: ...<br />
GetWidth();<br />
GetHeight();<br />
GetPixelFormat();<br />
TransformImage( String sPixelFormat,<br />
Image** ppOutputImage );<br />
GetBuffer();<br />
GetTransformBufferLength(String<br />
sPixelFormat);<br />
TransformImageToBuffer( String sPixelFormat,<br />
void* pBuffer, bo_uint64<br />
uBufferSize );<br />
His-<br />
GetHistogram(bo_tHistRecords<br />
togram);<br />
Release();<br />
Returns the buffer of the image.<br />
Returns the required buffer length of<br />
the image, after tranformation to a<br />
specified pixel format.<br />
Performs the image transformation<br />
using user allocated buffer of the previously<br />
determined length (GetTransformBufferLength).<br />
Returns the histogramm array of the<br />
image<br />
Releases the occupied resources (except<br />
the user allocated buffer).<br />
Returns the width of the image.<br />
Returns the height of the image.<br />
Returns the pixel format of the image.<br />
Performs the image transformation.<br />
22
3.4.2<br />
Image Processor<br />
Image Processor<br />
The task of this class is the creation of image objects<br />
Functions of the class Image Processor<br />
B<strong>GAPI2</strong>::ImageProcessor:: ...<br />
GetInstance();<br />
ReleaseInstance();<br />
GetVersion();<br />
CreateImage(bo_uint width, bo_<br />
uint height, String pixelformat,<br />
void* pBuffer, bo_uint64 uBuffer-<br />
Size);<br />
CreateTransformedImage(Image*<br />
pInputImage, const char* szDestinationPixelformat);<br />
SetDestinationFlip( bool vertical,<br />
bool horicontal );<br />
GetDestinationFlip( bool *vertical,<br />
bool *horicontal );<br />
Creates a singleton instance of the<br />
class.<br />
Releases the image processor instance.<br />
Returns the version of the Image processor.<br />
Creates a BGAPI Image object based<br />
on a filled buffer.<br />
Creates an image object and performes<br />
a pixel format transformation.<br />
Flips the image in the specified direction.<br />
Returns the direction of the image flipping.<br />
23
3.4.3<br />
Trace<br />
Trace<br />
B<strong>GAPI2</strong> Trace offers the possibility to monitor the program flow<br />
and detect errors.<br />
Functions of the class Trace<br />
B<strong>GAPI2</strong>::Trace:: ...<br />
Enable( bo_bool benable );<br />
ActivateOutputToFile( bo_bool bactive,<br />
String tracefilename );<br />
ActivateOutputToDebugger( bo_bool<br />
vactive );<br />
ActivateMaskError( bool vactive );<br />
ActivateMaskWarning( bo_bool bactive<br />
);<br />
ActivateMaskInformation( bo_bool<br />
bactive );<br />
ActivateOutputOptionTimestamp( bo_<br />
bool bactive );<br />
ActivateOutputOptionTimestampDiff(<br />
bo_bool bactive);<br />
ActivateOutputOptionPrefix( bo_bool<br />
bactive );<br />
Enables or disables of the tracing.<br />
Provides the possibility to print trace<br />
outputs to the specified file.<br />
Provides the possibility to print trace<br />
outputs to the debugger.<br />
Activates error tracing<br />
Activates warning tracing.<br />
Activates information tracing.<br />
Includes the timestamp to the trace<br />
output.<br />
Includes the time lag from the last to<br />
the current trace output.<br />
Includes the module, that created the<br />
trace output (such as producer, consumer<br />
...)<br />
24
3.5<br />
IException<br />
IException<br />
This class is responable for the exception handling and represents<br />
the parent class of all exception classes.<br />
Functions of the IException<br />
B<strong>GAPI2</strong>::IException:: ...<br />
GetErrorDescription();<br />
GetFunctionName();<br />
GetType();<br />
Exception Class<br />
NotInitializedException<br />
NotImplementedException<br />
ResourceInUseException<br />
AccessDeniedException<br />
InvalidHandleException<br />
InvalidIdException<br />
NoDataException<br />
Returns a description of the error.<br />
Returns the function name, where the error occured.<br />
Returns the type of the error.<br />
InvalidParameterException<br />
IOException<br />
AbortException<br />
InvalidBufferException<br />
NotAvailableException<br />
SysVarMissingException<br />
ErrorException<br />
Description<br />
The requested object is not initialized.<br />
The requested function/feature is not implemented.<br />
The requested object is already used.<br />
Requested operation is not allowed.<br />
Given handle does not support the operation.<br />
ID could not be connected to a resource.<br />
The function has no data to work on.<br />
One of the parameter given was not valid or out of<br />
range and none of the error codes above fits.<br />
Communication error has occurred.<br />
An operation has been aborted before it could be<br />
completed.<br />
No Buffer announced or one or more buffers with<br />
invalid buffer size.<br />
Resource or information is not available at a given<br />
time in a current state.<br />
System variable is not available or specified (see<br />
section 4.1).<br />
General purpose exception<br />
25
4. Programming Basics in <strong>Baumer</strong>-<strong>GAPI2</strong><br />
During the installation process, all required files were copied to your system.<br />
Default path Windows ® 32 bit / 64 bit:<br />
C:\Program Files\<strong>Baumer</strong>\<strong>Baumer</strong> GAPI <strong>SDK</strong><br />
In the following, these folders are refered to as <br />
Notice<br />
Location of the Runtime Modules<br />
All <strong>Baumer</strong>-<strong>GAPI2</strong> DLL's must be provided within the same directory as the calling<br />
application. This accounts for the fact, that the B<strong>GAPI2</strong>_genicam.dll tries to find its<br />
modules within the directory in which it finds itself.<br />
Further searches the B<strong>GAPI2</strong>_genicam.dll in the GENTL PATH for producers.<br />
Please take care to refer to the correct directory (Win32 = 32bit / x64 = 64 bit).<br />
This mainly should be considered for the employment of Microsoft ® Visual Studio –<br />
here the working directory needs to be suitable adjusted.<br />
26
4.1<br />
Setting System variables<br />
Microsoft ® Windows ® 7<br />
Notice<br />
The path to the system variable is set already during the installation process of the <strong>SDK</strong>.<br />
Follow the instructions to change the path to the system variables (bgapi2_xxx.cti).<br />
1. Click Start, then choose Computer.<br />
2. Click Properties.<br />
3. Select the tab Advanced.<br />
4. Click Environment Variables.<br />
5. Control whether in the System<br />
variables the entry GENICAM_GEN-<br />
TL32_PATH exists.<br />
If the entry does not exist continue<br />
with step 6.<br />
If the entry exists continue with<br />
step 8.<br />
6. Click New at System variables.<br />
7. Adjust the following.<br />
Variable name:<br />
GENICAM_GENTL32_PATH<br />
Variables value:<br />
32-bit systems<br />
\Components\Bin\Win32<br />
64-bit systems<br />
\Components\Bin\x64<br />
Continue with step 9.<br />
8. Select the Variable GENICAM_<br />
GENTL32_PATH and click Edit.<br />
Add the <strong>Baumer</strong> path to the Variable<br />
value. Separate it with a semicolon<br />
to existing entries.<br />
Variables value:<br />
32-bit systems<br />
\Components\Bin\Win32<br />
64-bit systems<br />
\Components\Bin\x64<br />
27
4.2 Implementation<br />
Depending on the programming language you have chosen, you will need to include<br />
different header files and libraries. See the respective precaution of your employed programming<br />
language.<br />
4.2.1<br />
Implementation C++<br />
Header files:<br />
Files required for the<br />
compiler and containing<br />
forwarded declarations for<br />
subroutines, variables and<br />
other identifiers.<br />
4.2.1.1 Header Files<br />
\Components\Dev\C++\Inc<br />
bgapi2_genicam.hpp<br />
bgapi2_def.h<br />
bgapi2_featurenames.h<br />
Interface definition for <strong>Baumer</strong>-<strong>GAPI2</strong>, including classes,<br />
functions and function pointer for callbacks.<br />
Definitions for <strong>Baumer</strong>-<strong>GAPI2</strong>, including defines, enumerations<br />
and typedefs.<br />
Summary of the features from the GenICam Standard Features<br />
Naming Convention.<br />
To include the necessary header file for C++ write the following code:<br />
#include "bgapi2_genicam.hpp"<br />
4.2.1.2 Libraries<br />
Library:<br />
Collection of recurrent<br />
routines.<br />
Notice<br />
The files required for 32 bit and 64 bit operating systems are totally different. Please<br />
include the correct folder. Including the wrong files may lead to problems!<br />
Default path Windows ® 32bit:<br />
\Components\Dev\C++\Lib\Win32<br />
Default path Windows ® 64bit:<br />
\Components\Dev\C++\Lib\x64<br />
bgapi2_genicam.lib<br />
This is where all function names and their implementations<br />
are filed.<br />
28
4.2.1.3<br />
Precaution<br />
Create a new project by generating a *.cpp file, then open the project properties from the<br />
context menu. Some required information such as the header files directory will need to<br />
be set here.<br />
Please set the following values in “ Properties”:<br />
▪▪<br />
“ C++” → “General”: “Additional Include Directories”:<br />
\Dev\C++\Inc<br />
▪▪<br />
“Linker” → “General”: “ Additional Library Directories”:<br />
\Dev\C++\Lib\Win32<br />
▪▪ “Linker” → “Input”: “Additional Dependencies”:<br />
bgapi2_genicam.lib<br />
▪▪ “Build Events” → “Post-Build-Event”: “Command Line”:<br />
absolute path:<br />
copy "\Components\Bin\Win32"\*.* .\<br />
or the relative path (which is used in the examples):<br />
copy ..\..\..\..\..\Bin\Win32\*.* .\<br />
Notice<br />
32-Bit:<br />
\Components\Bin\Win32<br />
bgapi2_genicam.dll<br />
bgapi2_img.dll<br />
BO_GigEFilterDrv.dll<br />
MathParser.dll<br />
64-Bit<br />
\Components\Bin\x64<br />
bgapi2_genicam.dll<br />
bgapi2_img.dll<br />
BO_GigEFilterDrv.dll<br />
MathParser.dll<br />
4.2.1.4 Using Namespace<br />
In order to employ the B<strong>GAPI2</strong> namespace for C++ as default, please enter the following<br />
code:<br />
using namespace B<strong>GAPI2</strong>;<br />
29
4.2.2 Implementation in C#<br />
4.2.2.1<br />
.NET Component<br />
Create a new project, open its properties via<br />
the context menu and select:<br />
"Add Reference...".<br />
Integrate the respective bgapi2_genicam_<br />
dotnet.dll.<br />
Now you can see under References the integrated<br />
bgapi2_genicam_dotnet.dll.<br />
Build Events (C#<br />
The reason for the<br />
command is that<br />
compiled .exe mu<br />
contain all require<br />
bgapi2.dll files in<br />
same directory.<br />
Notice<br />
32-Bit:<br />
\Components\Dev\C_Sharp\Win32<br />
bgapi2_genicam_dotnet.dll<br />
64-Bit<br />
\Components\Dev\C_Sharp\x64<br />
bgapi2_genicam_dotnet.dll<br />
Then go to the added bgapi2_genicam_dotnet.dll<br />
Properties and set "Copy Local" to<br />
"True".<br />
30
4.2.2.2<br />
Precaution<br />
The first method is applied with the provided examples.<br />
Please set the following values under<br />
“ Properties”:<br />
▪▪ “Build Events” → “Post-Build-Event”: “Command Line”:<br />
absolute path:<br />
copy "\Components\Bin\Win32"\*.* .\<br />
or relative path:<br />
relative path: copy "..\..\..\..\..\..\..\Bin\Win32"\*.* .\<br />
Alternatively you can use this method:<br />
Open the properties via the context menu<br />
and select:<br />
):<br />
copy<br />
he<br />
st<br />
d<br />
the<br />
"Add → Existing Item...".<br />
Add the respective DLL files.<br />
31
Notice<br />
32-Bit:<br />
\Components\Bin\Win32<br />
bgapi2_genicam.dll<br />
bgapi2_img.dll<br />
BO_GigEFilterDrv.dll<br />
MathParser.dll<br />
64-Bit<br />
\Components\Bin\x64<br />
bgapi2_genicam.dll<br />
bgapi2_img.dll<br />
BO_GigEFilterDrv.dll<br />
MathParser.dll<br />
At each of the included files you must set "Copy<br />
to Output Directory" to "Copy always".<br />
4.2.2.3 Using Namespace<br />
In order to employ the B<strong>GAPI2</strong> namespace for C# as a default, please enter the following<br />
code:<br />
using B<strong>GAPI2</strong>;<br />
or put B<strong>GAPI2</strong> to all calls at the head, e.g.:<br />
B<strong>GAPI2</strong>.Interface<br />
B<strong>GAPI2</strong>.Device<br />
B<strong>GAPI2</strong>.Image<br />
B<strong>GAPI2</strong>.Exception<br />
32
5. Application development with <strong>Baumer</strong>-GAPI<br />
Notice<br />
In order to ensure a smooth flow of your application, it is not recommended to perform<br />
function calls during the image acquisition on high system load. If parallel processing<br />
is necessary, <strong>Baumer</strong> suggests the processing of these function calls in a separate<br />
thread.<br />
5.1 First steps<br />
In this chapter, we will guide you on your way to the first image.<br />
This tutorial relates to working with one interface and one camera in C++ and C#.<br />
Instances<br />
<strong>Baumer</strong>-<strong>GAPI2</strong><br />
entry point<br />
Programmer<br />
DataStream<br />
Device<br />
Interface<br />
System<br />
SystemList<br />
◄ Figure 7<br />
Steps to the first image<br />
33
5.1.1<br />
Preparation<br />
5.1.1.1<br />
Includes<br />
First, please create a new project and set the “Configuration Properties”.<br />
Header files C++<br />
Header file of the default<br />
input/output library: This<br />
library includes macro<br />
definitions, constants,<br />
declarations of functions<br />
and types.<br />
For more information look<br />
into the documentation for<br />
standard library.<br />
C++ C#<br />
and include the necessary header file<br />
#include "bgapi2_genicam.hpp"<br />
using namespace B<strong>GAPI2</strong>;<br />
The standard library and the standard input/output<br />
header also need to be included:<br />
#include <br />
using System;<br />
#include <br />
using System.Collections.Generic;<br />
#include <br />
using System.Linq;<br />
using System.Text;<br />
using B<strong>GAPI2</strong>;<br />
5.1.1.2<br />
Declaration of Variables<br />
We also need to declare several variables and pointers for the main function:<br />
C++ C#<br />
int main()<br />
{<br />
static void Main(string[] args)<br />
{<br />
Variable for SystemList and System<br />
B<strong>GAPI2</strong>::SystemList * systemList = NULL;<br />
B<strong>GAPI2</strong>.SystemList systemList = null;<br />
B<strong>GAPI2</strong>::System * pSystem = NULL;<br />
B<strong>GAPI2</strong>.System mSystem = null;<br />
B<strong>GAPI2</strong>::String sSystemID; string sSystemID = "";<br />
Variables for InterfaceList and Interface:<br />
B<strong>GAPI2</strong>::InterfaceList * interfaceList =<br />
NULL;<br />
B<strong>GAPI2</strong>.InterfaceList interfaceList = null;<br />
B<strong>GAPI2</strong>::Interface * pInterface = NULL;<br />
B<strong>GAPI2</strong>.Interface mInterface = null;<br />
B<strong>GAPI2</strong>::String sInterfaceID; string sInterfaceID = "";<br />
Variable for DeviceList and Device<br />
B<strong>GAPI2</strong>::DeviceList * deviceList = NULL;<br />
B<strong>GAPI2</strong>.DeviceList deviceList = null;<br />
B<strong>GAPI2</strong>::Device * pDevice = NULL;<br />
B<strong>GAPI2</strong>.Device mDevice = null;<br />
B<strong>GAPI2</strong>::String sDeviceID; string sDeviceID = "";<br />
Variables for DataStreamList and DataStream<br />
B<strong>GAPI2</strong>::DataStreamList * datastreamList =<br />
NULL;<br />
DataStreamList datastreamList = null;<br />
B<strong>GAPI2</strong>::DataStream * pDataStream = NULL;<br />
B<strong>GAPI2</strong>.DataStream mDataStream = null;<br />
B<strong>GAPI2</strong>::String sDataStreamID; string sDataStreamID = "";<br />
Variables for BufferList and Buffer<br />
B<strong>GAPI2</strong>::BufferList * bufferList = NULL;<br />
BufferList bufferList = null;<br />
B<strong>GAPI2</strong>::Buffer * pBuffer = NULL;<br />
B<strong>GAPI2</strong>.Buffer mBuffer = null;<br />
34
5.1.2<br />
SystemList<br />
C++ C#<br />
instantiating and updating SystemList<br />
try<br />
try<br />
{ {<br />
systemList = SystemList::GetInstance();<br />
systemList = SystemList.Instance;<br />
systemList->Refresh();<br />
systemList.Refresh();<br />
std::cout
5.1.4<br />
Get the InterfaceList and fill it<br />
Get the the InterfaceList of the selected System and update that list. For this example we<br />
used a timeout of 100 ms.<br />
C++ C#<br />
interfaceList = pSystem->GetInterfaces(); interfaceList = mSystem.Interfaces;<br />
interfaceList->Refresh(100);<br />
interfaceList.Refresh(100);<br />
std::cout end(); ifc++)<br />
foreach (KeyValuePair<br />
ifc_pair in interfaceList)<br />
{ {<br />
ifc->second->Open(); ifc_pair.Value.Open();<br />
sInterfaceID = ifc->first; sInterfaceID = ifc_pair.Key;<br />
break; break;<br />
} }<br />
Check whether the InterfaceID is filled and assign the interface pointer:<br />
if (sInterfaceID == "") if (sInterfaceID == "")<br />
return 0; // no interface found return; // no interface found<br />
else<br />
else<br />
pInterface = (*interfaceList)[sInter<br />
faceID];<br />
mInterface =<br />
interfaceList[sInterfaceID];<br />
5.1.6<br />
Get the DeviceList and fill it<br />
Get the the DeviceList of the selected Interface and update that list. Using a timeout of<br />
100 ms.<br />
C++ C#<br />
deviceList = pInterface->GetDevices();<br />
deviceList = mInterface.Devices;<br />
deviceList->Refresh(100);<br />
deviceList.Refresh(100);<br />
std::cout
5.1.7<br />
Open a Device<br />
Now you search for the device in the list (here open the first device in the list):<br />
C++ C#<br />
for (DeviceList::iterator dev = deviceList->begin();<br />
dev != deviceList-<br />
>end(); dev++)<br />
foreach (KeyValuePair<br />
dev_pair in deviceList)<br />
{ {<br />
dev->second->Open(); dev_pair:Value.Open();<br />
sDeviceID = dev->first; sDeviceID = dev_pair.Key;<br />
break; break;<br />
} }<br />
Check the DeviceID is filled and assign the device pointer:<br />
if (sDeviceID == "") if (sDeviceID == "")<br />
return 0; // no device found return; // no device found<br />
else<br />
else<br />
pDevice = (*deviceList)[sDeviceID]; mDevice = deviceList[sDeviceID];<br />
5.1.8<br />
Get DataStreamList and fill it<br />
Get the the DataStreamList of the selected Device and update that list. Using a timeout<br />
of 100 ms.<br />
C++ C#<br />
datastreamList = pDevice-<br />
datastreamList = mDevice.DataStreams;<br />
>GetDataStreams();<br />
datastreamList->Refresh(100);<br />
datastreamList.Refresh(100);<br />
std::cout
5.1.9<br />
Open a DataStream<br />
Now you search for the data stream in the list (here open the first datastream in the list):<br />
C++ C#<br />
for(DataStreamList::iterator dst=<br />
datastreamList->begin();dst != datastream-<br />
List->end();dst++)<br />
foreach (KeyValuePair dst_pair in datastreamList)<br />
{ {<br />
dst->second->Open(); dst_pair.Value.Open();<br />
sDataStreamID = dst->first; sDataStreamID = dst_pair.Key;<br />
break; break;<br />
} }<br />
Check the DataStreamID is filled and assign the data stream pointer:<br />
if (sDataStreamID == "") if (sDataStreamID == "")<br />
return 0; // no datastream found return; // no datastream found<br />
else<br />
else<br />
pDataStream = (*datastreamList)<br />
[sDataStreamID];<br />
Now the datastream is opened.<br />
mDataStream =<br />
datastreamList[sDataStreamID];<br />
5.1.10<br />
Create the BufferList and allocate Buffer memory<br />
The created BufferList is empty and needs to be filled with buffers.<br />
C++ C#<br />
bufferList = pDataStream->GetBufferList(); bufferList = mDataStream.BufferList;<br />
for(int i=0; i
5.1.11<br />
Allocate Image Buffer to the DataStream<br />
C++ C#<br />
for (BufferList::iterator buf = bufferList->begin();<br />
buf != bufferList->end();<br />
buf++)<br />
foreach (KeyValuePair<br />
buf_pair in bufferList)<br />
{ {<br />
buf->second->QueueBuffer(); buf_pair.Value.QueueBuffer();<br />
} }<br />
std::cout
5.1.12<br />
Start Camera and fill the Image Buffer<br />
Start the data stream.<br />
40<br />
C++ C#<br />
pDataStream->StartAcquisitionContinuous(); mDataStream.StartAcquisition();<br />
pDevice->GetRemoteNode("AcquisitionStart")-<br />
>Execute();<br />
Start of the camera:<br />
mDevice.RemoteNodeList["AcquisitionStart"]<br />
.Execute();<br />
Fill the image buffer using a timeout of 1000 milliseconds. The memory pointer to the<br />
image data is displayed.<br />
B<strong>GAPI2</strong>::Buffer * pBufferFilled = NULL;<br />
B<strong>GAPI2</strong>.Buffer mBufferFilled = null;<br />
try<br />
try<br />
{ {<br />
pBufferFilled = pDataStream-<br />
>GetFilledBuffer(1000);<br />
mBufferFilled = mDataStream.Get<br />
FilledBuffer(1000);<br />
if(pBufferFilled == NULL) if(mBufferFilled == null)<br />
{ {<br />
std::cout
ufferList->DiscardAllBuffers();<br />
bufferList.DiscardAllBuffers();<br />
while( bufferList->size() > 0) while (bufferList.Count > 0)<br />
{ {<br />
pBuffer = bufferList->begin()-<br />
>second;<br />
mBuffer = bufferList.Values.First();<br />
bufferList->RevokeBuffer(pBuffer); bufferList.RevokeBuffer(mBuffer);<br />
delete pBuffer; }<br />
5.1.13<br />
Releasing the resources<br />
C++ C#<br />
pDataStream->Close();<br />
mDataStream.Close();<br />
pDevice->Close();<br />
mDevice.Close();<br />
pInterface->Close();<br />
mInterface.Close();<br />
pSystem->Close();<br />
mSystem.Close();<br />
B<strong>GAPI2</strong>::SystemList::ReleaseInstance();<br />
int endKey = 0;<br />
To prevent the application from closing use the following code:<br />
std::cout > endKey;<br />
return 0;<br />
} // end of main<br />
System.Console.Write("Input any number to<br />
close the program:\n");<br />
Console.Read();<br />
return;<br />
} //end of Main<br />
41
<strong>Baumer</strong> Optronic GmbH<br />
Badstrasse 30<br />
DE-01454 Radeberg, Germany<br />
Phone +49 (0)3528 4386 0 · Fax +49 (0)3528 4386 86<br />
sales@baumeroptronic.com · www.baumer.com<br />
Technical data has been fully checked, but accuracy of printed matter not guaranteed.<br />
Subject to change without notice. Printed in Germany 01/13. v1.0 11099008