串口初始化

来源:互联网 发布:python创建元组 编辑:程序博客网 时间:2024/05/22 08:23

int ComInit(unsigned char ComID,unsigned int Boudrate)
{
int status;
struct termios options;

tcflush(ComID,TCIOFLUSH);tcgetattr(ComID, &options);switch(Boudrate){    case 9600:       options.c_cflag = B9600|CS8|CLOCAL|CREAD;       break;    case 115200:       options.c_cflag = B115200|CS8|CLOCAL|CREAD;       break;    case 230400:        options.c_cflag = B230400|CS8|CLOCAL|CREAD;        break;       break;}options.c_iflag = IGNPAR;options.c_lflag = 0;options.c_oflag = 0;options.c_cc[VTIME]=3; options.c_cc[VMIN] =200;status = tcsetattr(ComID,TCSANOW,&options);if(status!=0) {                close(ComID);        printf("uart init ERR_DEVICE");        return -1;     }    tcflush(ComID,TCIOFLUSH); return 0;

}

原创粉丝点击