linux串口缓冲区的大小,linux-----------串口设置缓冲器的大小

2023-05-16

转自:http://stackoverflow.com/questions/10815811/linux-serial-port-reading-can-i-change-size-of-input-buffer

You want to use the serial IOCTL TIOCSSERIAL which allows changing both receive buffer depth and send buffer depth (among other things). The maximums depend on your hardware, but if a 16550A is in play, the max buffer depth is 14.

You can find code that does something similar to what you want to do here

一下转自:http://e2e.ti.com/support/embedded/linux/f/354/t/164893.aspx

Hello,

I need to send a character (acknowledgement) after reception of a telegram

within no more than 2ms. Before beginning the real application, I wrote a

small test program, to measure the latency. Very strange: sometimes the

latency is about 3ms, sometimes about some �s only, but never other values,

than these 2.

For testing, I send about 3 times per second the telegram "abcdefghij" from

another system to my serial interface.

Perhaps, I need some more information about the fifos: are there tx and rx

fifos, where and how should I configure them?

Here is my test-program with some more detailed questions:

/* I tried 0, 1, 10 and 16, but it does not seem to change anything... */

#define FIFO_SIZE 1

/* This is needed, if not, we can get up to 10ms latency. */

#define TEST_LOW_LATENCY 1

/* If 1, than it seems, some transmissions get lost... */

#define TEST_OUTPUT_FLUSH 0

/* Perhaps only useful with heavy load... */

#define TEST_SCHED 1

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define _POSIX_SOURCE 1

#define DEVICE "/dev/ttyS0"

#define FRAME_SIZE 10 // "abcdefghij"

int fd;

void serial_init()

{

struct termios options;

struct serial_struct serial;

if((fd = open(DEVICE, O_RDWR | O_NOCTTY)) < 0){

perror(DEVICE);

exit(-1);

}

ioctl(fd, TIOCGSERIAL, &serial);

#if TEST_LOW_LATENCY

serial.flags |= ASYNC_LOW_LATENCY;

#else

serial.flags &= ~ASYNC_LOW_LATENCY;

#endif

serial.xmit_fifo_size = FIFO_SIZE; // what is "xmit" ??

ioctl(fd, TIOCSSERIAL, &serial);

tcgetattr(fd, &options);

cfsetispeed(&options, B19200);

cfsetospeed(&options, B19200);

options.c_cflag &= ~(CSIZE | PARODD | CSTOPB | CRTSCTS);

options.c_cflag |= CLOCAL | CREAD | CS8 | PARENB;

options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

options.c_iflag |= INPCK | ISTRIP;

options.c_oflag &= ~OPOST;

options.c_cc[VTIME] = 1;

options.c_cc[VMIN] = FRAME_SIZE;

tcsetattr(fd, TCSANOW, &options);

}

int check_frame()

{

char buf[FRAME_SIZE + 1];

while(!read(fd, buf, FRAME_SIZE));

buf[FRAME_SIZE] = '\0';

puts(buf);

return buf[FRAME_SIZE - 1] == 'j';

}

void serial_ack()

{

write(fd, "a", 1);

#if TEST_OUTPUT_FLUSH

tcflush(fd, TCOFLUSH);

#endif

}

int main()

{

#if TEST_SCHED

struct sched_param sched;

sched_getparam(0, &sched);

sched.sched_priority = 50;

sched_setscheduler(0, SCHED_RR, &sched);

#endif

serial_init();

while(1)

if(check_frame())

serial_ack();

else

puts("Error");

return 0;

}

I would be glad about any hint!

Greetings, Peter

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

linux串口缓冲区的大小,linux-----------串口设置缓冲器的大小 的相关文章

  • PIL 的 Image.show() 带来*两个*不同的查看器

    在 python shell 中处理图像时 我使用 image show 其中 image 是 Image 的实例 很久以前什么也没发生 但在定义了一个名为 xv 的 Mirage 符号链接后 我很高兴 最近几天 show 将显示 Imag
  • 如何将一个文本文件拆分为多个 *.txt 文件?

    我有一个文本文件file txt 12 MB 包含 something1 something2 something3 something4 有没有办法分开file txt分成 12 个 txt 文件 比方说file2 txt file3 t
  • 任何退出 bash 脚本但不退出终端的方法

    当我使用exitshell 脚本中的命令 该脚本将终止终端 提示符 有什么方法可以终止脚本然后停留在终端中吗 我的剧本run sh预计通过直接获取或从另一个脚本获取来执行 编辑 更具体地说 有两个脚本run2 sh as run sh ec
  • 如何获取与 shell 中的文件名模式匹配的所有文件的总文件大小?

    我正在尝试仅使用 shell 来计算与文件名模式匹配的所有文件 在目录树中 的总大小 以字节为单位 这是我到目前为止所拥有的 find name undo exec stat c s awk 总计 1 END 打印总计 有没有更简单的方法来
  • 如何在C(Linux utf8终端)中打印“盒子抽屉”Unicode字符?

    我正在尝试显示 方框图范围 2500 257F 中的 Unicode 字符 它应该是标准 utf8 Unicode 标准 版本 6 2 我根本做不到 我首先尝试使用旧的 ASCII 字符 但 Linux 终端以 utf8 显示 并且没有显示
  • 使用脚本检查 git 分支是否领先于另一个分支

    I have branch1 and branch2我想要某种 git branch1 isahead branch2 这将显示如果branch1已承诺branch2没有 也可能指定这些提交 我无法检查差异原因branch2 is在之前br
  • 在 Linux 中重新启动时,新创建的文件变为 0 kb(数据被覆盖为空)

    我遇到了一个奇怪的问题 这让我发疯 当前的任务是在 root 用户第一次登录时启动一组文件 并在同一用户第二次登录时启动另一组文件 我决定使用 profile 和 bashrc 文件 并在第一次登录期间发生的任务结束时重新加载 bashrc
  • 更新Linux中的包含路径

    我的 my path to file 文件夹中有几个头文件 我知道如何将这些文件包含在新的 C 程序中 但每次我都需要在包含它之前输入头文件的完整路径 我可以在linux中设置一些路径变量 以便它自动查找头文件吗 您可以创建一个 makef
  • MySQL 与 PHP 的连接无法正常工作

    这是我的情况 我正在尝试使用 Apache 服务器上的 PHP 文件连接到 MySQL 数据库 现在 当我从终端运行 PHP 时 我的 PHP 可以连接到 MySQL 数据库 使用 php f file php 但是当我从网页执行它时 它只
  • 为什么 OS X 和 Linux 之间的 UTF-8 文本排序顺序不同?

    我有一个包含 UTF 8 编码文本行的文本文件 mac os x cat unsorted txt foo foo 津 如果它有助于重现问题 这里是文件中确切字节的校验和和转储 以及如何自己生成文件 在 Linux 上 使用base64 d
  • /sys/device/ 和 dmidecode 报告的不同 CPU 缓存大小

    我正在尝试获取系统中不同缓存级别的大小 我尝试了两种技术 a 使用 sys device 中的信息 这是输出 cat sys devices system cpu cpu0 cache index1 size 32K cat sys dev
  • Linux无法删除文件

    当我找到文件时 我在删除它们时遇到问题 任务 必须找到带有空格的文件并将其删除 我的尝试 rm find L root grep i 但我有错误 rm cannot remove root test No such file or dire
  • 为什么 fork 炸弹没有使 android 崩溃?

    这是最简单的叉子炸弹 我在许多 Linux 发行版上执行了它 但它们都崩溃了 但是当我在 android 终端中执行此操作时 即使授予后也没有效果超级用户权限 有什么解释为什么它没有使 Android 系统崩溃吗 一句话 ulimit Li
  • ssh 连接超时

    我无法在 git 中 ssh 到 github bitbucket 或 gitlab 我通常会收到以下错误消息 如何避免它 输出 ssh T email protected cdn cgi l email protection i ssh
  • vmsplice() 和 TCP

    在原来的vmsplice 执行 有人建议 http lwn net Articles 181169 如果您的用户态缓冲区是管道中可容纳的最大页面数的 2 倍 则缓冲区后半部分成功的 vmsplice 将保证内核使用缓冲区的前半部分完成 但事
  • 为什么 Linux 原始套接字的 RX 环大小限制为 4GB?

    背景 我试图mmap 我的原始套接字的 RX 环形缓冲区64 bitLinux 应用程序 我的环由 4096 个块组成 每个块大小为 1MB 总共 4GB 请注意 每个 1MB 块中可以有许多帧 如果您好奇 请参阅此文档了解背景信息 htt
  • SSH,运行进程然后忽略输出

    我有一个命令可以使用 SSH 并在 SSH 后运行脚本 该脚本运行一个二进制文件 脚本完成后 我可以输入任意键 本地终端将恢复到正常状态 但是 由于该进程仍在我通过 SSH 连接的计算机中运行 因此任何时候它都会登录到stdout我在本地终
  • 适用于 Linux 的轻量级 IDE [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 在 .gitconfig 中隐藏 GitHub 令牌

    我想将所有点文件存储在 GitHub 上 包括 gitconfig 这需要我将 GitHub 令牌隐藏在 gitconfig 中 为此 我有一个 gitconfig hidden token 文件 这是我打算编辑并放在隐藏令牌的 git 下
  • 我们真的应该使用 Chef 来管理 sudoers 文件吗?

    这是我的问题 我担心如果 Chef 破坏了 sudoers 文件中的某些内容 可能是 Chef 用户错误地使用了说明书 那么服务器将完全无法访问 我讨厌我们完全失去客户的生产服务器 因为我们弄乱了 sudoers 文件并且无法再通过 ssh

随机推荐