blob: bd71163c2514b625d90ba8ac0c67b94d133bc7c7 (
plain)
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
|
public static int main(string[] args) {
if(args.length < 2) {
stderr.printf("%s <device>\n", args[0]);
return 1;
}
var s = new Serial(args[1], 19200, 7, 1);
char[] detected = {};
while(true) {
uint8 buf[64];
int size = (int) Posix.read(s.fd, buf, 64);
for(int i = 0; i < size; i++)
if(buf[i] != '\r' && buf[i] != '\n') {
detected += (char) buf[i];
} else {
if(detected.length > 0) {
detected += '\0';
interpret(detected);
}
detected = {};
}
}
}
public static void interpret(char[] data) {
stdout.printf("%s\n", (string) data);
}
|