dev_fd = open(dev, O_RDWR | O_NOCTTY);
if (dev_fd <0 ) {
perror(dev);
return 0;
//0 -- Serial open failed.
}
tcgetattr(dev_fd, &oldtio);
/* save current DEVICE settings */
bzero(&newtio, sizeof(newtio));
//newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | IGNBRK;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 1;
tcflush(dev_fd, TCIFLUSH);
if (tcsetattr(dev_fd, TCSANOW, &newtio) == -1) {
// fprintf(stderr, "sorry,tcsetattr error!/n");
return -1;
//-1 set attr failed.
}
tcdrain(dev_fd);