惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
腾讯CDC
博客园 - Franky
Engineering at Meta
Engineering at Meta
C
Check Point Blog
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
S
SegmentFault 最新的问题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学

博客园 - ahuo

dts删除节点方法 Ubuntu ap桥接到有线 MQTT 3.1.1 客户端如何使用共享订阅 mdns shell Ubuntu笔记本盖上不休眠 win10+ubuntu24 双系统 http代理-docker拉取 Ubuntu20 IP显示登录界面 串口启用密码或者不用密码的配置方法(/etc/inittab) mkpasswd 万用表测量MCU的GPIO trackerslist Linux串口通讯监听-jpnevulator crop_yuv420_sp NV12数据转OpenCV的Mat Ubuntu 22 root桌面登录 Ubuntu22 向日葵黑屏 vscode ssh key登录 Samba 访问失败,提示“你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问。” Linux NAT转发
Linux下串口的RTS控制
ahuo · 2025-05-12 · via 博客园 - ahuo
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>

void set_rts(int fd, int state) {
    int status;
    ioctl(fd, TIOCMGET, &status); // 获取当前的串口控制信号状态
    if (state) {
        status |= TIOCM_RTS;      // 设置 RTS 为高电平
    } else {
        status &= ~TIOCM_RTS;     // 设置 RTS 为低电平
    }
    ioctl(fd, TIOCMSET, &status); // 将修改后的状态设置回去
}

int main() {
    int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY); // 打开串口设备,这里以 /dev/ttyS0 为例
    if (fd < 0) {
        perror("open");
        return -1;
    }

    int state = 0; // 初始状态为低电平
    while (1) {
        set_rts(fd, state); // 设置 RTS 信号
        state = !state;     // 切换状态
        sleep(1);           // 等待一秒
    }

    close(fd); // 关闭串口设备
    return 0;
}

gcc rts.c -o rts