堕落~到~人间
获得 0 次赞
帮助过1人
int open_port(char *port_device,FILE *write_fp) { int fd; fd = open(port_device, O_RDWR); if (fd == -1) { fprintf(write_fp,"open_port: Unable to open %d ",fd); } return (fd); } int main(){ struct termios options; char buf[1024]; FILE *write_fp; write_fp = fopen("gpsInfo11.txt","w"); int fd=open_port("/dev/1-1",write_fp); fprintf(write_fp,"fd===%d ",fd); if(fd==-1){ close(fd); return -1; } tcgetattr(fd,&options); cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); ssize_t nread; while(1){ nread =read(fd, buf, sizeof(buf)); fprintf(write_fp,"n==%d ",nread); fprintf(write_fp,"buf==%s ",buf); delay(500); } fclose(write_fp); close(fd); return 0; }