硬汉嵌入式论坛

 找回密码
 立即注册
查看: 42|回复: 0
收起左侧

linux下串口接收数据

[复制链接]

9

主题

15

回帖

42

积分

新手上路

积分
42
发表于 前天 10:41 | 显示全部楼层 |阅读模式
在linux串口接收数据时,发现一整包数据被分割成多个接收,也没有超过缓冲区,想要发送不定长数据,也不设置帧头帧尾。这个问题该如何解决


void *recetive_thread(void *arg)
{
    int count;
    int bytes_read;

    count = 0;
    bytes_read = 0;

    while(!flag){
        bytes_read = read(fd, buf, sizeof(buf));
        // bytes_read = read_data(fd, (char *)buf, len);
        if (bytes_read > 0){
            fprintf(stderr, "Recv %d byte(s) %X\n", bytes_read, *buf);
        }
        for (int i = 0; i < bytes_read; i++) {
                fprintf(stderr, " %02X", (unsigned int)buf);
            }
            fprintf(stderr, "\n");
    }
    pthread_exit(NULL);
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-25 07:12 , Processed in 0.217950 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表