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;
}