Skip to content

Instantly share code, notes, and snippets.

@dfirfpi
Created November 16, 2016 21:19
Show Gist options
  • Save dfirfpi/496406d111490ced54f9afc09eeeb839 to your computer and use it in GitHub Desktop.
Save dfirfpi/496406d111490ced54f9afc09eeeb839 to your computer and use it in GitHub Desktop.
Baud Rate Detector
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
// Author: clacke
// Ref: http://unix.stackexchange.com/questions/72979/how-does-cat-know-the-baud-rate-of-the-serial-port
// do a lookup for the value returned in termbits.h
int main() {
struct termios tios;
tcgetattr(0, &tios);
speed_t ispeed = cfgetispeed(&tios);
speed_t ospeed = cfgetospeed(&tios);
printf("baud rate in: 0%x\n", ispeed);
printf("baud rate out: 0%x\n", ospeed);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment