int main() { int fd; int nread; char command[256]; char buf; int nset; fd = open("/dev/ttySAC1", O_RDONLY); if (fd == -1) { printf("open failed\n"); exit(1); } nset = set_opt(fd, 4800, 8, 'N', 1); if (nset == -1) { printf("set_opt failed\n"); exit(1); } memset(command, '\0', 256); while (1) { nread = read(fd, &buf, 1); if (nread > 0) { concat_command(command, buf); if (buf == 'q') break; } } close(fd); return (0); }
int main(void) { int fd1,fd2,nset1,nset2,nread; char buf; char buff[256]; fd2 = open("/dev/ttySAC1", O_RDONLY); // fd2 = open( "/home/junhan/Desktop/part4/test1", O_RDWR); //for ok6410-B GPS module if (fd2 == -1) exit(1); nset2 = set_opt(fd2, 4800, 8, 'N', 1); if (nset2 == -1) exit(1); //使用的时候取消注释 memset(buff, '\0', 256); while(1) { nread = read(fd2, &buf, 1); if(nread > 0){ concat_command(buff,buf); if(buf == 'q') break; } } close(fd2); return 0; }