lock the device, fix baudrate setting
This commit is contained in:
@@ -568,23 +568,28 @@ int openSerial(std::string port) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// backup terminal settings
|
if (flock(fd, LOCK_EX|LOCK_NB)) {
|
||||||
if (tcgetattr(fd, &termios_original)!=0) {
|
close(fd);
|
||||||
memset(&termios_original, 0, sizeof(termios_original));
|
std::cerr<<"unable to lock "<<port<<std::endl;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// backup terminal settings
|
||||||
|
tcgetattr(fd, &termios_original);
|
||||||
|
|
||||||
// configure terminal settings
|
// configure terminal settings
|
||||||
struct termios termios = termios_original;
|
struct termios termios;
|
||||||
|
memset(&termios, 0, sizeof(termios));
|
||||||
|
|
||||||
if (cfsetspeed(&termios, BAUDRATE)!=0) {
|
if (cfsetspeed(&termios, BAUDRATE)!=0) {
|
||||||
std::cerr<<"unable to set speed "<<std::endl;
|
std::cerr<<"unable to set speed "<<std::endl;
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
termios.c_iflag = 0;//IGNPAR;//IGNBRK|IGNPAR|IGNCR;
|
termios.c_iflag |= 0;//IGNPAR;//IGNBRK|IGNPAR|IGNCR;
|
||||||
termios.c_oflag = 0;
|
termios.c_oflag |= 0;
|
||||||
termios.c_cflag = CS8 | CREAD | CLOCAL;
|
termios.c_cflag |= CS8 | CREAD | CLOCAL;
|
||||||
termios.c_lflag = 0;
|
termios.c_lflag |= 0;
|
||||||
termios.c_cc[VMIN] = 1;
|
termios.c_cc[VMIN] = 1;
|
||||||
termios.c_cc[VTIME] = 0;
|
termios.c_cc[VTIME] = 0;
|
||||||
if (tcsetattr(fd, TCSANOW, &termios)!=0) {
|
if (tcsetattr(fd, TCSANOW, &termios)!=0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user