linux中串口如何支持非标准波特率B28800?
来源:互联网 发布:现在淘宝店还好做吗 编辑:程序博客网 时间:2024/09/21 08:14
http://blog.csdn.net/chenzhixin/article/details/2172524
#include <termios.h>
#include <sys/ioctl.h>
#include <linux/serial.h>
struct serial_t {
int fd;
char *device;/*/dev/ttyS0,...*/
int baud;
int databit;/*5,6,7,8*/
char parity;/*O,E,N*/
int stopbit;/*1,2*/
int startbit;/*1*/
struct termios options;
};
//设置为特诉波特率,比如28800
int serial_set_speci_baud(struct serial_t *tty,int baud)
{
struct serial_struct ss,ss_set;
cfsetispeed(&tty->options,B38400);
cfsetospeed(&tty->options,B38400);
tcflush(tty->fd,TCIFLUSH);/*handle unrecevie char*/
tcsetattr(tty->fd,TCSANOW,&tty->options);
if((ioctl(tty->fd,TIOCGSERIAL,&ss))<0){
dprintk("BAUD: error to get the serial_struct info:%s/n",strerror(errno));
return -1;
}
ss.flags = ASYNC_SPD_CUST;
ss.custom_divisor = ss.baud_base / baud;
if((ioctl(tty->fd,TIOCSSERIAL,&ss))<0){
dprintk("BAUD: error to set serial_struct:%s/n",strerror(errno));
return -2;
}
ioctl(tty->fd,TIOCGSERIAL,&ss_set);
dprintk("BAUD: success set baud to %d,custom_divisor=%d,baud_base=%d/n",
baud,ss_set.custom_divisor,ss_set.baud_base);
return 0;
}
用法:只要指定serial_t的baud就可以了
static struct serial_t __seri_conf[] = {
[0] = {//connect with b board, ttyS0
.device = "/dev/ttyS0",
.baud = 28800,
.databit = 8,
.parity = 'N',
.stopbit = 1,
},
};
- linux中串口如何支持非标准波特率B28800?
- linux中串口如何支持非标准波特率B28800?
- linux下串口非标准波特率的实现
- linux设置非标准波特率200000bit/s
- 串口通信中波特率
- 剖析非标准波特率的设置和使用于Linux操作系统中
- linux下非标准波特率的设置和使用
- linux下非标准波特率的设置和使用
- FireFox如何支持DHTML非标准属性:innerText
- 串口波特率
- Linux设置串口波特率等参数
- 如何在S3C2440上linux操作系统下将串口的波特率提高以致921600
- arm-linux内核中串口时钟频率及波特率的设置
- STM32中如何计算波特率
- project中如何设置非标准工作时间
- tera term 如何修改串口输出的波特率
- linux 命令修改串口或USB的波特率
- 串口通信过程中更改波特率的方法 C#实现
- 深入理解Java内存模型
- Android开发中使用Volley框架发送请求的get和post方法
- 模板方法模式
- quickcocos2dx 的绘画功能
- pageContext.pushBody() getOutputStream方法冲突
- linux中串口如何支持非标准波特率B28800?
- Android中Parcelable接口用法
- mac 生成 ssh keys
- ip
- warning:this program uses gets(), which is unsafe
- JSP和Servlet
- Android 文字粗体设置方法
- SQL注入网址
- Chrome内核解析 -- 背景篇:HTML, CSS解析与JavaScript执行