Using ActiveGige API at runtime
Top  Previous  Next

Most applications would use ActiveGige by embedding one or several ActiveX objects into an application form at design time, as described in the previous topics. Sometimes however you may want to use ActiveGige SDK dynamically at runtime. This can be useful if you want a user of your application to decide if he wants to use GigE Vision cameras or if you are creating a dynamic link library that has no GUI. ActiveGige easily allows you to do it via its COM programming interface.

C/C++

1. Copy ActiveGige_i.c and ActiveGige.h files into your project folder and include them into your project.

2. Add the following defines to a module which will be using ActiveGige functions:

#include <comdef.h>  
#include <atlbase.h>  
#include <atlconv.h>  
#include "ActiveGige.h"  

3. Initialize COM library and instantiate an ActiveGige object:
 
IActiveGige *pActiveGige;  
HRESULT hr = CoInitialize(0);  
if (hr==S_OK)  
{  
hr = CoCreateInstance(CLSID_ActiveGige, NULL, CLSCTX_INPROC_SERVER, IID_IActiveGige, (void**) &pActiveGige);  
}  
 
4. Start using ActiveGige properties and methods, for example:

hr = pActiveGige->put_Camera(0); // selecting camera #0  
hr = pActiveGige->Grab(); // grabbing a frame  
hr = pActiveGige->SaveImage( OLESTR("frame1.jpg") ); //saving a frame as jpg file  

Refer to GcamConsole and GcamWin sample applications for more details.


VB6

1. Add the ActiveGige component to the Toolbox as described in Getting started in VB.

2. Declare a global ActiveGige-type object variable in the beginning of your code:

Dim WithEvents AG As ActiveGige  

3. Instantiate an ActiveGige object and assign it to the variable:

Set AG = New ActiveGige  
 
4. Start using ActiveGige properties and methods, for example:

CameraList=AG.GetCameraList    'retreiving the list of names of connected cameras  
AG.Camera=0         'selecting camera #0     
AG.SetFeature "GainRaw", 150   'setting Gain value  
AG.Acquire=True         'initiating the acquisition  

5. To add an ActiveGige event handler to your code, select the AG variable from the Object combo box on top of your code window and then select a desired event from the Procedure box on the right, for example FrameAcquired. The following fragment will be added to your code:

Private Sub AG_FrameAcquired()  
End Sub  

Refer to GcamByRef sample application for more details.

6. When you are done with using the ActiveGige object, destroy it with the following command:

Set AG = Nothing  

 
VB.NET

1. 1. Right click on your application in the Solution Explorer, select Add Reference...->COM, then select ActiveGige Control from the list.

2. Declare a global ActiveGige-type object variable in the beginning of your code:

Dim WithEvents AG As ACTIVEGIGELib.ActiveGige  

3. Instantiate an ActiveGige object and assign it to the variable:

AG = New ACTIVEGIGELib.ActiveGige  
 
4. Start using ActiveGige properties and methods, for example:

Dim CamLst As Object  
Dim i As Integer  
CamLst = AG.GetCameraList      'retrieving camera list  
CamNumber = UBound(CamLst)   'number of connected cameras found

For
i = 0 To
CamNumber      'filling out combo box with the names of cameras

ComboBox1.Items.Add(CamLst(i))
Next
......  
AG.Camera = 0     
AG.Acquire = True  
 
5. To add an ActiveGige event handler to your code, select the AG variable from the Class Name box on top of your code window and then select a desired event from the Method Name box on the right, for example FrameAcquired. The following fragment will be added to your code:

Private Sub AG_FrameAcquired() Handles AG.FrameAcquired  
End Sub  
 
6. When you are done using the ActiveGige object, destroy it with the following command:

AG = Nothing  
 
 
C#

1. Right click on your application in the Solution Explorer, select Add Reference.../COM, then select ActiveGige Control from the list.

2. Declare a global ActiveGige-type object variable:

ACTIVEGIGELib.ActiveGige AG;  

3. Instantiate an ActiveGige object and assign it to the variable:

AG = new ACTIVEGIGELib.ActiveGige();  
 
4. Start using ActiveGige properties and methods, for example:

AG.Camera = 0  
AG.Acquire=true;      'starting automatic acquisition  
AG.ShowProperties (true, 0);   'displaying buit-in property pages