How to make a program against the libcalcprotocols library


  
You will find in the test folder of the library source archive a test/example program which uses this library.
Below is listed a light version (error management has been removed and update functions are set to void) of this program to make it clearer:

#include <calccables.h>
#include <calcfiles.h>
#include <calcprotocols.h>

static void print_lc_error(int errnum)
{
    char *msg;

    calccables_error_get(errnum, &msg);
    fprintf(stderr, "Link cable error (code %i)...\n<<%s>>\n",
        errnum, msg);

    free(msg);

}

int main(int argc, char **argv)
{
    CableHandle* cable;
    CalcHandle* calc;
    int err;

    // init libs
    calccables_library_init();
    calcprotocols_library_init();

    // set cable
    cable = calccables_handle_new(CABLE_BLK, PORT_2);
    if(cable == NULL)
        return -1;

    // set calc
    calc = calcprotocols_handle_new(CALC_TI83);
    if(calc == NULL)
        return -1;

    // attach cable to calc (and open cable)
    err = calcprotocols_cable_attach(calc, cable);

    err = calcprotocols_calc_isready(h);
    if(err)
        print_lc_error(err);
    printf("Hand-held is %sready !\n", err ? "not " : "");

    // detach cable (made by handle_del, too)
    err = calcprotocols_cable_detach(calc);

    // remove calc & cable
    calcprotocols_handle_del(calc);
    calccables_handle_del(cable);

  return 0;
}

That's all !

Return to the main index