if (m_BaudRates[i] == speed) {
// found the baudrate from the table
// in case custom divisor was in use, turn it off first
serial_struct ss = new serial_struct();
r = ioctl(fd, TIOCGSERIAL, ss);
if (r != 0) {
// not every driver supports TIOCGSERIAL, so if it fails, just ignore it
// (see also issues #12 and #16)
if (errno() != EINVAL && errno() != ENOTSUP)
return r;
} else {
ss.flags &= ~ASYNC_SPD_MASK;
r = ioctl(fd, TIOCSSERIAL, ss);
if (r != 0) {
// not every driver supports TIOCSSERIAL, so if it fails, just ignore it
// (see also issues #12 and #16)
if (errno() != EINVAL && errno() != ENOTSUP)
return r;
}
}
// now set the speed with the constant from the table
c = m_BaudRates[i + 1];
if ((r = JTermios.cfsetispeed(termios, c)) != 0)
return r;
if ((r = JTermios.cfsetospeed(termios, c)) != 0)
return r;
if ((r = JTermios.tcsetattr(fd, TCSANOW, termios)) != 0)
return r;
return 0;
}
}
// baudrate not defined in the table, try custom divisor approach
// configure port to use custom speed instead of 38400
serial_struct ss = new serial_struct();
if ((r = ioctl(fd, TIOCGSERIAL, ss)) != 0)
return r;
ss.flags = (ss.flags & ~ASYNC_SPD_MASK) | ASYNC_SPD_CUST;
if (speed == 0) {