程序代码已经在Linux系统上正确运行
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h> //set baud rate
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
//#define rec_buf_wait_2s 2
#define buffLen 1024
#define rcvTimeOut 2
/*******************************************************/
/**下面的函数暂时并没什么意思,完全可以忽略**/
int read_data_tty(int fd, char *rec_buf, int rec_wait) {
int retval;
fd_set rfds;
struct timeval tv;
int ret, pos;
tv.tv_sec = rec_wait;
tv.tv_usec = 0;
pos = 0;
while (1) {
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
retval = select(fd + 1, &rfds, NULL, NULL, &tv);
if (retval == -1) {
perror("select()");
break;
}
else if (retval) {
ret = read(fd, rec_buf + pos, 2048);
pos += ret;
if (rec_buf[pos - 2] == '\r' && rec_buf[pos - 1] == '\n') {
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
retval = select(fd + 1, &rfds, NULL, NULL, &tv);
if (!retval) {
break;
}
}
}
else {
break;
}
}
return 1;
}
int device_485_receive(int fd) {
int ret;
char rec_buf[1024];
int i;
char send_buf[] = { "02030202f925" };
for (i = 0; i<10; i++) {
/*ret = write(fd, send_buf, strlen(send_buf));
if


369

被折叠的 条评论
为什么被折叠?



