主题 : linux虚拟机下面写的串口写函数,write的返回值为什么一直是0 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 76822
精华: 0
发帖: 11
金钱: 55 两
威望: 11 点
贡献值: 0 点
综合积分: 22 分
注册时间: 2012-08-30
最后登录: 2012-09-25
楼主  发表于: 2012-09-03 17:28

 linux虚拟机下面写的串口写函数,write的返回值为什么一直是0

/*com_writer.c*/
#include "uart_api.h"
int main(void)
{
int fd;
char buff[BUFFER_SIZE];
if((fd=open_port(HOST_COM_PORT))<0)  /*打开串口*/
{
  perror("open serial error");
  return 1;
}
if(set_com_config(fd,115200,8,'N',1)<0) /*配置串口*/
{
  perror("set_com_config error");
  return 1;
}
do
{
  printf("Input some words(enter 'quit' to exit):");
  memset(buff,0,BUFFER_SIZE);
  if(fgets(buff,BUFFER_SIZE,stdin)==NULL)
  {
   perror("fgets");
   break;
  }
  write(fd,buff,strlen(buff));
}while(strncmp(buff,"quit",4));
close(fd);
return 0;
}