1

I am trying to setup a serial port on centos but can't get it to work. this is the code that I'm having trouble with.

tcgetattr(idComDev[i], &options); // get current settings

    printw("default baudrate is %d ", cfgetispeed(&options));

    cfsetispeed(&options, B115200); // set baud rate
    cfsetospeed(&options, B115200); // set baud rate

tcsetattr(idComDev[i], TCSANOW, &options);// save the settings

    printw("Seg %d = COM%hd at %d Baudrate",i,CommNo[i], cfgetispeed(&options));

The out put from this is: Default baud rate is 4098 Seg0 = COM1 at 4098 Baudrate.

Why is it at 4098? I can't find this baudrate anywhere.

If I set the baud rate to 1800 it says it is at 10. If I set it to 9600 it says it is at 13.

I have done some research and found that suposidly the hardware cannot support this high a baud rate but I have a Java program on the same computer commutating with the same device that I am trying to connect to. So I know this cannot be that case.

Does anyone know what is going on and how to fix it?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Skeith
  • 2,512
  • 5
  • 35
  • 57
  • @phresnel it is the baud rate, if you look here http://www.easysw.com/~mike/serial/serial.html then you will see that all the baudrates are preceded with B when using termios – Skeith Oct 04 '11 at 09:14
  • I see, I had the fear that you are possibly using a compiler extension that allows for binary literals. – Sebastian Mach Oct 04 '11 at 09:30

1 Answers1

3

B115200 is a macro, and expands to 0x1002. That's a combination of two bits: 0x1000 signals that it's a non-standard rate (as you discovered) and 0x2 is the second non-standard rate (B57600 is 0x1001, the first non-standard rate).

MSalters
  • 173,980
  • 10
  • 155
  • 350