歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux串口編程分析(二)

Linux串口編程分析(二)

日期:2017/2/25 10:38:40   编辑:Linux教程
 options.c_cflag &= ~CSIZE; //這是設置c_cflag選項不按位數據位掩碼

  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;

Copyright © Linux教程網 All Rights Reserved