这是我的程序代码
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>
#define FALSE -1
#define TRUE 0
int openDevice(char *dev){
int fd = open(dev, O_RDWR);
if(fd == FALSE){
perror(“CAN NOT OPEN SERIAL PORT”);
return FALSE;
}
else{
return fd;
}
}
int main(){
int fd;
int nread;
char buff[1024];
char *dev = “/dev/ser1”;
bzero(buff,1024);
fd = openDevice(dev);
while(1){
while((nread=read(fd, buff, 1024))>0){
printf("\nLength: %d\n", nread);
buff[nread+1] = ‘\0’;
printf("\n%s\n", buff);
}
}
close(fd);
exit(0);
}
运行的时候只能读到底一个字节,要第二次运行才会把所有的数据读出来,请问这是哪里出了问题?
小弟刚开始学C,请多多指教,谢谢