| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Making programs against the TiCables library</title> |
| 5 | <style type="TEXT/CSS"> |
| 6 | <!-- |
| 7 | BODY {FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #FFFFFF; FONT-SIZE: 10pt} |
| 8 | TD {FONT-SIZE: 10pt} |
| 9 | H1 {FONT-SIZE: 18pt} |
| 10 | H3 {FONT-SIZE: 13pt} |
| 11 | PRE {FONT-FAMILY: Courier New; FONT-SIZE: 9pt} |
| 12 | CODE {FONT-FAMILY: Courier New; FONT-SIZE: 9pt} |
| 13 | --> |
| 14 | </style> |
| 15 | </head> |
| 16 | <body alink="#ff0000" bgcolor="#ffffff" text="#000000" vlink="#0000ff"> |
| 17 | <h1> How to make a program against ticables library </h1> |
| 18 | <hr> |
| 19 | <pre> <em> </em></pre> |
| 20 | You will find in the <i>test</i> folder of the library source archive a |
| 21 | test/example program which uses this lib.<br> |
| 22 | Below is a light version (most error management has been removed) of this |
| 23 | program to make it clearer: |
| 24 | <pre># include <stdio.h> |
| 25 | # include <string.h> |
| 26 | # include <glib.h> |
| 27 | # include <ticables.h> |
| 28 | |
| 29 | static void print_lc_error(int errnum) |
| 30 | { |
| 31 | char *msg; |
| 32 | |
| 33 | ticables_error_get(errnum, &msg); |
| 34 | fprintf(stderr, "Link cable error (code %i)...\n<<%s>>\n", |
| 35 | errnum, msg); |
| 36 | |
| 37 | g_free(msg); |
| 38 | } |
| 39 | |
| 40 | int main(int argc, char **argv) |
| 41 | { |
| 42 | CableHandle *handle; |
| 43 | int err, i; |
| 44 | uint8_t buf[4]; |
| 45 | |
| 46 | // init lib |
| 47 | ticables_library_init(); |
| 48 | |
| 49 | // set cable |
| 50 | handle = ticables_handle_new(CABLE_SLV, PORT_1); |
| 51 | if(handle == NULL) |
| 52 | return -1; |
| 53 | |
| 54 | ticables_options_set_timeout(handle, 15); |
| 55 | ticables_options_set_delay(handle, 10); |
| 56 | ticables_handle_show(handle); |
| 57 | |
| 58 | // open cable |
| 59 | err = ticables_cable_open(handle); |
| 60 | if(err) print_lc_error(err); |
| 61 | if(err) return -1; |
| 62 | |
| 63 | // do a simple test with a TI89/92+ calculator |
| 64 | buf[0] = 0x08; buf[1] = 0x68; buf[2] = 0x00; buf[3] = 0x00; // RDY |
| 65 | err = ticables_cable_send(handle, buf, 4); |
| 66 | if(err) print_lc_error(err); |
| 67 | |
| 68 | // display answer |
| 69 | memset(buf, 0xff, 4); |
| 70 | err = ticables_cable_recv(handle, buf, 4); |
| 71 | if(err) print_lc_error(err); |
| 72 | |
| 73 | for(i = 0; i < 4; i++) |
| 74 | printf("%02x ", buf[i]); |
| 75 | printf("\n"); |
| 76 | |
| 77 | // close cable |
| 78 | ticables_cable_close(handle); |
| 79 | |
| 80 | // release handle |
| 81 | ticables_handle_del(handle); |
| 82 | |
| 83 | // exit lib |
| 84 | ticables_library_exit(); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | </pre> |
| 89 | That's all !<br><br> |
| 90 | <strong>NOTE</strong>: for this example to work, you probably have to add compiler options related to the include path and library path, e.g. |
| 91 | <pre>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</pre> |
| 92 | or better |
| 93 | <pre>gcc -Os -g -Wall -W `pkg-config --cflags --libs ticables2` ticables.c -o ticables</pre> |
| 94 | <h3><a href="index.html">Return to the main index</a> </h3> |
| 95 | </body> |
| 96 | </html> |