You can use ioctl and termios to directly control the baud rate and serial port parameters. Its not terribly difficult.
If you only need a simple serial port and do not need the asynchronous IO components you can try: https://github.com/wjwwood/serial its a library a friend of mine wrote for some of his projects. Be sure to use the boostless
branch. I know the OS X drivers support custom baud rates, I have tested those, and custom baud rates should work in Linux as well. It doesn't currently support Windows, so if you need Windows support, its won't be much help at the moment.
If you only want to use ioctl and termios you can do:
#define IOSSIOSPEED _IOW('T', 2, speed_t)
int new_baud = static_cast<int> (baudrate_);
ioctl (fd_, IOSSIOSPEED, &new_baud, 1);
And it will let you set the baud rate to any value in OS X, but that is OS specific. for Linux you need to do:
struct serial_struct ser;
ioctl (fd_, TIOCGSERIAL, &ser);
// set custom divisor
ser.custom_divisor = ser.baud_base / baudrate_;
// update flags
ser.flags &= ~ASYNC_SPD_MASK;
ser.flags |= ASYNC_SPD_CUST;
if (ioctl (fd_, TIOCSSERIAL, ser) < 0)
{
// error
}
For any other OS your gonna have to go read some man pages or it might not even work at all, its very OS dependent.