Chunks Sample
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax);
#define NUM_GRABS 20
#define NUM_BUFFERS 2
int main(void)
{
GENAPIC_RESULT res;
size_t numDevices;
int32_t payloadSize;
unsigned char *buffers[NUM_BUFFERS];
int nGrabs;
size_t nStreams;
_Bool isAvail;
_Bool isReady;
size_t i;
int ret=EXIT_FAILURE;
const char* triggerSelectorValue = "FrameStart";
_Bool isAvailFrameStart;
_Bool isAvailAcquisitionStart;
hDev = PYLONC_INVALID_HANDLE;
printf("Enumerating devices ...\n");
CHECK(res);
if ( 0 == numDevices )
{
fprintf( stderr, "No devices found.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
printf("Opening first device ...\n");
CHECK(res);
res =
PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM );
CHECK(res);
if (isAvail)
{
CHECK(res);
}
if (isAvailAcquisitionStart && !isAvailFrameStart)
{
CHECK(res);
CHECK(res);
triggerSelectorValue = "AcquisitionStart";
}
else
{
if (isAvailAcquisitionStart)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
CHECK(res);
CHECK(res);
}
CHECK(res);
CHECK(res);
if ( isAvail )
{
CHECK(res);
}
if ( ! isAvail )
{
fprintf( stderr, "The device doesn't support the chunk mode.\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
if ( isAvail )
{
CHECK(res);
if ( isAvail )
{
CHECK(res);
}
}
if ( isAvail )
{
CHECK(res);
if ( isAvail )
{
CHECK(res);
}
}
CHECK(res);
if ( hChunkParser == PYLONC_INVALID_HANDLE )
{
fprintf(stderr, "No chunk parser available.\n");
goto exit;
}
CHECK(res);
if ( nStreams < 1 )
{
fprintf( stderr, "The transport layer doesn't support image streams.\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
CHECK(res);
CHECK(res);
res = PylonDeviceGetIntegerFeatureInt32( hDev, "PayloadSize", &payloadSize );
CHECK(res);
for ( i = 0; i < NUM_BUFFERS; ++i )
{
buffers[i] = (unsigned char*) malloc ( payloadSize );
if ( NULL == buffers[i] )
{
fprintf( stderr, "Out of memory.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
}
CHECK(res);
CHECK(res);
CHECK(res);
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
}
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
}
CHECK(res);
CHECK(res);
nGrabs = 0;
while ( nGrabs < NUM_GRABS )
{
size_t bufferIndex;
unsigned char min, max;
int32_t chunkWidth = 0;
int32_t chunkHeight = 0;
CHECK(res);
if ( ! isReady )
{
fprintf(stderr, "Grab timeout occurred.\n");
break;
}
CHECK(res);
if ( ! isReady )
{
fprintf(stderr, "Failed to retrieve a grab result\n");
break;
}
nGrabs++;
CHECK(res);
bufferIndex = (size_t) grabResult.
Context;
{
unsigned char* buffer;
buffer = (
unsigned char*) grabResult.
pBuffer;
printf("Grabbed frame #%2d into buffer %2d.\n", nGrabs, (int) bufferIndex );
{
fprintf(stderr, "Received a buffer not containing chunk data?\n");
}
else
{
_Bool hasCRC;
CHECK(res);
CHECK(res);
if ( hasCRC )
{
_Bool isOk;
CHECK(res);
printf("Frame %d contains a CRC checksum. The checksum %s ok.\n", nGrabs, isOk ? "is" : "is not");
}
printf("Frame %d %s a frame counter chunk.\n", nGrabs, isAvail ? "contains" : "doesn't contain" );
if ( isAvail )
{
int64_t counter;
CHECK(res);
#if __STDC_VERSION__ >= 199901L || defined(__GNUC__)
printf("Frame counter of frame %d: %lld.\n", nGrabs, (long long) counter );
#else
printf("Frame counter of frame %d: %I64d.\n", nGrabs, counter );
#endif
}
printf("Frame %d %s a width chunk.\n", nGrabs, isAvail ? "contains" : "doesn't contain" );
if ( isAvail )
{
res = PylonDeviceGetIntegerFeatureInt32( hDev, "ChunkWidth", &chunkWidth );
CHECK(res);
printf("Width of frame %d: %d.\n", nGrabs, chunkWidth );
}
CHECK(res);
printf("Frame %d %s a height chunk.\n", nGrabs, isAvail ? "contains" : "doesn't contain" );
if ( isAvail )
{
res = PylonDeviceGetIntegerFeatureInt32( hDev, "ChunkHeight", &chunkHeight );
CHECK(res);
printf("Height of frame %d: %d.\n", nGrabs, chunkHeight );
}
}
getMinMax( buffer, chunkWidth, chunkHeight, &min, &max );
printf("Min. gray value = %3u, Max. gray value = %3u\n", min, max);
CHECK(res);
}
{
fprintf( stderr, "Frame %d wasn't grabbed successfully. Error code = 0x%08X\n",
}
CHECK(res);
}
CHECK(res);
CHECK(res);
do
{
CHECK(res);
} while ( isReady );
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
free( buffers[i] );
}
CHECK(res);
CHECK(res);
CHECK(res);
ret = EXIT_SUCCESS;
exit:
if ( hDev != PYLONC_INVALID_HANDLE )
{
CHECK(res);
CHECK(res);
CHECK(res);
}
CHECK(res);
CHECK(res);
pressEnterToExit();
return ret;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
size_t length;
errMsg = (char*) malloc( length );
fprintf( stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
free( errMsg);
errMsg = (char*) malloc( length );
fprintf( stderr, "%s\n", errMsg);
free( errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax)
{
unsigned char min = 255;
unsigned char max = 0;
unsigned char val;
const unsigned char *p;
for ( p = pImg; p < pImg + width * height; p++ )
{
val = *p;
if ( val > max )
max = val;
if ( val < min )
min = val;
}
pMin = min;
pMax = max;
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
Events Sample
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax);
void GENAPIC_CC endOfExposureCallback(
NODE_HANDLE hNode );
#define NUM_GRABS 100
#define NUM_IMAGE_BUFFERS 5
#define NUM_EVENT_BUFFERS 20
int main(void)
{
GENAPIC_RESULT res;
size_t numDevices;
int32_t payloadSize;
unsigned char *buffers[NUM_IMAGE_BUFFERS];
int nGrabs;
size_t nStreams;
_Bool isAvail;
_Bool isReady;
size_t i;
int32_t sfncVersionMajor;
CHECK(res);
if ( 0 == numDevices )
{
fprintf( stderr, "No devices found.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
res =
PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM | PYLONC_ACCESS_MODE_EVENT );
CHECK(res);
{
char buf[256];
size_t siz = sizeof(buf);
_Bool isReadable;
if ( isReadable )
{
CHECK(res);
printf("Using camera %s\n", buf);
}
}
if (isAvail)
{
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
CHECK(res);
if ( isAvail )
{
CHECK(res);
}
if ( !isAvail )
{
fprintf(stderr, "Device doesn't support events.\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
if ( PylonDeviceGetIntegerFeatureInt32( hDev,
"DeviceSFNCVersionMajor", &sfncVersionMajor ) !=
GENAPI_E_OK )
{
sfncVersionMajor = 0;
}
CHECK(res);
if ( sfncVersionMajor >= 2 )
else
CHECK(res);
res = PylonDeviceGetIntegerFeatureInt32( hDev, "PayloadSize", &payloadSize );
CHECK(res);
CHECK(res);
if ( nStreams < 1 )
{
fprintf( stderr, "The transport layer doesn't support image streams\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
CHECK(res);
CHECK(res);
for ( i = 0; i < NUM_IMAGE_BUFFERS; ++i )
{
buffers[i] = (unsigned char*) malloc ( payloadSize );
if ( NULL == buffers[i] )
{
fprintf( stderr, "Out of memory!\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
}
CHECK(res);
CHECK(res);
CHECK(res);
for ( i = 0; i < NUM_IMAGE_BUFFERS; ++i )
{
CHECK(res);
}
for ( i = 0; i < NUM_IMAGE_BUFFERS; ++i )
{
CHECK(res);
}
CHECK(res);
if ( hEventGrabber == PYLONC_INVALID_HANDLE )
{
fprintf(stderr, "No event grabber supported.\n");
pressEnterToExit();
return EXIT_FAILURE;
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
if ( hEventAdapter == PYLONC_INVALID_HANDLE )
{
fprintf(stderr, "No event adapter supported.\n");
pressEnterToExit();
return EXIT_FAILURE;
}
CHECK(res);
if ( sfncVersionMajor >= 2 )
else
CHECK(res);
{
fprintf( stderr, "There is no ExposureEndEventFrameID or EventExposureEndFrameID parameter.\n");
pressEnterToExit();
return EXIT_FAILURE;
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
nGrabs = 0;
while ( nGrabs < NUM_GRABS )
{
size_t bufferIndex;
size_t waitObjectIndex;
unsigned char min, max;
CHECK(res);
if ( ! isReady )
{
fprintf(stderr, "Timeout. Neither grabbed an image nor received an event.\n");
break;
}
if ( 0 == waitObjectIndex )
{
CHECK(res);
if ( ! isReady )
{
fprintf(stderr, "Failed to retrieve an event\n");
break;
}
{
CHECK(res);
}
else
{
fprintf(stderr,
"Error when receiving an event: 0x%08x\n", eventMsg.
ErrorCode );
}
}
else if ( 1 == waitObjectIndex )
{
CHECK(res);
if ( ! isReady )
{
fprintf(stderr, "Failed to retrieve a grab result\n");
break;
}
nGrabs++;
bufferIndex = (size_t) grabResult.
Context;
{
unsigned char* buffer;
buffer = (
unsigned char*) grabResult.
pBuffer;
getMinMax( buffer, grabResult.
SizeX, grabResult.
SizeY, &min, &max );
printf("Grabbed frame #%2d into buffer %2d. Min. gray value = %3u, Max. gray value = %3u\n",
nGrabs, (int)bufferIndex, min, max);
}
{
fprintf( stderr, "Frame %d wasn't grabbed successfully. Error code = 0x%08X\n",
}
CHECK(res);
}
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
do
{
CHECK(res);
} while ( isReady );
for ( i = 0; i < NUM_IMAGE_BUFFERS; ++i )
{
CHECK(res);
free( buffers[i] );
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
pressEnterToExit();
return EXIT_SUCCESS;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
size_t length;
errMsg = (char*) malloc( length );
fprintf( stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
free( errMsg);
errMsg = (char*) malloc( length );
fprintf( stderr, "%s\n", errMsg);
free( errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax)
{
unsigned char min = 255;
unsigned char max = 0;
unsigned char val;
const unsigned char *p;
for ( p = pImg; p < pImg + width * height; p++ )
{
val = *p;
if ( val > max )
max = val;
if ( val < min )
min = val;
}
pMin = min;
pMax = max;
}
void GENAPIC_CC endOfExposureCallback(
NODE_HANDLE hNode )
{
int64_t frame;
GENAPIC_RESULT res;
CHECK(res);
#if __STDC_VERSION__ >= 199901L || defined(__GNUC__)
printf("Got end-of-exposure event. Frame number: %lld\n", (long long) frame );
#else
printf("Got end-of-exposure event. Frame number: %I64d\n", frame );
#endif
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
GenApiParam Sample
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#define STRING_BUFFER_SIZE 512
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
void pressEnterToExit(void);
static void
printErrorAndExit(GENAPIC_RESULT errc)
{
char *errMsg;
size_t length;
errMsg = (char*) malloc(length);
fprintf(stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
free(errMsg);
errMsg = (char*) malloc(length);
fprintf(stderr, "%s\n", errMsg);
free(errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
static void
{
const char * pFeatureName;
_Bool val, val_read, val_write;
GENAPIC_RESULT res;
CHECK(res);
pFeatureName = "Width";
CHECK(res);
{
CHECK(res);
}
else
{
val = 0;
}
printf("The '%s' feature %s implemented\n", pFeatureName, val ? "is" : "is not");
pFeatureName = "Weirdness";
CHECK(res);
{
CHECK(res);
}
else
{
val = 0;
}
printf("The '%s' feature %s implemented\n", pFeatureName, val ? "is" : "is not");
pFeatureName = "BinningVertical";
CHECK(res);
{
CHECK(res);
}
else
{
val = 0;
}
printf("The '%s' feature %s available\n", pFeatureName, val ? "is" : "is not");
pFeatureName = "Width";
CHECK(res);
{
CHECK(res);
CHECK(res);
}
else
{
val_read = val_write = 0;
}
printf("The '%s' feature %s readable\n", pFeatureName, val_read ? "is" : "is not");
printf("The '%s' feature %s writable\n", pFeatureName, val_write ? "is" : "is not");
printf("\n");
}
static void
{
static const char featureName[] = "Width";
int64_t val, min, max, incr;
GENAPIC_RESULT res;
_Bool bval;
CHECK(res);
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", featureName);
return;
}
CHECK(res);
{
fprintf(stderr, "'%s' is not an integer feature\n", featureName);
return;
}
CHECK(res);
if (bval)
{
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
#if __STDC_VERSION__ >= 199901L || defined(__GNUC__)
printf("%s: min= %lld max= %lld incr=%lld Value=%lld\n", featureName, (long long) min, (long long) max, (long long) incr, (long long) val);
#else
printf("%s: min= %I64d max= %I64d incr=%I64d Value=%I64d\n", featureName, min, max, incr, val);
#endif
CHECK(res);
if (bval)
{
CHECK(res);
}
else
fprintf(stderr, "Cannot set value for feature '%s' - node not writable\n", featureName);
}
else
fprintf(stderr, "Cannot read feature '%s' - node not readable\n", featureName);
}
static void
{
static const char featureName[] = "Gamma";
_Bool bval;
double min, max, value;
GENAPIC_RESULT res;
CHECK(res);
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", featureName);
return;
}
CHECK(res);
{
fprintf(stderr, "'%s' is not an floating-point feature\n", featureName);
return;
}
CHECK(res);
if (bval)
{
CHECK(res);
CHECK(res);
CHECK(res);
printf("%s: min = %4.2f, max = %4.2f, value = %4.2f\n", featureName, min, max, value);
CHECK(res);
if (bval)
{
value = 0.5 * (min + max);
printf("Setting %s to %4.2f\n", featureName, value);
CHECK(res);
}
else
printf("Cannot set value for feature '%s' - node not writable\n", featureName);
}
else
printf("Cannot read feature '%s' - node not readable\n", featureName);
}
static void
{
static const char featureName[] = "GammaEnable";
_Bool value,bval;
GENAPIC_RESULT res;
CHECK(res);
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", featureName);
return;
}
CHECK(res);
{
fprintf(stderr, "'%s' is not a boolean feature\n", featureName);
return;
}
CHECK(res);
if (bval)
{
CHECK(res);
printf("The %s features is %s\n", featureName, value ? "on" : "off");
CHECK(res);
if (bval)
{
value = (_Bool) !value;
printf("Switching the %s feature %s\n", featureName, value ? "on" : "off");
CHECK(res);
}
else
printf("Cannot set value for feature '%s' - node not writable\n", featureName);
}
else
printf("Cannot read feature '%s' - node not readable\n", featureName);
}
static void
{
static const char featureName[] = "Width";
_Bool bval;
GENAPIC_RESULT res;
CHECK(res);
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", featureName);
return;
}
CHECK(res);
{
fprintf(stderr, "'%s' is not an integer feature\n", featureName);
return;
}
CHECK(res);
if (bval)
{
size_t len;
char *buf, fixBuf[32];
_Bool bval;
CHECK(res);
buf = (char *) malloc(len);
CHECK(res);
printf("%s: %s\n", featureName, buf);
free(buf);
len = 1;
{
printf("Buffer is too small for the value of '%s'. The required buffer size is %d\n", featureName, (int) len);
}
else
CHECK(res);
len = sizeof fixBuf;
CHECK(res);
CHECK(res);
if (bval)
{
{
size_t l;
char *msg;
msg = (char *)malloc(l);
printf("%s\n", msg);
free(msg);
}
}
else
printf("Cannot set value for feature '%s' - node not writable\n", featureName);
}
else
printf("Cannot read feature '%s' - node not readable\n", featureName);
}
static void
{
static const char featureName[] = "PixelFormat";
_Bool bval;
GENAPIC_RESULT res;
CHECK(res);
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", featureName);
return;
}
CHECK(res);
{
fprintf(stderr, "'%s' is not an enumeration feature\n", featureName);
return;
}
CHECK(res);
if (bval)
{
static const char symMono8[] = "Mono8",
symMono16[] = "Mono16",
symYUV422Packed[] = "YUV422Packed";
size_t len;
char value[64];
_Bool supportsMono8, supportsYUV422Packed, supportsMono16;
len = sizeof value;
CHECK(res);
printf("PixelFormat: %s\n", value);
CHECK(res);
{
CHECK(res);
}
else
{
supportsMono8 = 0;
}
printf("%s %s a supported value for the PixelFormat feature\n", symMono8, supportsMono8 ? "is" : "is not");
CHECK(res);
{
CHECK(res);
}
else
{
supportsYUV422Packed = 0;
}
printf("%s %s a supported value for the PixelFormat feature\n", symYUV422Packed, supportsYUV422Packed ? "is" : "is not");
CHECK(res);
{
CHECK(res);
}
else
{
supportsMono16 = 0;
}
printf("%s %s a supported value for the PixelFormat feature\n", symMono16, supportsMono16 ? "is" : "is not");
CHECK(res);
if (bval)
{
if (supportsMono16)
{
printf("Setting PixelFormat to Mono16\n");
CHECK(res);
}
else if (supportsYUV422Packed)
{
printf("Setting PixelFormat to YUV422Packed\n");
CHECK(res);
}
else if (supportsMono8)
{
printf("Setting PixelFormat to Mono8\n");
CHECK(res);
}
CHECK(res);
}
else
printf("Cannot set value for feature '%s' - node not writable\n", featureName);
}
else
printf("Cannot read feature '%s' - node not readable\n", featureName);
}
static void
{
static const char featureName[] = "PixelFormat";
_Bool bval;
GENAPIC_RESULT res;
CHECK(res);
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", featureName);
return;
}
CHECK(res);
{
fprintf(stderr, "'%s' is not an enumeration feature\n", featureName);
return;
}
CHECK(res);
if (bval)
{
size_t max, i;
CHECK(res);
printf("Allowed values for feature '%s':\n"
"--------------\n",
featureName);
for (i = 0; i < max; i++)
{
char name[128], displayName[STRING_BUFFER_SIZE], description[STRING_BUFFER_SIZE];
size_t siz;
_Bool avail;
CHECK(res);
siz = sizeof name;
CHECK(res);
siz = sizeof displayName;
CHECK(res);
siz = sizeof description;
CHECK(res);
CHECK(res);
printf("Node name: %s\n"
"Display name: %s\n"
"Description: %s\n"
"Available: %s\n"
"--------------\n",
name, displayName, description, avail ? "yes" : "no");
}
}
else
printf("Cannot read feature '%s' - node not readable\n", featureName);
}
static void
handleCategory(
NODE_HANDLE hRoot,
char * buf,
unsigned int depth)
{
GENAPIC_RESULT res;
size_t bufsiz, siz, numfeat, i;
siz = bufsiz = STRING_BUFFER_SIZE - depth * 2;
CHECK(res);
CHECK(res);
printf("%s category has %u children\n", buf - depth * 2, (unsigned int) numfeat);
buf++ = ' ';
buf++ = ' ';
bufsiz -= 2;
++depth;
for (i = 0; i < numfeat; ++i)
{
CHECK(res);
CHECK(res);
{
const char *amode;
siz = bufsiz;
CHECK(res);
CHECK(res);
switch (am)
{
amode = "not implemented";
break;
amode = "not available";
break;
amode = "write only";
break;
amode = "read only";
break;
amode = "read and write";
break;
default:
amode = "undefined";
break;
}
printf("%s feature - access: %s\n", buf - depth * 2, amode);
}
else
handleCategory(hNode, buf, depth);
}
}
static void
{
char buf[512];
GENAPIC_RESULT res;
CHECK(res);
CHECK(res);
handleCategory(hNode, buf, 0);
}
static void
{
static const char selectorName[] = "UserSetSelector",
commandName[] = "UserSetLoad";
_Bool bval;
GENAPIC_RESULT res;
CHECK(res);
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", commandName);
return;
}
CHECK(res);
{
fprintf(stderr, "There is no feature named '%s'\n", selectorName);
return;
}
CHECK(res);
{
fprintf(stderr, "'%s' is not a command feature\n", selectorName);
return;
}
CHECK(res);
if (bval)
{
CHECK(res);
}
else
printf("Cannot set selector '%s' - node not writable\n", selectorName);
CHECK(res);
if (bval)
{
printf("Loading the default set.\n");
CHECK(res);
}
else
printf("Cannot execute command '%s' - node not writable\n", commandName);
}
int
main(void)
{
GENAPIC_RESULT res;
size_t numDevices;
CHECK(res);
if (0 == numDevices)
{
fprintf(stderr, "No devices found.\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
res =
PylonDeviceOpen(hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM);
CHECK(res);
{
char buf[256];
size_t siz = sizeof(buf);
_Bool isReadable;
if (isReadable)
{
CHECK(res);
printf("Using camera %s\n", buf);
}
}
demonstrateAccessibilityCheck(hDev);
puts("");
demonstrateIntFeature(hDev);
puts("");
demonstrateFloatFeature(hDev);
puts("");
demonstrateBooleanFeature(hDev);
puts("");
demonstrateFromStringToString(hDev);
puts("");
demonstrateEnumFeature(hDev);
puts("");
demonstrateEnumIteration(hDev);
puts("");
demonstrateCommandFeature(hDev);
puts("");
demonstrateCategory(hDev);
CHECK(res);
CHECK(res);
pressEnterToExit();
return EXIT_SUCCESS;
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
GrabTwoCameras Sample
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0400
#endif
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#ifdef GENAPIC_LINUX_BUILD
# include <sys/timerfd.h>
# include <alloca.h>
# include <errno.h>
# include <unistd.h>
#endif
#define NUM_DEVICES 2
#define NUM_BUFFERS 5
#define GIGE_PACKET_SIZE 1500
#define GIGE_PROTOCOL_OVERHEAD 36
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax);
int main(void)
{
GENAPIC_RESULT res;
size_t numDevicesAvail;
_Bool isAvail;
int deviceIndex;
#ifdef GENAPIC_WIN_BUILD
HANDLE hTimer;
#else
int fdTimer;
#endif
unsigned char *buffers[NUM_DEVICES][NUM_BUFFERS];
CHECK(res);
if ( numDevicesAvail < NUM_DEVICES)
{
fprintf( stderr, "Not enough devices found. Found %u devices. At least %i devices needed to run this sample.\n", (unsigned int) numDevicesAvail, NUM_DEVICES );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
#ifdef GENAPIC_WIN_BUILD
hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
if (hTimer == NULL)
{
fprintf( stderr, "CreateWaitableTimer() failed.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
res = PylonWaitObjectFromW32(hTimer, 0, &woTimer);
CHECK(res);
#else
fdTimer = timerfd_create(CLOCK_MONOTONIC, 0);
if (fdTimer == -1)
{
fprintf( stderr, "timerfd_create() failed. %s\n", strerror(errno) );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
#endif
CHECK(res);
for (deviceIndex = 0; deviceIndex < NUM_DEVICES; ++deviceIndex)
{
CHECK(res);
res =
PylonDeviceOpen( hDev[deviceIndex], PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM );
CHECK(res);
{
char buf[256];
size_t siz = sizeof(buf);
_Bool isReadable;
if ( isReadable )
{
CHECK(res);
printf("Using camera '%s'\n", buf);
}
}
if ( ! isAvail )
{
fprintf(stderr, "Device doesn't support the Mono8 pixel format");
pressEnterToExit();
exit (EXIT_FAILURE);
}
CHECK(res);
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
CHECK(res);
CHECK(res);
{
CHECK(res);
CHECK(res);
CHECK(res);
}
#ifdef GENAPIC_WIN_BUILD
{
int64_t newPacketSize = 4915 / NUM_DEVICES;
int64_t recommendedPacketSize = 0;
CHECK(res);
if (newPacketSize < recommendedPacketSize)
{
int64_t packetSizeInc = 0;
CHECK(res);
newPacketSize -= newPacketSize % packetSizeInc;
}
else
{
newPacketSize = recommendedPacketSize;
}
CHECK(res);
#if __STDC_VERSION__ >= 199901L
printf("Using packetsize: %lld\n", newPacketSize);
#else
printf("Using packetsize: %I64d\n", newPacketSize);
#endif
}
#endif
}
for (deviceIndex = 0; deviceIndex < NUM_DEVICES; ++deviceIndex)
{
size_t i;
int32_t payloadSize;
res = PylonDeviceGetIntegerFeatureInt32( hDev[deviceIndex], "PayloadSize", &payloadSize );
CHECK(res);
CHECK(res);
if ( i < 1 )
{
fprintf( stderr, "The transport layer doesn't support image streams.\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
for ( i = 0; i < NUM_BUFFERS; ++i )
{
buffers[deviceIndex][i] = (unsigned char *) malloc ( payloadSize );
if ( NULL == buffers[deviceIndex][i] )
{
fprintf( stderr, "Out of memory.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
}
CHECK(res);
CHECK(res);
CHECK(res);
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
}
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
}
}
for (deviceIndex = 0; deviceIndex < NUM_DEVICES; ++deviceIndex)
{
{
break;
}
}
{
unsigned int nGrabs = 0;
#ifdef GENAPIC_WIN_BUILD
LARGE_INTEGER intv;
intv.QuadPart = -50000000I64;
if (!SetWaitableTimer(hTimer, &intv, 0, NULL, NULL, FALSE))
{
fprintf( stderr, "SetWaitableTimer() failed.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
#else
struct itimerspec timer_value;
timer_value.it_interval.tv_sec = 0;
timer_value.it_interval.tv_nsec = 0;
timer_value.it_value.tv_sec = 5;
timer_value.it_value.tv_nsec = 0;
if (timerfd_settime(fdTimer, 0, &timer_value, NULL) == -1)
{
fprintf( stderr, "timerfd_settime() failed. %s\n", strerror(errno) );
pressEnterToExit();
exit(EXIT_FAILURE);
}
#endif
for (;;)
{
_Bool isReady;
size_t woidx;
unsigned char min, max;
CHECK(res);
if ( !isReady )
{
fputs("Grab timeout occurred.\n", stderr);
break;
}
if (woidx == 0) {
fputs("Game over.\n", stderr);
break;
}
--woidx;
CHECK(res);
if ( !isReady )
{
fprintf(stderr, "Failed to retrieve a grab result\n");
break;
}
{
unsigned char* buffer = (
unsigned char*) grabResult.
pBuffer;
getMinMax( buffer, grabResult.
SizeX, grabResult.
SizeY, &min, &max );
printf("Grabbed frame #%2u from camera %2u into buffer %2ld. Min. val=%3u, Max. val=%3u\n",
nGrabs, (
unsigned int) woidx, (
long) grabResult.
Context, min, max);
#ifdef GENAPIC_WIN_BUILD
res = PylonImageWindowDisplayImageGrabResult(woidx, &grabResult);
CHECK(res);
#endif
}
{
fprintf( stderr, "Frame %u wasn't grabbed successfully. Error code = 0x%08X\n",
}
CHECK(res);
nGrabs++;
}
}
for (deviceIndex = 0; deviceIndex < NUM_DEVICES; ++deviceIndex)
{
CHECK(res);
}
CHECK(res);
CHECK(res);
CHECK(res);
for (deviceIndex = 0; deviceIndex < NUM_DEVICES; ++deviceIndex)
{
size_t i;
_Bool rdy;
CHECK(res);
do
{
CHECK(res);
} while ( rdy );
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
free( buffers[deviceIndex][i] );
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
}
pressEnterToExit();
#ifdef GENAPIC_LINUX_BUILD
close(fdTimer);
#endif
return EXIT_SUCCESS;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
size_t length;
errMsg = (char*) alloca( length );
fprintf( stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
pressEnterToExit();
exit(EXIT_FAILURE);
}
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax)
{
unsigned char min = 255;
unsigned char max = 0;
unsigned char val;
const unsigned char *p;
for ( p = pImg; p < pImg + width * height; p++ )
{
val = *p;
if ( val > max )
max = val;
if ( val < min )
min = val;
}
pMin = min;
pMax = max;
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
OverlappedGrab Sample
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax);
#define NUM_GRABS 100
#define NUM_BUFFERS 5
int main(void)
{
GENAPIC_RESULT res;
size_t numDevices;
int32_t payloadSize;
unsigned char *buffers[NUM_BUFFERS];
int nGrabs;
size_t nStreams;
_Bool isAvail;
_Bool isReady;
size_t i;
CHECK(res);
if ( 0 == numDevices )
{
fprintf( stderr, "No devices found.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
res =
PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM );
CHECK(res);
{
char buf[256];
size_t siz = sizeof(buf);
_Bool isReadable;
if ( isReadable )
{
CHECK(res);
printf("Using camera %s\n", buf);
}
}
if (isAvail)
{
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
CHECK(res);
if ( isAvail )
{
CHECK(res);
}
CHECK(res);
if ( nStreams < 1 )
{
fprintf( stderr, "The transport layer doesn't support image streams\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
CHECK(res);
CHECK(res);
{
res = PylonDeviceGetIntegerFeatureInt32( hDev, "PayloadSize", &payloadSize );
CHECK(res);
}
else
{
int64_t i64payloadSize;
CHECK(res);
CHECK(res);
{
fprintf( stderr, "There is no PayloadSize parameter.\n");
pressEnterToExit();
return EXIT_FAILURE;
}
CHECK(res);
payloadSize = (int32_t) i64payloadSize;
}
for ( i = 0; i < NUM_BUFFERS; ++i )
{
buffers[i] = (unsigned char*) malloc ( payloadSize );
if ( NULL == buffers[i] )
{
fprintf( stderr, "Out of memory!\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
}
CHECK(res);
CHECK(res);
CHECK(res);
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
}
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
}
CHECK(res);
nGrabs = 0;
while ( nGrabs < NUM_GRABS )
{
size_t bufferIndex;
unsigned char min, max;
CHECK(res);
if ( ! isReady )
{
fprintf(stderr, "Grab timeout occurred\n");
break;
}
CHECK(res);
if ( ! isReady )
{
fprintf(stderr, "Failed to retrieve a grab result\n");
break;
}
nGrabs++;
bufferIndex = (size_t) grabResult.
Context;
{
unsigned char* buffer;
buffer = (
unsigned char*) grabResult.
pBuffer;
getMinMax( buffer, grabResult.
SizeX, grabResult.
SizeY, &min, &max );
printf("Grabbed frame %2d into buffer %2d. Min. gray value = %3u, Max. gray value = %3u\n",
nGrabs, (int) bufferIndex, min, max);
#ifdef GENAPIC_WIN_BUILD
res = PylonImageWindowDisplayImageGrabResult(0, &grabResult);
CHECK(res);
#endif
}
{
fprintf( stderr, "Frame %d wasn't grabbed successfully. Error code = 0x%08X\n",
}
CHECK(res);
}
CHECK(res);
CHECK(res);
do
{
CHECK(res);
} while ( isReady );
for ( i = 0; i < NUM_BUFFERS; ++i )
{
CHECK(res);
free( buffers[i] );
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
pressEnterToExit();
return EXIT_SUCCESS;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
size_t length;
errMsg = (char*) malloc( length );
fprintf( stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
free( errMsg);
errMsg = (char*) malloc( length );
fprintf( stderr, "%s\n", errMsg);
free( errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax)
{
unsigned char min = 255;
unsigned char max = 0;
unsigned char val;
const unsigned char *p;
for ( p = pImg; p < pImg + width * height; p++ )
{
val = *p;
if ( val > max )
max = val;
if ( val < min )
min = val;
}
pMin = min;
pMax = max;
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
ParametrizeCamera Sample
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#ifdef __GNUC__
# include <alloca.h>
#endif
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
int main(void)
{
GENAPIC_RESULT res;
size_t numDevices;
CHECK(res);
if ( 0 == numDevices )
{
fprintf( stderr, "No devices found.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
res =
PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM );
CHECK(res);
{
char buf[256];
size_t siz = sizeof(buf);
_Bool isReadable;
if ( isReadable )
{
CHECK(res);
printf("Using camera %s\n", buf);
}
}
demonstrateAccessibilityCheck( hDev );
puts("");
demonstrateIntFeature( hDev );
puts("");
demonstrateInt32Feature( hDev );
puts("");
demonstrateFloatFeature( hDev );
puts("");
demonstrateBooleanFeature( hDev );
puts("");
demonstrateFromStringToString( hDev );
puts("");
demonstrateEnumFeature( hDev );
puts("");
demonstrateCommandFeature( hDev );
CHECK(res);
CHECK(res);
pressEnterToExit();
return EXIT_SUCCESS;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
size_t length;
errMsg = (char*) malloc( length );
fprintf( stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
free( errMsg);
errMsg = (char*) malloc( length );
fprintf( stderr, "%s\n", errMsg);
free( errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
{
_Bool val;
printf("The 'Width' feature %s implemented\n", val ? "is" : "isn't");
printf("The 'MyCustomFeature' feature %s implemented\n", val ? "is" : "isn't");
printf("The 'BinningVertical' feature %s available\n", val ? "is" : "isn't");
printf("The 'Width' feature %s readable\n", val ? "is" : "isn't");
printf("The 'MyCustomFeature' feature %s readable\n", val ? "is" : "isn't");
printf("The 'Width' feature %s writable\n", val ? "is" : "isn't");
printf("\n");
}
{
static const char featureName[] = "Width";
int64_t val, min, max, incr;
GENAPIC_RESULT res;
{
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
#if __STDC_VERSION__ >= 199901L || defined(__GNUC__)
printf("%s: min= %lld max= %lld incr=%lld Value=%lld\n", featureName, (long long ) min, (long long ) max, (long long ) incr, (long long ) val );
#else
printf("%s: min= %I64d max= %I64d incr=%I64d Value=%I64d\n", featureName, min, max, incr, val );
#endif
{
CHECK(res);
}
else
fprintf(stderr, "The %s feature is not writable.\n", featureName );
}
else
fprintf(stderr, "The %s feature is not readable.\n", featureName );
}
{
static const char featureName[] = "Height";
int32_t val, min, max, incr;
GENAPIC_RESULT res;
{
res = PylonDeviceGetIntegerFeatureMinInt32( hDev, featureName, &min );
CHECK(res);
res = PylonDeviceGetIntegerFeatureMaxInt32( hDev, featureName, &max );
CHECK(res);
res = PylonDeviceGetIntegerFeatureIncInt32( hDev, featureName, &incr);
CHECK(res);
res = PylonDeviceGetIntegerFeatureInt32( hDev, featureName, &val );
CHECK(res);
printf("%s: min= %d max= %d incr=%d Value=%d\n", featureName, min, max, incr, val );
{
res = PylonDeviceSetIntegerFeatureInt32( hDev, featureName, min + (max - min) / incr / 2 * incr );
CHECK(res);
}
else
fprintf(stderr, "The %s feature is not writable.\n", featureName );
}
else
fprintf(stderr, "The %s feature is not readable.\n", featureName );
}
{
static const char featureName[] = "Gamma";
_Bool isWritable;
double min, max, value;
GENAPIC_RESULT res;
{
CHECK(res);
CHECK(res);
CHECK(res);
printf("%s: min = %4.2f, max = %4.2f, value = %4.2f\n", featureName, min, max, value );
if ( isWritable )
{
value = 0.5 * ( min + max );
printf("Setting %s to %4.2f\n", featureName, value );
CHECK(res);
}
else
fprintf(stderr, "The %s feature is not writable.\n", featureName );
}
else
fprintf(stderr, "The %s feature is not readable.\n", featureName );
}
{
static const char featureName[] = "GammaEnable";
_Bool isWritable;
_Bool value;
GENAPIC_RESULT res;
if ( isWritable )
{
CHECK(res);
printf("The %s features is %s\n", featureName, value ? "on" : "off" );
value = (_Bool) !value;
printf("Switching the %s feature %s\n", featureName, value ? "on" : "off" );
CHECK(res);
}
else
printf("The %s feature isn't writable\n", featureName );
}
{
static const char featureName[] = "Width";
size_t len;
char* buf;
char smallBuf[1];
char properBuf[32];
GENAPIC_RESULT res;
CHECK(res);
buf = (char*) alloca( len );
CHECK( res );
printf("%s: %s\n", featureName, buf );
len = sizeof (smallBuf);
{
printf("Buffer is too small for the value of '%s'. The required buffer size is %d\n", featureName, (int) len );
}
else
CHECK(res);
len = sizeof (properBuf );
CHECK(res);
{
size_t l;
char *msg;
msg = (char *)malloc(l);
printf("%s\n", msg );
free(msg);
}
}
{
char value[64];
size_t len;
GENAPIC_RESULT res;
_Bool isWritable,
supportsMono8,
supportsYUV422Packed,
supportsMono16;
len = sizeof(value);
CHECK(res);
printf("PixelFormat: %s\n", value);
printf("Mono8 %s a supported value for the PixelFormat feature\n", supportsMono8 ? "is" : "isn't");
printf("YUV422Packed %s a supported value for the PixelFormat feature\n", supportsYUV422Packed ? "is" : "isn't");
printf("Mono16 %s a supported value for the PixelFormat feature\n", supportsMono16 ? "is" : "isn't");
if ( isWritable )
{
if ( supportsMono16 )
{
printf("Setting PixelFormat to Mono16\n");
CHECK(res);
}
else if ( supportsYUV422Packed )
{
printf("Setting PixelFormat to YUV422Packed\n");
CHECK(res);
}
else if ( supportsMono8 )
{
printf("Setting PixelFormat to Mono8\n");
CHECK(res);
}
}
}
{
GENAPIC_RESULT res;
CHECK(res);
printf("Loading the default set.\n");
CHECK(res);
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
SimpleGrab Sample
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax);
int main(void)
{
GENAPIC_RESULT res;
size_t numDevices;
const int numGrabs = 10;
int32_t payloadSize;
unsigned char* imgBuf;
_Bool isAvail;
int i;
CHECK(res);
if ( 0 == numDevices )
{
fprintf( stderr, "No devices found!\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
res =
PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM );
CHECK(res);
{
char buf[256];
size_t siz = sizeof(buf);
_Bool isReadable;
if ( isReadable )
{
CHECK(res);
printf("Using camera %s\n", buf);
}
}
if (isAvail)
{
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if (isAvail)
{
CHECK(res);
CHECK(res);
}
if ( isAvail )
{
CHECK(res);
}
{
res = PylonDeviceGetIntegerFeatureInt32( hDev, "PayloadSize", &payloadSize );
CHECK(res);
}
else
{
int64_t i64payloadSize;
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
{
fprintf( stderr, "There is no PayloadSize parameter.\n");
pressEnterToExit();
return EXIT_FAILURE;
}
CHECK(res);
payloadSize = (int32_t) i64payloadSize;
CHECK(res);
}
imgBuf = (unsigned char*) malloc( payloadSize );
if ( NULL == imgBuf )
{
fprintf( stderr, "Out of memory.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
for ( i = 0; i < numGrabs; ++i )
{
unsigned char min, max;
_Bool bufferReady;
&grabResult, &bufferReady, 500 );
{
printf("Frame %d: timeout\n", i+1);
}
CHECK(res);
{
getMinMax( imgBuf, grabResult.
SizeX, grabResult.
SizeY, &min, &max );
printf("Grabbed frame #%2d. Min. gray value = %3u, Max. gray value = %3u\n", i+1, min, max);
#ifdef GENAPIC_WIN_BUILD
res = PylonImageWindowDisplayImageGrabResult(0, &grabResult);
CHECK(res);
#endif
}
{
fprintf( stderr, "Frame %d wasn't grabbed successfully. Error code = 0x%08X\n",
}
}
CHECK(res);
CHECK(res);
free( imgBuf );
pressEnterToExit();
return EXIT_SUCCESS;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
size_t length;
errMsg = (char*) malloc( length );
fprintf( stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
free( errMsg);
errMsg = (char*) malloc( length );
fprintf( stderr, "%s\n", errMsg);
free( errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
void getMinMax( const unsigned char* pImg, int32_t width, int32_t height,
unsigned char* pMin, unsigned char* pMax)
{
unsigned char min = 255;
unsigned char max = 0;
unsigned char val;
const unsigned char *p;
for ( p = pImg; p < pImg + width * height; p++ )
{
val = *p;
if ( val > max )
max = val;
if ( val < min )
min = val;
}
pMin = min;
pMax = max;
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
SurpriseRemoval Sample
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#ifdef __GNUC__
# include <unistd.h>
# define Sleep(ms) usleep(ms*1000)
#endif
static int callbackCounter = 0;
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
int main(void)
{
GENAPIC_RESULT res;
size_t numDevices;
int loopCount;
int isGigECamera;
CHECK(res);
if ( 0 == numDevices )
{
fprintf( stderr, "No devices found.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
res =
PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM );
CHECK(res);
{
char buf[256];
size_t siz = sizeof(buf);
_Bool isReadable;
if ( isReadable )
{
CHECK(res);
printf("Using camera %s\n", buf);
}
}
CHECK(res);
{
CHECK(res);
isGigECamera = 0 == strcmp( devInfo.
DeviceClass,
"BaslerGigE" );
if ( isGigECamera )
{
setHeartbeatTimeout( hDev, 1000 );
}
}
loopCount = 20 * 4;
printf( "Please disconnect the device (timeout %d s) \n", loopCount / 4 );
do
{
if (--loopCount % 4 == 0)
{
printf(".");
fflush(stdout);
}
Sleep(250);
}
while (callbackCounter < 1 && loopCount >= 0);
if (callbackCounter < 1)
printf( "\nTimeout expired. Device hasn't been removed.\n" );
CHECK(res);
CHECK(res);
CHECK(res);
pressEnterToExit();
return EXIT_SUCCESS;
}
{
GENAPIC_RESULT res;
CHECK(res);
callbackCounter++;
}
{
GENAPIC_RESULT res;
int64_t oldTimeout;
CHECK(res);
{
return -1;
}
CHECK(res);
{
return -1;
}
CHECK(res);
CHECK(res);
return oldTimeout;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
size_t length;
errMsg = (char*) malloc( length );
fprintf( stderr, "%s (%#08x).\n", errMsg, (unsigned int) errc);
free( errMsg);
errMsg = (char*) malloc( length );
fprintf( stderr, "%s\n", errMsg);
free( errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
ActionCommands Sample
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0400
#endif
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#define MAX_NUM_DEVICES 4
#define GIGE_PACKET_SIZE 1500
#define GIGE_PROTOCOL_OVERHEAD 36
#define CHECK( errc ) if ( GENAPI_E_OK != errc ) printErrorAndExit( errc )
const uint32_t AllGroupMask = 0xffffffff;
void pressEnterToExit(void);
void printErrorAndExit( GENAPIC_RESULT errc );
int main(void)
{
GENAPIC_RESULT res;
size_t i;
size_t numDevicesEnumerated;
size_t numDevicesToUse;
_Bool isAvail;
size_t enumeratedDeviceIndex;
size_t deviceIndex;
uint32_t DeviceKey;
uint32_t GroupKey;
unsigned char *buffers[MAX_NUM_DEVICES];
srand((unsigned int)time(NULL));
DeviceKey = rand();
GroupKey = 0x24;
CHECK(res);
if ( numDevicesEnumerated == 0 )
{
fprintf( stdout, "No devices found!\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
deviceIndex = 0;
for (enumeratedDeviceIndex = 0; enumeratedDeviceIndex < numDevicesEnumerated; ++enumeratedDeviceIndex)
{
CHECK(res);
{
continue;
}
CHECK(res);
res =
PylonDeviceOpen( hDev[deviceIndex], PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM );
CHECK(res);
deviceInfos[deviceIndex] = di;
printf("Using camera '%s'\n", deviceInfos[deviceIndex].ModelName);
if (! isAvail)
{
fprintf(stderr, "Device doesn't support the Action Control");
pressEnterToExit();
exit( EXIT_SUCCESS );
}
res = PylonDeviceSetIntegerFeatureInt32( hDev[deviceIndex], "ActionSelector", 1 );
CHECK( res );
res = PylonDeviceSetIntegerFeatureInt32( hDev[deviceIndex], "ActionDeviceKey", DeviceKey );
CHECK( res );
res = PylonDeviceSetIntegerFeatureInt32( hDev[deviceIndex], "ActionGroupKey", GroupKey );
CHECK( res );
CHECK( res );
CHECK(res);
CHECK(res);
CHECK(res);
if ( ! isAvail )
{
fprintf(stderr, "Device doesn't support the Mono8 pixel format.\n");
pressEnterToExit();
exit (EXIT_SUCCESS);
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
++deviceIndex;
}
numDevicesToUse = deviceIndex;
if (numDevicesToUse == 0)
{
fprintf(stderr, "No suitable cameras found!\n");
pressEnterToExit();
exit(EXIT_SUCCESS);
}
if (numDevicesToUse < 2)
{
printf("WARNING: This sample works best with two or more GigE cameras supporting action commands.\n");
}
for (deviceIndex = 0; deviceIndex < numDevicesToUse; ++deviceIndex)
{
int32_t payloadSize;
res = PylonDeviceGetIntegerFeatureInt32( hDev[deviceIndex], "PayloadSize", &payloadSize );
CHECK(res);
CHECK(res);
if ( i < 1 )
{
fprintf( stderr, "The transport layer doesn't support image streams.\n");
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
buffers[deviceIndex] = (unsigned char *) malloc ( payloadSize );
if ( NULL == buffers[deviceIndex] )
{
fprintf( stderr, "Out of memory.\n" );
pressEnterToExit();
exit(EXIT_FAILURE);
}
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
}
for (deviceIndex = 0; deviceIndex < numDevicesToUse; ++deviceIndex)
{
{
break;
}
}
{
char subnet[ 32 ] = {'\0'};
size_t buflen = sizeof subnet;
CHECK( res );
CHECK( res );
CHECK( res );
for (deviceIndex = 0; deviceIndex < numDevicesToUse; ++deviceIndex)
{
_Bool isReady;
size_t woIndex = 0;
CHECK(res);
if ( !isReady )
{
fprintf(stderr, "Grab timeout occurred.\n");
break;
}
CHECK(res);
if ( !isReady )
{
fprintf(stderr, "Failed to retrieve a grab result\n");
break;
}
{
printf("Grabbed frame from camera %u into buffer.\n", (unsigned int) woIndex);
#ifdef GENAPIC_WIN_BUILD
if (woIndex <= 31)
{
res = PylonImageWindowDisplayImageGrabResult(woIndex, &grabResult);
CHECK(res);
}
#endif
}
{
fprintf( stderr, "Frame wasn't grabbed successfully. Error code = 0x%08X\n",
}
}
}
for (deviceIndex = 0; deviceIndex < numDevicesToUse; ++deviceIndex)
{
CHECK(res);
}
CHECK(res);
CHECK(res);
for (deviceIndex = 0; deviceIndex < numDevicesToUse; ++deviceIndex)
{
_Bool rdy;
CHECK(res);
do
{
CHECK(res);
} while ( rdy );
CHECK(res);
free( buffers[deviceIndex] );
CHECK(res);
CHECK(res);
CHECK(res);
CHECK(res);
}
pressEnterToExit();
return EXIT_SUCCESS;
}
void printErrorAndExit( GENAPIC_RESULT errc )
{
char *errMsg;
char *errDetail;
size_t length = 0;
errMsg = (char*) malloc( length );
length = 0;
errDetail = (char*) malloc( length );
fprintf( stderr, "%s (%#08x).\n%s\n", errMsg, (unsigned int) errc, errDetail);
free(errDetail);
free(errMsg);
pressEnterToExit();
exit(EXIT_FAILURE);
}
void pressEnterToExit(void)
{
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}