Getting started in C++
Top  Previous  Next

This chapter describes how to create a simple GigE Vision server application (virtual camera) with GigESim SDK in Visual C++ for both 32- and 64-bit platforms.

Creating the Project

In the Visual Studio development environment select New -> Project. The New Project Dialog box will appear. Select Visual C++ projects on the left and MFC Application on the right. In the Name filed below type the name of your application, for instance GigeCam and click OK . When MFC Application Wizard appears, click Application Type , select Dialog based radio button and click Finish . The project will be created, and the program dialog GigeCam will be displayed for editing.

Adding the CGevCam class

In the Solution Explorer right-click on your project (GigeCam) and select Add -> Existing Item.. Find GigeSimSDK.h file supplied with GigESim and copy it to your project folder. Depending on the platform of your application (32- or 64-bit), add a reference to either gigesimsdk.lib or gigesimsdk64.lib to your project.

Add the following line to the beginning of CGigeCamDlg.cpp:

#include "GigeSimSDK.h"

Add the following member variable to CGigeCamDlg.h:

CGevCamera* m_pCamera;

You are now ready to create and initialize a virtual camera object.

Initializing the camera object

Add the following lines to CGigeCamDlg::OnInitDialog

m_pCamera = createCamera(); //create camera object  
m_pCamera->SetImageSize(1024,768); //define the image size  
m_pCamera->AddPixelFormat("Mono8"); //define supported pixel formats  
m_pCamera->SetPixelFormat("Mono8"); //select the current pixel format  

You should also add the following line to the dialog's destructor:

   delete m_pCamera;  

It is now time to prepare a function that will generate simulated images and transmit them to the network.

Creating the image transmission thread

Add the following method to the dialog class:

void CGigeCamDlg::videoGenerator()   
int width;  
int height;  
int i=0;  
char buffer[2048*2048];  
char *ptr;  
//the cycle below fills the image buffer with a moving pattern  
//and transmits it over the network  
while (!m_exitThread)   
m_pCamera->LockFormat();    //this is needed to synchronize our cycle with the client  
for (ptr=buffer; ptr < buffer+width*heigh; ptr++)  
We will also have to add the following function that will call the video transmission method in a separate thread:

ULONG videoTransmitThread(CGigeCamDlg* pDlg) 
Connecting the camera to the network and starting the transmission thread

Add the "Connect" button to your dialog. Insert the following code into the button handler:

//bind the camera with the GigE card

(ret == 0)
      m_exitThread = false
      //start the video transmission thread

      m_thread = CreateThread(NULL, 80000000, (LPTHREAD_START_ROUTINE)videoTransmitThread, this
, 0, NULL);
Upon the button click the virtual camera (GigE Vision server) will get activated and become available to GigE Vision client applications operating on the same network. Once a client application issues the AcquisitionStart command, the virtual camera will enter the image streaming cycle and will keep transmitting images to the client until the latter issues the AcquisitionStop command.

Before running your application, make sure to place gigesimsdk.dll or/and gigesimsdk64.dll in the folder where your executable is located.

For more details refer to the sample project provided with GigESim.