How to make a program against ticables library


  
You will find in the test folder of the libary source archive a test/example program which uses this lib.
Below is listed a light version (error management has been removed) of this program to make it clearer:
# include <tilp/ticables.h>

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

ticables_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 *handle;
int err, i;
uint8_t buf[4];

// init lib
ticables_library_init();

// set cable
handle = ticables_handle_new(CABLE_SLV, PORT_1);
if(handle == NULL)
return -1;

ticables_options_set_timeout(handle, 15);
ticables_options_set_delay(handle, 10);
ticables_handle_show(handle);

// open cable
err = ticables_cable_open(handle);
if(err) print_lc_error(err);
if(err) return -1;

// do a simple test with a TI89/92+ calculator
buf[0] = 0x08; buf[1] = 0x68; buf[2] = 0x00; buf[3] = 0x00; // RDY
err = ticables_cable_send(handle, buf, 4);
if(err) print_lc_error(err);

// display answer
memset(buf, 0xff, 4);
err = ticables_cable_recv(handle, buf, 4);
if(err) print_lc_error(err);

for(i = 0; i < 4; i++)
printf("%02x ", buf[i]);
printf("\n");

// close cable
ticables_cable_close(handle);

// release handle
ticables_handle_del(handle);

// exit lib
ticables_library_exit();

return 0;
}

That's all !

Return to the main index