日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

發布時間:2025/3/8 linux 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux串口缓冲区的大小,linux-----------串口设置缓冲器的大小 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉自: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

總結

以上是生活随笔為你收集整理的linux串口缓冲区的大小,linux-----------串口设置缓冲器的大小的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。