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-----------串口设置缓冲器的大小 的相关文章

  • 让 MongoDB 在 Linux 上监听远程连接

    我已在 Windows 本地计算机上 上成功安装 MongoDB 作为服务 但现在我想将 MongoDb 移动到单独的服务器 所以我将 tarball 解压到网络上的虚拟服务器 运行 Linux 当我从本地计算机使用 PuTTY 连接到服务
  • 如何使用 sed 仅删除双空行?

    我找到了这个问题和答案 https stackoverflow com questions 4651591 howto use sed to remove only triple empty lines关于如何删除三重空行 但是 我只需要对
  • arm-linux-gnueabi 编译器选项

    我在用 ARM Linux gnueabi gcc在 Linux 中为 ARM 处理器编译 C 程序 但是 我不确定它编译的默认 ARM 模式是什么 例如 对于 C 代码 test c unsigned int main return 0x
  • 嵌入式Linux poll()不断返回

    我有一个特别的问题 当我知道没有什么可读时 民意调查不断返回 因此设置如下 我有 2 个文件描述符 它们构成fd设置民意调查监视 一种用于引脚从高到低的变化 GPIO 另一个用于代理输入 代理输入出现问题 处理的顺序是 启动main函数 然
  • Godaddy 托管上的 CakePHP 控制台

    我一直在努力让我的 CakePHP 网站在 Godaddy 网格托管 帐户上运行 我的蛋糕应用程序设置是从帐户的子目录托管的 并且可以通过子域访问 我必须调整我的 htaccess 文件才能使其正常工作 现在我需要让 CakePHP 控制台
  • xsel -o 对于 OS X 等效项

    是否有一个等效的解决方案可以在 OS X 中抓取选定的文本 就像适用于 Linux 的 xsel o 一样 只需要当前的选择 这样我就可以在 shell 脚本中使用文本 干杯 埃里克 你也许可以安装xsel在 MacOS 上 更新 根据 A
  • 拆分字符串以仅获取前 5 个字符

    我想去那个地点 var log src ap kernelmodule 10 001 100 但看起来我的代码必须处理 ap kernelmodule 10 002 100 ap kernelmodule 10 003 101 等 我想使用
  • 修改linux下的路径

    虽然我认为我已经接近 Linux 专业人士 但显然我仍然是一个初学者 当我登录服务器时 我需要使用最新版本的R 统计软件 R 安装在 2 个地方 当我运行以下命令时 which R I get usr bin R 进而 R version
  • bluetoothctl 到 hcitool 等效命令

    在 Linux 中 我曾经使用 hidd connect mmac 来连接 BT 设备 但自 Bluez5 以来 这种情况已经消失了 我可以使用 bluetoothctl 手动建立连接 但我需要从我的应用程序使用这些命令 并且使用 blue
  • 从 PL/SQL 调用 shell 脚本,但 shell 以 grid 用户而非 oracle 身份执行

    我正在尝试使用 Runtime getRuntime exec 从 Oracle 数据库内部执行 shell 脚本 在 Red Hat 5 5 上运行的 Oracle 11 2 0 4 EE CREATE OR REPLACE proced
  • 是否可以在Linux上将C转换为asm而不链接libc?

    测试平台为Linux 32位 但也欢迎 Windows 32 位上的某些解决方案 这是一个c代码片段 int a 0 printf d n a 如果我使用 gcc 生成汇编代码 gcc S test c 然后我会得到 movl 0 28 e
  • 如何检测并找出程序是否陷入死锁?

    这是一道面试题 如何检测并确定程序是否陷入死锁 是否有一些工具可用于在 Linux Unix 系统上执行此操作 我的想法 如果程序没有任何进展并且其状态为运行 则为死锁 但是 其他原因也可能导致此问题 开源工具有valgrind halgr
  • 通过特定分隔符删除字符串

    我的文件中有几列 其中第二列有 分隔符 我想删除第二列中的第一个 第三个和第四个字符串 并将第二个字符串留在该列中 但我有正常的分隔符空间 所以我不知道 input 22 16050075 A G 16050075 A G 22 16050
  • 仅打印“docker-container ls -la”输出中的“Names”列

    发出时docker container ls la命令 输出如下所示 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a67f0c2b1769 busybox tail f dev
  • 如何在bash中使用jq从变量中包含的json中提取值

    我正在编写一个 bash 脚本 其中存储了一个 json 值 现在我想使用 Jq 提取该 json 中的值 使用的代码是 json val code lyz1To6ZTWClDHSiaeXyxg redirect to http examp
  • 为什么内核需要虚拟寻址?

    在Linux中 每个进程都有其虚拟地址空间 例如 32位系统为4GB 其中3GB为进程保留 1GB为内核保留 这种虚拟寻址机制有助于隔离每个进程的地址空间 对于流程来说这是可以理解的 因为有很多流程 但既然我们只有 1 个内核 那么为什么我
  • Linux中的定时器类

    我需要一个计时器来以相对较低的分辨率执行回调 在 Linux 中实现此类 C 计时器类的最佳方法是什么 有我可以使用的库吗 如果您在框架 Glib Qt Wx 内编写 那么您已经拥有一个具有定时回调功能的事件循环 我认为情况并非如此 如果您
  • linux perf:如何解释和查找热点

    我尝试了linux perf https perf wiki kernel org index php Main Page今天很实用 但在解释其结果时遇到了困难 我习惯了 valgrind 的 callgrind 这当然是与基于采样的 pe
  • 尝试安装 LESS 时出现“请尝试以 root/管理员身份再次运行此命令”错误

    我正在尝试在我的计算机上安装 LESS 并且已经安装了节点 但是 当我输入 node install g less 时 出现以下错误 并且不知道该怎么办 FPaulMAC bin paul npm install g less npm ER
  • 如何在 Linux shell 中将十六进制转换为 ASCII 字符?

    假设我有一个字符串5a 这是 ASCII 字母的十六进制表示Z 我需要找到一个 Linux shell 命令 它将接受一个十六进制字符串并输出该十六进制字符串代表的 ASCII 字符 所以如果我这样做 echo 5a command im

随机推荐