| 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 the ticalcs library </h1> |
| 18 | <hr> |
| 19 | <pre> <em> </em></pre> |
| 20 | You will find in the <i>test</i> folder of the library source archive |
| 21 | a test/example program which uses this library.<br> |
| 22 | Below is a light version (most error management has been removed and |
| 23 | update functions are set to void) of this program to make it clearer:<br> |
| 24 | <br> |
| 25 | <pre>#include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <glib.h> |
| 28 | #include <ticables.h> |
| 29 | #include <tifiles.h> |
| 30 | #include <ticalcs.h> |
| 31 | |
| 32 | static void print_lc_error(int errnum) |
| 33 | { |
| 34 | char *msg; |
| 35 | |
| 36 | ticables_error_get(errnum, &msg); |
| 37 | fprintf(stderr, "Link cable error (code %i)...\n<<%s>>\n", errnum, msg); |
| 38 | |
| 39 | g_free(msg); |
| 40 | } |
| 41 | |
| 42 | int main(int argc, char **argv) |
| 43 | { |
| 44 | CableHandle* cable; |
| 45 | CalcHandle* calc; |
| 46 | int err; |
| 47 | |
| 48 | // init libs |
| 49 | ticables_library_init(); |
| 50 | ticalcs_library_init(); |
| 51 | |
| 52 | // set cable |
| 53 | cable = ticables_handle_new(CABLE_BLK, PORT_2); |
| 54 | if(cable == NULL) |
| 55 | return -1; |
| 56 | |
| 57 | // set calc |
| 58 | calc = ticalcs_handle_new(CALC_TI83); |
| 59 | if(calc == NULL) |
| 60 | return -1; |
| 61 | |
| 62 | // attach cable to calc (and open cable) |
| 63 | err = ticalcs_cable_attach(calc, cable); |
| 64 | |
| 65 | err = ticalcs_calc_isready(h); |
| 66 | if(err) |
| 67 | print_lc_error(err); |
| 68 | printf("Hand-held is %sready !\n", err ? "not " : ""); |
| 69 | |
| 70 | // detach cable (made by handle_del, too) |
| 71 | err = ticalcs_cable_detach(calc); |
| 72 | |
| 73 | // remove calc & cable |
| 74 | ticalcs_handle_del(calc); |
| 75 | ticables_handle_del(cable); |
| 76 | |
| 77 | return 0; |
| 78 | }</pre> |
| 79 | That's all !<br><br> |
| 80 | <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. |
| 81 | <pre>gcc -I/usr/include/tilp2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -Os -g -Wall -W <...>.c -o <...> -lglib-2.0 -lticalcs2</pre> |
| 82 | or better |
| 83 | <pre>gcc -Os -g -Wall -W `pkg-config --cflags --libs ticalcs2` ticalcs.c -o ticalcs</pre> |
| 84 | <h3><a href="index.html">Return to the main index</a> </h3> |
| 85 | </body> |
| 86 | </html> |