By default what is the baud rate during serial communication. That is if a write a program where I do not mention any baud rate, then what baud rate will be taken into account?
If on a POSIX system:
open()
. tcgetattr()
to initialise a struct termios
. struct termios
from 2. to cfgetispeed()
/ cfgetospeed()
to get the port's current inbound/outbound baud rate. Example:
#include <termios.h>
#include <unistd.h>
[...]
struct termios t = {0};
speed_t baudrate_in = 0;
speed_t baudrate_out = 0;
int fd = open("/dev/ttyS0", O_RDWR);
if (-1 == fd)
{
perror("open() failed");
exit(1);
}
if (-1 == tcgetattr(fd, &t))
{
perror("tcgetattr() failed");
exit(1);
}
baudrate_in = cfgetispeed(&t);
baudrate_out = cfgetospeed(&t);
您可以使用setserial找出http://linux.die.net/man/8/setserial
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.