MT7688 串口调整每次接收数据的字节数
2016-12-05 14:22
267 查看
零:MT7688 串口编程 最初使用的串口只能每次接收八个字节
多余八个字节之后就分成多次
进行发送,之前更改过一次后来更改每次能接收64字节 ,时间一长当初怎么改的忘记了,现在我的需求有所增加,每次得接收至少150字节,索性仔细看了看之前的程序,然后做下记录。
1 、串口编程的介绍
我的串口驱动是原厂自带的 所以修改的主要是应用程序对串口的配置。
打开/关闭 串口
int fd;
至于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中的控制字符
我的配置是
opt.c_cc[VTIME] = 1;//150; //15 seconds 150x100ms = 15s 每次读取等待时间
opt.c_cc[VMIN] = 150;//60; 每次读取的字节数目
所以 主要是更改这个地方
多余八个字节之后就分成多次
进行发送,之前更改过一次后来更改每次能接收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) |
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; 每次读取的字节数目
所以 主要是更改这个地方
相关文章推荐
- 闪烁led来标志串口的接收与发送数据
- 地磅称量系统之(59) 接收串口数据(串口控件的属性设置和超级终端的使用)
- 一个串口接收数据的代码
- VC写串口通信遇到只能接收发送数据交替执行的情况
- 使用Msp430的串口中断接收一包数据
- net2.0下实现串口接收GPS数据读写(-)
- vs 串口接收数据时 如果数据中含有中文 有时出现乱码的 解决
- 串口接收时丢数据问题解决方案
- 串口接收时丢数据问题解决方案
- linux多线程下打开串口发送和接收数据
- 串口接收时丢数据问题解决方案
- C#异步数据接收串口操作类
- C#异步数据接收串口操作类
- C#异步数据接收串口操作类
- [VB.NET]串口接收过程中怎样将末尾3位字符数据去掉?
- GPS串口数据接收程序实例
- 串口接收数据c#
- GPS数据串口接收的数据 是否在一个设定好的检测区内
- 串口处理数据(接收、解析、回复、框架)
- C#中请问如何在串口通讯中接收输出HEX格式数据