3

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

dsolimano
  • 8,870
  • 3
  • 48
  • 63
M B
  • 41
  • 5

1 Answers1

1

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.

mathematician1975
  • 21,161
  • 6
  • 59
  • 101
  • The same page also cites `speeds beyond those defined in POSIX.1 (57600 and above)`. Any idea whether these extended rates are ubiquitous or if other names or numbers are used on other POSIX implementations? – doynax Dec 26 '13 at 22:33
  • @doynax I am afraid I do not know. All I know is that the code above works fine in my applications when I need baudrates of 57.6k and above. – mathematician1975 Dec 26 '13 at 22:40
  • I regularly use 115200 bps on serial applications in C. I've not seen any recent version of Linux that won't go to at least 230400. On my Ubuntu 12.04 (X86_64), B57600, B115200, etc. are all defined in x86_64-linux-gnu/bits/termios.h. I have no idea why the defines on yuor system are limited. – DoxyLover Dec 26 '13 at 23:17
  • I was looking at the header files incorrectly. I also was able to set the baud rate to 230400 manually using basic AT commands using the Xbee interface. By default, 115200 is the highest baud rate in the preset list for the Xbee I was using, so I had to manually define the custom baud rate. – M B Jan 06 '14 at 01:56