最近用s3c6410在inux环境下进行串口通信,遇到一个纠结的问题。
代码如下:
/*******************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<sys/ioctl.h>
int fd;
int flag_close;
void set_opt() //配置串口
{
struct termios option;
tcgetattr(fd,&option); //保存原来配置
cfmakeraw(&option);
option.c_cflag |=CLOCAL|CREAD;
cfsetispeed(&option,B115200);//设置波特率
cfsetospeed(&option,B115200);
option.c_cflag &=~CSIZE; //设置8位数据位
option.c_cflag |=CS8;
option.c_cflag &=~PARENB; //无奇偶校验
option.c_cflag |=CSTOPB; //2位停止位
option.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG);
tcflush(fd,TCIFLUSH); //清除缓存
tcsetattr(fd,TCSANOW,&option); //激活配置
} |