linux串口驱动初始化
来源:互联网 发布:sql server browser 编辑:程序博客网 时间:2024/05/29 19:55
- // 内容比较简单,只为保存一下!
- int uart_init(int num,int nSpeed)
- {
- int fd;
- char port[20];
- struct termios Opt;
- sprintf(port, "/dev/ttySAC%d", num);
- dprintf("Use port: %s ", port);
- fd = open(port, O_RDWR); //打开串口
- if (fd < 0)
- {
- perror("open ttySAC error");
- }
- tcgetattr(fd, &Opt); //初始化
- tcflush(fd, TCIFLUSH);
- switch (nSpeed)
- {
- case 2400:
- cfsetispeed(&Opt, B2400);
- cfsetospeed(&Opt, B2400);
- break;
- case 4800:
- cfsetispeed(&Opt, B4800);
- cfsetospeed(&Opt, B4800);
- break;
- case 9600:
- cfsetispeed(&Opt, B9600);
- cfsetospeed(&Opt, B9600);
- break;
- case 57600:
- cfsetispeed(&Opt, B57600);
- cfsetospeed(&Opt, B57600);
- break;
- case 115200:
- cfsetispeed(&Opt, B115200);
- cfsetospeed(&Opt, B115200);
- break;
- case 460800:
- cfsetispeed(&Opt, B460800);
- cfsetospeed(&Opt, B460800);
- break;
- default:
- cfsetispeed(&Opt, B9600);
- cfsetospeed(&Opt, B9600);
- break;
- }
- Opt.c_cflag |= CS8; //设置数据位
- Opt.c_cflag &= ~PARENB;
- Opt.c_oflag &= ~(OPOST);
- Opt.c_cflag &= ~CSTOPB;
- Opt.c_lflag &= ~(ICANON | ISIG | ECHO | IEXTEN);
- Opt.c_iflag &= ~(INPCK | BRKINT | ICRNL | ISTRIP | IXON);
- Opt.c_cc[VMIN] = 0;
- Opt.c_cc[VTIME] = 0;
- if (tcsetattr(fd, TCSANOW, &Opt) != 0)
- {
- perror("SetupSerial!");
- close(fd);
- return -1;
- }
- return fd;
- }
0 0
- linux串口驱动初始化
- linux串口驱动初始化
- linux串口驱动初始化
- Linux串口驱动分析初始化
- Linux串口驱动分析初始化
- [4]ARM-Linux S5PV210 UART驱动----串口驱动初始化过程
- 串口驱动分析-初始化
- 串口tty驱动之初始化
- Linux 串口终端初始化
- linux UART串口驱动
- linux串口驱动分析
- linux串口驱动分析
- linux串口驱动分析
- linux串口驱动分析
- linux串口驱动分析
- linux串口驱动分析
- linux串口驱动分析
- linux 串口驱动
- jBPM4.4:ProcessDefinition/ProcessInstance/Execution/Task关系和区别
- jBPM4.4:ProcessDefinition/ProcessInstance/Execution/Task关系和区别
- java之反射进阶
- jbpm4各个包的作用描述
- jbpm4各个包的作用描述
- linux串口驱动初始化
- linux串口驱动初始化
- Linux Platform Device and Driver的注册过程解析
- Linux Platform Device and Driver的注册过程解析
- linux termios 详解
- linux termios 详解
- linux串口编程例子
- linux串口编程例子
- 使程序在Linux下后台运行