How to make a program against ticables library


  
You will find in the test folder of the library source archive a test/example program which uses this lib.
Below is a light version (most error management has been removed) of this program to make it clearer:
# include <stdio.h>
# include <string.h>
# include <glib.h>
# include <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);

  g_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 !

NOTE: for this example to work, you probably have to add compiler options related to the include path and library path, e.g.
gcc -I/usr/include/tilp2 -Os -g -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -Wall -W ticables.c -o ticables -lglib-2.0 -lticables2
or better
gcc -Os -g -Wall -W `pkg-config --cflags --libs ticables2` ticables.c -o ticables

Return to the main index