提供一个linux串口程序

    xiaoxiao2021-04-13  34

    #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; }
    转载请注明原文地址: https://ju.6miu.com/read-669420.html

    最新回复(0)