Chinaunix首页 | 论坛 | 博客
  • 博客访问: 554415
  • 博文数量: 104
  • 博客积分: 4131
  • 博客等级: 上校
  • 技术积分: 1137
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-31 15:05
文章分类

全部博文(104)

文章存档

2011年(13)

2010年(23)

2009年(68)

我的朋友

分类:

2010-04-03 18:30:44

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include ...
int ttyWriterTester(int chan )
{
    char ttyname[64];
    char dbuf[128];
    int ttyFd, len;
  int i = 1000;
    sprintf(ttyname,"/tyCo/%d", chan);
    ttyFd = open (ttyname, O_RDWR, 0);
    printf("Now Test Write with Port %s\n",ttyname);
 
     ioctl(ttyFd,FIOSETOPTIONS,OPT_RAW);
     ioctl(ttyFd,FIOBAUDRATE,115200);
     ioctl(ttyFd,SIO_HW_OPTS_SET,(CLOCAL|CREAD|CS8)&~(HUPCL|STOPB|PARENB));
     ioctl(ttyFd,FIOFLUSH,0);
    sprintf(dbuf, " hello world!", ttyname);
    len = strlen(dbuf);
 
  while(1){
     write(ttyFd, dbuf, len);
  
   taskDelay(60);
  }
     close(ttyFd);
    return 0;
    }

int ttyReaderTester (int chan)
    {
    char ttyname[64];
    char dbuf[128];
    int ttyFd,len,result;
    sprintf(ttyname,"/tyCo/%d", chan);
    ttyFd = open (ttyname, O_RDWR, 0);
    printf("Now Test Read with Port %s\n",ttyname);
 
    len = sizeof(dbuf);
     ioctl(ttyFd,FIOSETOPTIONS,OPT_RAW);
     ioctl(ttyFd,FIOBAUDRATE,115200);
     ioctl(ttyFd,SIO_HW_OPTS_SET,(CLOCAL|CREAD|CS8)&~(HUPCL|STOPB|PARENB));
    printf("before read  is called!\n");
    while(1){
            result= read (ttyFd, dbuf,len);
      dbuf[result] = 0;
      printf("read from line :%s \n",dbuf);
     }
    printf("after read .\n"); 
    printf("before close is called\n");
    close(ttyFd);
    printf("after close\n"); 
    return 0;
    }
 
阅读(3092) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~