-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_form_data.cpp
61 lines (41 loc) · 931 Bytes
/
serial_form_data.cpp
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
#include "serial_form_data.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <pthread.h>
#include <unistd.h>
#include <termios.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include "set_serial.h"
using namespace std;
int sendPacket(int fd,char *data,int size){
write(fd,"@",1);
write(fd,data,size);
write(fd,"$",1);
return 1;
}
int sendPacket_zh(int fd,const char *data,int size){
write(fd,"$",1);
write(fd,data,size);
write(fd,"%",1);
return 1;
}
int receivePacket(int fd,char *data, int size){
fcntl(fd,F_SETFL,FNDELAY);
while(1){
int re=read(fd,data,size);
if(re<0){
perror("receivePacket is error!");
}else if(re==0){
return 1;
}else{
//目前
}
}
fcntl(fd, F_SETFL, FNDELAY);
return 1;
}