标题:帮忙看喜爱这个小程序,都快崩溃了;
取消只看楼主
xdp5202008
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-11-16
结帖率:0
已结贴  问题点数:20 回复次数:0 
帮忙看喜爱这个小程序,都快崩溃了;
#include <stdio.h>   
#include <string.h>  
#include <unistd.h>  
#include <fcntl.h>  
#include <errno.h>   
#include <termios.h>
#include <stdlib.h>
int fd;/* File descriptor for the port */
int open_port(void)
  {
  fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1)
    {
   /*
    * Could not open the port.
    */

    perror("open_port: Unable to open /dev/ttyS0 - ");
     }
  else
    fcntl(fd, F_SETFL, 0);
  return (fd);
   }
main()
{
   int n;
   int open_port(void);
   /*write data to the serial*/
    n = write(fd, "abcdefgh\n", 12);
    if (n < 0)
  fputs("write serial port failed!\n", stderr);
    else
  printf("write serial port is:\n");
    /*read data for the serail*/
  fcntl(fd, F_SETFL, FNDELAY);
   close(fd);
}

以上程序执行完后都是得到
abcdefgh
wrwrite serial port is:
而且不管串口有没有连接开发板;
不知道是哪里的问题,求教了;
搜索更多相关主题的帖子: void include return 
2012-11-16 16:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-387277-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.416023 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved