switch (databits) /*設置數據位數*/
{
case 7:
options.c_cflag |= CS7; //設置c_cflag選項數據位為7位
break;
case 8:
options.c_cflag |= CS8; //設置c_cflag選項數據位為8位
break;
default:
fprintf(stderr,"Unsupported data size\n"); //其他的都不支持
return (FALSE);
}
switch (parity) //設置奇偶校驗,c_cflag和c_iflag有效
{
case 'n':
case 'N': //無校驗 當然都不選
options.c_cflag &= ~PARENB; /* Clear parity enable */
options.c_iflag &= ~INPCK; /* Enable parity checking */
break;
case 'o': //奇校驗 其中PARENB校驗位有效;PARODD奇校驗
INPCK檢查校驗
case 'O': options.c_cflag |= (PARODD | PARENB); /* 設置為奇效驗*/
options.c_iflag |= INPCK; /* Disnable parity checking */
break;
case 'e':
case 'E': //偶校驗,奇校驗不選就是偶校驗了
options.c_cflag |= PARENB; /* Enable parity */
options.c_cflag &= ~PARODD; /* 轉換為偶效驗*/
options.c_iflag |= INPCK; /* Disnable parity checking */
break;