Using ActiveUSB API at runtime
Top  Previous  Next

Most applications would use ActiveUSB 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 ActiveUSB SDK dynamically at runtime. This can be useful if you want a user of your application to decide if he wants to use USB3 Vision cameras or if you are creating a dynamic link library that has no GUI. ActiveUSB easily allows you to do it via its COM programming interface.

C/C++

1. Copy ActiveUSB_i.c and ActiveUSB.h files into your project folder and include them into your project.

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

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

3. Initialize COM library and instantiate an ActiveUSB object:
 
IActiveUSB *pActiveUSB;  
HRESULT hr = CoInitialize(0);  
if (hr==S_OK)  
{  
hr = CoCreateInstance(CLSID_ActiveUSB, NULL, CLSCTX_INPROC_SERVER, IID_IActiveUSB, (void**) &pActiveUSB);  
}  
 
4. Start using ActiveUSB properties and methods, for example:

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

Refer to UcamConsole and UcamWin sample applications for more details.


VB6

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

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

Dim WithEvents AU As ActiveUSB  

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

Set AU = New ActiveUSB  
 
4. Start using ActiveUSB properties and methods, for example:

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

5. To add an ActiveUSB event handler to your code, select the AU 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 AU_FrameAcquired()  
End Sub  

Refer to UcamByRef sample application for more details.

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

Set AU = Nothing  

 
VB.NET

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

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

Dim WithEvents AU As ActiveUSBLib.ActiveUSB  

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

AU = New ActiveUSBLib.ActiveUSB  
 
4. Start using ActiveUSB properties and methods, for example:

Dim CamLst As Object  
Dim i As Integer  
CamLst = AU.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
......  
AU.Camera = 0     
AU.Acquire = True  
 
5. To add an ActiveUSB event handler to your code, select the AU 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 AU_FrameAcquired() Handles AU.FrameAcquired  
End Sub  
 
6. When you are done using the ActiveUSB object, destroy it with the following command:

AU = Nothing  
 
 
C#

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

2. Declare a global ActiveUSB-type object variable:

ActiveUSBLib.ActiveUSB AU;  

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

AU = new ActiveUSBLib.ActiveUSB();  
 
4. Start using ActiveUSB properties and methods, for example:

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