VxWorks下串口应用编程

3209阅读 0评论2010-04-03 red_eyed_hare
分类:

#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;
    }
 
上一篇:VxWorks workbench中simulator的使用心得
下一篇:VxWorks 网络编程