Serial port won't accept baud rate
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("S开发者_开发百科eg %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?
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).
精彩评论