Header Header

Examples
[Device handling]

Table of contents

gxdevices01 - List devices example

Shows the way of listing the GX system devices.

When specifying the needed include files we have included the gxsdldr.c loader file directly:

#include "gxsd.h"
#include "gxsdldr.c"

Defining the number of devices limit:

#define MAXDEVICES  100     /* Maximal number of devices */

Starting the main function and defining the needed variables:

/*
 * Main function.
 */
int main(void) {
    int st, i;
    char errbuf[256];
    int errcode;
    struct GX_DEVICE_INFOA *devices;
    char type[sizeof(devices->type)+1];
    char devname[sizeof(devices->devname)+1];

Allocating the buffer for the device list:

    /* Allocates the array for information of devices */
    int ndevices = MAXDEVICES;
    devices = (struct GX_DEVICE_INFOA *)malloc(
                sizeof(struct GX_DEVICE_INFOA)*MAXDEVICES);
    if(!devices) {
        fprintf(stderr, "** Out of memory\n");
        return 1;
    }

Getting the device list:

    /* Calls the listdevices function */
    st = gx_listdevicesa(&ndevices, devices, 0, 0);

If an error occured, then the return value is 0. In this case displaying the error code and message and ending the sample program:

    if(!st) {
        free(devices);
        errcode = gx_geterrora(0, errbuf, sizeof(errbuf));
        errbuf[sizeof(errbuf)-1] = 0;
        fprintf(stderr, "** GX Error: (%x) %s\n", errcode, errbuf);
        return 1;
    }

If no devices found then displaying message and ending the sample program:

    /* Displays devices */
    if(ndevices == 0) {
        free(devices);
        printf("No GX devices.\n");
        return 0;
    }

If one or more devices found then displaying general informations and ending the sample program:

    printf("GX devices in the system:\n");

    type[sizeof(type)-1] = 0;
    devname[sizeof(devname)-1] = 0;

    for(i = 0; i < ndevices; i++) {
        strncpy(type, devices[i].type, sizeof(type)-1);
        strncpy(devname, devices[i].devname, sizeof(devname)-1);
        
        printf("%3i. Name: %s, Type: %s, Serial: %08x, Prio: %i\n",
                i+1, devname, type, devices[i].serial, devices[i].priority);
    }
    printf("%i devices found.\n", ndevices);

    /* Frees the array */
    free(devices);

    return 0;
}

gxdevices02 - System information example

Shows the way of getting system information about the GX devices.

When specifying the needed include files we have included the gxsdldr.c loader file directly:

#include "gxsd.h"
#include "gxsdldr.c"

Starting the main function and defining the needed variables:

/*
 * Main function.
 */
int main(void) {
    int st;
    char errbuf[256];
    int errcode;
    /* Define a GX_SYSTEM_INFO structure to store the informations */
    GX_SYSTEM_INFO gxinfo;

Setting the size member properly:

    /* Set the size of the structure. We will get maximum size number of bytes. */
    memset(&gxinfo,0,sizeof(GX_SYSTEM_INFO));
    gxinfo.size = sizeof(GX_SYSTEM_INFO);

Getting system informations:

    /* Calls the getsysteminfo function */
    st = gx_getsysteminfo(&gxinfo);
    if(!st) {
        errcode = gx_geterrora(0, errbuf, sizeof(errbuf));
        errbuf[sizeof(errbuf)-1] = 0;
        fprintf(stderr, "** GX Error: (%x) %s\n", errcode, errbuf);
        return 1;
    }

Displaying the result and ending program:

    /* Displays the informations */
    printf("GX licences in the system:\n");
    printf("Freeflow licences:          %i\n",gxinfo.cm_ff);
    printf("Parking licences:           %i\n",gxinfo.cm_park);
    printf("Container licences:         %i\n",gxinfo.cm_accr);
    printf("Parking Lane licences:      %i\n",gxinfo.cm_pl);
    printf("Face ident licences:        %i\n",gxinfo.cm_face);
    printf("Passport Reader licences:   %i\n",gxinfo.pr);
    return 0;
}


Generated  for GX
(c) Adaptive Recognition