-
Notifications
You must be signed in to change notification settings - Fork 20
/
test.c
68 lines (44 loc) · 1013 Bytes
/
test.c
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
/* Example application of Columbo Simple Serial Library
* Copyright 2003 Marcin Siennicki <[email protected]>
* see COPYING file for details */
#include <stdio.h>
#include <unistd.h>
#include "cssl.h"
/* if it is time to finish */
static int finished=0;
/* example callback, it gets its id, buffer, and buffer length */
static void callback(int id,
uint8_t *buf,
int length)
{
int i;
for(i=0;i<length;i++) {
switch (buf[i]) {
case 0x04: /* Ctrl-D */
finished=1;
return;
case '\r': /* replace \r with \n */
buf[i]='\n';
}
putchar(buf[i]);
}
fflush(stdout);
}
int main()
{
cssl_t *serial;
cssl_start();
serial=cssl_open("/dev/ttyS0",callback,0,
19200,8,0,1);
if (!serial) {
printf("%s\n",cssl_geterrormsg());
return -1;
}
cssl_putstring(serial,"Type some data, ^D finishes.");
while (!finished)
pause();
printf("\n^D - we exit\n");
cssl_close(serial);
cssl_stop();
return 0;
}