我编写了以下代码,在其中打开并配置了我的串口设备
int open_port(void)
{
 int fd; // file description for the serial port 
 fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);
 if(fd == -1) // if open is unsucessful
  {
   //perror("open_port: Unable to open /dev/ttyAMA0 - ");
   printf("open_port: Unable to open /dev/ttyAMA0. \n");
  }
 else
 {
  fcntl(fd, F_SETFL, 0);
  printf("port is open.\n");
 }
return(fd);
} //open_port
并配置端口
int configure_port(int fd)      // configure the port
{
 struct termios port_settings;      // structure to store the port settings in
 cfsetispeed(&port_settings, B9600);    // set baud rates
 cfsetospeed(&port_settings, B9600);
 port_settings.c_cflag &= ~PARENB;    // set no parity, stop bits, data bits
 port_settings.c_cflag &= ~CSTOPB;
 port_settings.c_cflag &= ~CSIZE;
 port_settings.c_cflag |= CS8;
 tcsetattr(fd, TCSANOW, &port_settings);    // apply the settings to the port
 return(fd);
} //configure_port 
我的问题(也许很简单)是我必须在这两个功能中完全改变才能拥有
FILE *fd;
fd=fopen("/dev/ttyUSB0","r");
而不是 fd= open(...) 等?