MT7688 串口调整每次接收数据的字节数

零:MT7688 串口编程   最初使用的串口只能每次接收八个字节    多余八个字节之后就分成多次 进行发送,之前更改过一次后来更改每次能接收64字节 ,时间一长当初怎么改的忘记了,现在我的需求有所增加,每次得接收至少150字节,索性仔细看了看之前的程序,然后做下记录。
1 、串口编程的介绍
我的串口驱动是原厂自带的   所以修改的主要是应用程序对串口的配置。 
打开/关闭 串口
int fd;
   fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
   if (fd == -1)
   {
        
        perror("open_port: Unable to open /dev/ttyS0 -");
   }
    close(fd);
2、设置波特率等等一些参数
termios结构体成员
成员 描述
c_cflag 控制选项
c_lflag 行选项
c_iflag 输入选项
c_oflag 输出选项
c_cc 控制字符
c_ispeed 输入波特率(NEW)
c_ospeed 输出波特率(NEW)
至于termios的各个参数的选项 不在赘述。我的配置如下
struct termios opt;

if (tcgetattr(fd, &opt) != 0) {
perror("set parity");
return FALSE;
}
opt.c_cflag &= ~CSIZE;
switch (databits) {
case 5:
opt.c_cflag |=CS5;
break;
case 6:
opt.c_cflag |=CS6;
break;
case 7:
opt.c_cflag |= CS7;
break;
case 8:
opt.c_cflag |= CS8;
break;
default:
fprintf(stderr, "Unsupported data size\n");
return FALSE;
}
switch (parity) {
case 'n':
case 'N':
opt.c_cflag &= ~PARENB;
opt.c_iflag &= ~INPCK;
break;
case 'o':
case 'O':
opt.c_cflag |= (PARODD | PARENB);
opt.c_iflag |= INPCK;
break;
case 'e':
case 'E':
opt.c_cflag |= PARENB;
opt.c_cflag &= ~PARODD;
opt.c_iflag |= INPCK;
break;
case 's':
case 'S':
opt.c_cflag &= ~PARENB;
opt.c_cflag &= ~CSTOPB;
break;
default:
fprintf(stderr, "Unsupported parity\n");
return FALSE;
}

switch (stopbits) {
case 0:
case 1:
opt.c_cflag &= ~CSTOPB;
break;
case 2:
opt.c_cflag |= CSTOPB;
break;
default:
fprintf(stderr, "Unsupported stop bits\n");
return FALSE;
}

if (parity != 'n' || parity != 'N')
opt.c_iflag |= INPCK;

   

opt.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
opt.c_oflag &= ~OPOST;
opt.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
 
opt.c_cc[VTIME] = 1;//150; //15 seconds 150x100ms = 15s
opt.c_cc[VMIN] = 150;//60;
   
tcflush(fd, TCIFLUSH); //update the options and do it now
if (tcsetattr(fd, TCSANOW, &opt) != 0) {
perror("Setup Ser ial");
return FALSE;
}
termios 的c_cflag初始化很简单理解,控制每次传输字节数的配置主要在 termios的c_cc【】这个选项中。

成员变量c_cc中的控制字符

常量 描述
VINTR Interrupt CTRL-C
VQUIT Quit CTRL-Z
VERASE Erase Backspace (BS)
VKILL Kill-line CTRL-U
VEOF End-of-file CTRL-D
VEOL End-of-line Carriage return (CR)
VEOL2 Second end-of-line Line feed (LF)
VMIN Minimum number of characters to read -
VSTART Start flow CTRL-Q (XON)
VSTOP Stop flow CTRL-S (XOFF)
VTIME Time to wait for data (tenths of seconds) -

我的配置是
opt.c_cc[VTIME] = 1;//150; //15 seconds 150x100ms = 15s   每次读取等待时间
         opt.c_cc[VMIN] = 150;//60; 每次读取的字节数目
所以  主要是更改这个地方
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值