M B
M B

Reputation: 41

Getting faster baud rates with termios

Using Non-Canonical Input Processing, I am reading in the serial data being sent to a Xbee S2B Pro (ZB) using a Xbee Interface XBIB-R-Dev with a "DB9-to-USB" cable. I am using some of the example code from http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html. The project I am doing this in is strictly c code not C++.

When reading info on termios.h on my laptop running Ubuntu Linux 12.04 LTS (32-bit - latest updates), I see that only the highest baud rate available is just 38400 BAUD (B38400 constant). Simply swapping the "#define BAUDRATE" of B38400 for a higher baudrate B57600 or higher will not work since it isn't defined on the header files. I'll get an error say that B57600 is not defined.

My question is is there a better way or a way to get around this (using termios) so I can read data at a faster rate as the Xbee S2B Pro is able to push up to 1 Mbps serial data rate (specification as listed on digi.com site).

Thank you for your help.

Mike

Upvotes: 3

Views: 2396

Answers (1)

mathematician1975
mathematician1975

Reputation: 21351

Can you not use the following (using the struct termios newtio; as in the example within your link in the question)

 cfsetispeed(&newtio, B57600);
 cfsetospeed(&newtio, B57600);

or just

  cfsetspeed(&options, B57600);

from the termios man pages, it indicates that the speed_t parameter passed to these functions can take values as high as B230400. I also develop serial port reading applications on 12.04 Ubuntu and the above function works perfectly well for me.

Upvotes: 1

Related Questions