1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Making programs against the TiCables library</title>
<style type="TEXT/CSS">
<!--
BODY {FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #FFFFFF; FONT-SIZE: 10pt}
TD {FONT-SIZE: 10pt}
H1 {FONT-SIZE: 18pt}
H3 {FONT-SIZE: 13pt}
PRE {FONT-FAMILY: Courier New; FONT-SIZE: 9pt}
CODE {FONT-FAMILY: Courier New; FONT-SIZE: 9pt}
-->
</style>
</head>
<body alink="#ff0000" bgcolor="#ffffff" text="#000000" vlink="#0000ff">
<h1> How to make a program against ticables library </h1>
<hr>
<pre> <em> </em></pre>
You will find in the <i>test</i> folder of the library source archive a
test/example program which uses this lib.<br>
Below is a light version (most error management has been removed) of this
program to make it clearer:
<pre># 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;
}
</pre>
That's all !<br><br>
<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.
<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>
or better
<pre>gcc -Os -g -Wall -W `pkg-config --cflags --libs ticables2` ticables.c -o ticables</pre>
<h3><a href="index.html">Return to the main index</a> </h3>
</body>
</html>
|