-
Notifications
You must be signed in to change notification settings - Fork 11
/
example.c
97 lines (73 loc) · 1.57 KB
/
example.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
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
#include <stdio.h>
#include "serialib.h"
/*
typedef struct str{
char *name;
int id;
} sss;
void sss_init(sss **s, char* name, int id)
{
*s = (sss *) malloc(sizeof(sss));
(*s)->name = name;
(*s)->id = id;
}
*/
int main(void)
{
serial *s;
if (serial_open(&s, "/dev/ttyUSB1", 115200) == 0){
printf("Port opened.\n");
} else {
printf("Problem with port opening\n");
return -1;
}
printf("%s -> %d\n", s->port, s->fd);
system("sleep 3");
char buffer[128];
serial_read(s, buffer, '\n', 128);
printf("%s %d\n", buffer, strlen(buffer));
serial_read(s, buffer, '\n', 128);
printf("%s %d\n", buffer, strlen(buffer));
serial_read(s, buffer, '\n', 128);
printf("%s %d\n", buffer, strlen(buffer));
//while (1) {
/*
serial_read(s, buffer, '\n', 128);
printf("%s", buffer);
timer *t;
timer_init(&t);
serial_read(s, buffer, '\n', 128);
printf("%s", buffer);
serial_write(s, "ls\r\n");
sleep(1);
printf("\nt=%d\n", timer_elapsed(t));
//system("sleep 1");
serial_read(s, buffer, '\n', 128);
printf("%s", buffer);
serial_read(s, buffer, '\n', 128);
printf("%s", buffer);
serial_read(s, buffer, '\n', 128);
printf("%s", buffer);
//}
*/
/*
serial_read(s, buffer, '\n', 128);
printf("-> %s\n", buffer);
serial_read(s, buffer, '\n', 128);
printf("-> %s\n", buffer);
serial_read(s, buffer, '\n', 128);
printf("-> %s\n", buffer);
*/
/*
char p;
int i;
i = serial_read_char(s, &p);
printf("-> %c %d ", p, i);
*/
/*
sss *es;
//es = (sss *) malloc(sizeof(sss));
sss_init(&es, "ahoj", 5);
printf("%s, %d\n",es->name, es->id);
*/
}