It can also be helpful to familiarize yourself with the NodeMapCallback_C example, as a callback can be thought of as a simpler, easier-to-use event. Although events are more cumbersome, they are also much more flexible and extensible.
Events generally require a class to be defined as an event handler; however, because C is not an object-oriented language, a pseudo-class is created using a function (or two) and a struct whereby the function(s) acts as the event handler method and the struct acts as its properties.
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define MAX_BUFF_LEN 256
{
}
{
{
printf(
"Unable to create camera list (system arrival). Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
{
printf(
"Unable to retrieve camera list (system arrival). Non-fatal error: %s [%d]\n\n",
err);
return;
}
size_t numCameras = 0;
{
printf(
"Unable to retrieve camera list size (system arrival). Non-fatal error: %s [%d]\n\n",
err);
return;
}
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
printf("System event handler:\n");
printf("\tDevice %s has arrived on the system.\n", deviceSerialNumber);
printf(
"\tThere %s %u %s on the system.\n\n",
(numCameras == 1 ? "is" : "are"),
(unsigned int)numCameras,
(numCameras == 1 ? "device" : "devices"));
{
printf(
"Unable to clear camera list (system arrival). Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
{
printf(
"Unable to destroy camera list (system arrival). Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
}
{
{
printf(
"Unable to create camera list (system removal). Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
{
printf(
"Unable to retrieve camera list (system removal). Non-fatal error: %s [%d]\n\n",
err);
return;
}
size_t numCameras = 0;
{
printf(
"Unable to retrieve camera list size (system removal). Non-fatal error: %s [%d]\n\n",
err);
return;
}
{
strcpy(deviceSerialNumber, "");
lenDeviceSerialNumber = 0;
}
printf("System event handler:\n");
printf("\tDevice %s was removed from the system.\n", deviceSerialNumber);
printf(
"\tThere %s %u %s on the system.\n\n",
(numCameras == 1 ? "is" : "are"),
(unsigned int)numCameras,
(numCameras == 1 ? "device" : "devices"));
{
printf(
"Unable to clear camera list (system removal). Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
{
printf(
"Unable to destroy camera list (system removal). Non-fatal error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
}
{
{
printf(
"Unable to retrieve TL system nodemap. error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
err =
spinNodeMapGetNode(hNodeMapTLSystem,
"EnumerateGEVInterfaces", &hEnumerateGevInterfaces);
{
printf(
"Unable to retrieve EnumerateGEVInterfaces node. error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return;
}
{
printf(
"Unable to retrieve node readability (EnumerateGEVInterfaces node), with error: %s [%d]\n\n",
err);
return;
}
if (pbReadable)
{
{
printf(
"Unable to retrieve EnumerateGEVInterfaces node value. error: %s [%d]\n\n",
GetLastErrorMessage(), err);
}
else if (!gevEnabled)
{
printf("WARNING: GEV Enumeration is disabled.\n");
printf("If you intend to use GigE cameras please run the EnableGEVInterfaces shortcut\n");
printf("or set EnumerateGEVInterfaces to true and relaunch your application.\n\n");
}
else
{
printf("EnumerateGEVInterfaces is enabled. Continuing..\n\n");
}
}
else
{
printf("EnumerateGEVInterfaces node is unavailable.");
}
}
{
unsigned int i = 0;
printf("Application build date: %s %s \n\n", __DATE__, __TIME__);
{
printf(
"Unable to retrieve system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
spinLibraryVersion hLibraryVersion;
printf(
"Spinnaker library version: %d.%d.%d.%d\n\n",
hLibraryVersion.major,
hLibraryVersion.minor,
hLibraryVersion.type,
hLibraryVersion.build);
size_t numCameras = 0;
{
printf(
"Unable to create camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to retrieve camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to retrieve number of cameras. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("Number of cameras detected: %u\n\n", (unsigned int)numCameras);
printf("\n*** CONFIGURE ENUMERATION EVENTS ***\n\n");
{
printf(
"Unable to create interface event for system. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("Interface event for system created...\n");
{
printf(
"Unable to register interface event on system. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("Interface event registered to system...\n");
printf("Ready! Remove/Plug in cameras to test or press Enter to exit...\n");
getchar();
{
printf(
"Unable to unregister interface event from system. Aborting with error: %s [%d]\n\n",
err);
return err;
}
printf("Event handlers unregistered from system...\n");
{
printf(
"Unable to destroy interface event. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("System event handler destroyed...\n");
{
printf(
"Unable to clear camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to destroy camera list. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
{
printf(
"Unable to release system instance. Aborting with error: %s [%d]\n\n",
GetLastErrorMessage(), err);
return err;
}
printf("\nDone! Press Enter to exit...\n");
getchar();
return err;
}