Jump to content

GigE Camera Callback Function


Recommended Posts

Hello experts,

I am trying to operate an SVS GigE camera using the SVGigE.x64.dll and the Call Library Function. So far everything seems to work.  

 

But how do you use the callback function to wait for the event each time an image is captured and then read out the image?

 

SVGigE_RETURN __stdcall ImageCallback(Image_handle Image, void* Context)
{
    unsigned char *buffer = Image_getDataPointer(Image);
    printf(“Callback: %08x\n”, buffer);
    return SVGigE_SUCCESS;

 

 

SVGigE_RETURN __stdcall eventCallback(Event_handle EventId, void* Context)
{
    int MessageID;
    SVGigE_SIGNAL_TYPE MessageType;
    Stream_getMessage((StreamingChannel_handle)Context, EventId, &MessageID, &MessageType);
    if (MessageType == SVGigE_SIGNAL_START_OF_TRANSFER)
    printf(“Event: SVGigE SIGNAL START OF TRANSFER\n”);
    return SVGigE_SUCCESS;
}

 

via the function call:

result = StreamingChannel_create (&StreamingChannel, CameraClient, Camera, BufferCount, &ImageCallback, 0);


can be integrated. Here I would have to pass the function pointer.... if I have understood it correctly. But how do I create this in LabView?

 

 

In the Call Library Function there is an extra item Callbacks. Perhaps it can be realized with it. Unfortunately I can't find a good explanation.

grafik.png.89af50a1e5e03438b6b1f952fee8511e.png

 

I would be very happy about your help. Have a good time.

 

Jim

 

 

Example from the camera manufacturer:

 

#include <windows.h>

#include "stdafx.h"

#include "stdlib.h"

#include "SVGigE.h"

#include "conio.h"

#include <string>

 

 // stream callback function will be registered when creating streaming channel

//--------------------------------------------------------------------------------------------

SVGigE_RETURN __stdcall ImageCallback(Image_handle Image, void* Context)

{

    unsigned char *buffer = Image_getDataPointer(Image);

    printf("Callback:  %08x\n", buffer);

    return SVGigE_SUCCESS;

}

 //event callback function to be registered for demonstrating a messaging channel's capabilities

//--------------------------------------------------------------------------------------------

SVGigE_RETURN __stdcall eventCallback(Event_handle EventId, void* Context)

{

    int MessageID;

    SVGigE_SIGNAL_TYPE MessageType;

    Stream_getMessage((StreamingChannel_handle)Context, EventId, &MessageID, &MessageType);

    if (MessageType == SVGigE_SIGNAL_START_OF_TRANSFER)

    printf("Event: SVGigE SIGNAL START OF TRANSFER\n");

    return SVGigE_SUCCESS;

}

 

// --------------------------------------------------------------------------------

int _tmain(int argc, _TCHAR* argv[])

{

    printf("SVGigE-SDK Mini Sample\n"); printf("\n");

    //---------------------------------------------------------------------

    // Discovery

    //---------------------------------------------------------------------

    CameraContainerClient_handle CameraClient;

    int Index = 0;

    Camera_handle Camera;

    CameraClient = CameraContainer_create(SVGigETL_TypeWinsock);

    CameraContainer_discovery(CameraClient);

    int NumCameras = CameraContainer_getNumberOfCameras(CameraClient);

    if(NumCameras < 1 )

    {

    printf("no cameras found !!\n"); printf("Press any key to end..");

    _getch();      

    return 0;

    }

    printf("Nbr of Cameras found:  %-10d \n", NumCameras);

    // select the first discovered camera

    Camera = CameraContainer_getCamera(CameraClient, Index);

    std::string modelname = Camera_getModelName(Camera);

    printf ("Selected Camera: %s \n",modelname.c_str());

 

    int SizeX, SizeY, ImageSize, PacketSize;

    SVGigE_RETURN result;

    result = Camera_openConnection(Camera, 3.0);

 

    if(result != SVGigE_SUCCESS)

    {  

        printf("Open connection failed,  is camera occupied ? is subnet mask OK ? \n"); printf("Press any key to end..");

        _getch();      

        return -1;

    }

    Camera_getSizeX(Camera, &SizeX);

    Camera_getSizeY(Camera, &SizeY);

    Camera_getImageSize(Camera, &ImageSize);

 

    // Adjust camera to maximal possible packet size

    Camera_evaluateMaximalPacketSize(Camera, &PacketSize);

    printf("Sizex %d, Sizey %d\n", SizeX, SizeY);

    printf("PacketSize %d\n", PacketSize);

 

    //-----------------------------------------------------------------------

 

    int BufferCount = 3;

    StreamingChannel_handle StreamingChannel;

    result = StreamingChannel_create (&StreamingChannel, CameraClient, Camera, BufferCount, &ImageCallback, 0);  

 

    //---------------------------------------------------------------------

    // Create an event for demonstrating a messaging channel's capabilities

    //---------------------------------------------------------------------

   

    Event_handle EventID;

    #define SIZE_FIFO 100

    if( SVGigE_SUCCESS != Stream_createEvent(StreamingChannel,&EventID,SIZE_FIFO) )    

     

    {

        printf("Error creating Event\n");

    }

    // Enable the 'Start-of-Transfer' in the messaging channel

    if( SVGigE_SUCCESS != Stream_addMessageType(StreamingChannel,EventID,SVGigE_SIGNAL_START_OF_TRANSFER) )

    {

        printf("adding event failed \n");

        Stream_closeEvent(StreamingChannel,EventID);

    }

    // Register a message callback for demonstrating a messaging channel's capabilities

    if(SVGigE_SUCCESS != Stream_registerEventCallback(StreamingChannel,EventID, &eventCallback, StreamingChannel) )

    {

        Stream_closeEvent(StreamingChannel,EventID);

        printf("registering event failed\n");

    }

 

    //---------------------------------------------------------------------

    // do some camera configurations

    //---------------------------------------------------------------------

   

    //------------------------------------------------------------------------

    Camera_setAcquisitionMode(Camera, ACQUISITION_MODE_SOFTWARE_TRIGGER);

    float  exposure = 50000; // 50 ms

    Camera_setExposureTime(Camera, exposure);

    float Gain = 3 ; // 3 db

    Camera_setGain(Camera, Gain);

    /* if the  settings (binning mode, AOI, pixel depth, Flipping mode) have been changed

    after creating Streaming channel, a reopen of streaming channel is required: */

   

    //---------------------------------------------------------------------

    // start Acquisition: Software Trigger

    //---------------------------------------------------------------------

 

    Camera_setAcquisitionControl(Camera, ACQUISITION_CONTROL_START);

 

    printf("\n"); printf("------------Start Acquisition-----\n"); printf("\n");

    for(int i = 0; i < 10; i++)

    {

        printf("----------------------------------\n");

        Camera_softwareTrigger(Camera);

        printf("Trigger %-10d \n", i);

        Sleep(1000);

    }

    Sleep(1000);

 

    printf("\n"); printf("----------End of Transfer---------\n");   printf("\n");  

    Sleep(1000);

 

    //---------------------------------------------------------------------

    // close Camera and and unregister messages

    //---------------------------------------------------------------------

    printf("Stop Acquisition...\n");

    Camera_setAcquisitionControl(Camera, ACQUISITION_CONTROL_STOP);

    Sleep(1000);

    printf("Unregister messages...\n");

    Stream_unregisterEventCallback(StreamingChannel, EventID, &eventCallback);

    Sleep(1000);

    printf("Delete streaming channel...\n");

    StreamingChannel_delete(StreamingChannel);

    Sleep(1000);

    printf("Close connection...\n");

    Camera_closeConnection(Camera);

    Sleep(1000);

    printf("Press any key to end...");

    _getch();      

    return 0;

}

Edited by JimPanse
Link to comment

LabVIEW can NOT generate a callback function pointer. That would require a very complex stack configuration dialog that would make the current Call Library Node configuration dialog look like childs play.

Instead you have to write a wrapper DLL in C that provides the callback function, calls the driver function to install that callback function and the callback function needs to translate the actual callback event into a LabVIEW compatible event such as an occurrence or user event.

The Callback tab in the Call Library Node configuration is despite its name NOT what you are looking for. It's not to configure a callback function that your DLL can call but instead to configure callback functions that the DLL provides that LabVIEW can call into while it loads the VI containing the function node (Reserve), when unloading that VI (Unreserve) and when aborting the VI hierarchy containing that function node (Abort). It's the opposite of what you try to do here.

Link to comment
Posted (edited)

Hello Rolf,

thank you very much for your reply. Is there an example somewhere of how to create this wrapper DLL in C? Or could you briefly describe how the wrapper should be structured so that the event-based image acquisition can be output under LabView.

Many thanks, Jim

Edited by JimPanse
Link to comment

It's been getting a bit silent on that front in recent years but searching for PostLVUserEvent() on google (and more specifically the NI forum and here on LavaG) should give you a number of posts to study that will give you some ideas. But one warning, function pointers is usually mentioned in one of the last chapters of every C programming manual, since it is quite tricky to understand and use for most C programmers. It's definitely not a topic for the faint at heart.

Edited by Rolf Kalbermatter
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.