linux中串口如何支持非标准波特率B28800?
2008-03-12 11:11
197 查看
转贴请注明出处,文章来自: blog.csdn.net/chenzhixin
参考:http://blog.ednchina.com/seam_liu/7181/post.aspx
#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,
},
};
参考:http://blog.ednchina.com/seam_liu/7181/post.aspx
#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?
- 如何在S3C2440上linux操作系统下将串口的波特率提高以致921600
- linux下串口非标准波特率的实现
- Linux PHP增加JSON支持及如何使用JSON
- 在linux下如何查看CPU是否支持64位的方法
- Linux PHP增加JSON支持及如何使用JSON
- Linux支持串口输出的方法
- 剖析非标准波特率的设置和使用于Linux操作系统中
- linux支持串口(serial)登录配置方法
- 如何让linux/Centos 32位支持大于4G内存
- 【linux内核剖析笔记】linux支持的终端设备类型及终端、控制台、串口、UART、RS232、RS485的联系和区别
- Linux下如何通过串口连接Cisco交换机
- 如何查看arm-linux-gcc某个版本支持的-mcpu,-march可选值
- Linux PHP增加JSON支持及如何使用JSON
- 如何让Linux浏览器(iceweasel, firefox)支持java程序
- 如何让linux/Centos 32位支持大于4G内存 .
- 如何查看linux是否支持cfg80211
- 如何让LINUX支持中文目录
- 如何使Linux支持中文字符
- 如何理解Linux支持多用户?