提供一个linux串口程序

来源:互联网 发布:linux 命令 竖线 编辑:程序博客网 时间:2024/06/05 05:03
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>


int main(void)
{
int fd;
struct termios opts;
int ret;
char *buffer = "Hello";
fd = open("/dev/ttySAC3", O_RDWR);
if (fd < 0)
{
printf("open ttys3");
return 1;
}
printf("tty3 open ok!");
tcgetattr(fd, &opts);


opts.c_cflag |= CLOCAL;
opts.c_cflag &= ~CRTSCTS;


opts.c_cflag &= ~CSIZE;
opts.c_cflag |= CS8;
opts.c_cflag &= ~CSTOPB;


opts.c_cflag &= ~PARENB;


cfsetispeed(&opts, B115200);
cfsetospeed(&opts, B115200);


tcsetattr(fd, TCSANOW, &opts);


write(fd, buffer, 5);


close(fd);
return 0;
}
0 0
原创粉丝点击