专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VxWorks

新手 串口通信测试有关问题

发布时间:2010-06-14 16:49:58 文章来源:www.iduyao.cn 采编人员:星星草
新手 串口通信测试问题
写了一个测试串口通信的小程序,通道3和通道4相连。向通道3写入数据,然后从通道4读出来,并且打印出来的。但是我发现打印出来的不是通道4读出来的结果。原程序如下。

#include <ioLib.h>
#include <stdio.h>
#include <taskLib.h>
int fd1=0,fd2=0;
int length=0;
int tyRecv( int fd2)
{
char szBuf[40]={0};
int i;
for(i=0;i<length;i++)
{
  if ( NULL!=read(fd2,szBuf,1) )
  {
  printf("szBuf=%s",szBuf) ;
  taskDelay(1) ;
  }
}
}
int tySend( int fd1 )
{
char seBuf[40]={0};
strcpy(seBuf, "Hello, world!\n"); 
length=strlen(seBuf);
write(fd1,seBuf,length) ;
/*taskDelay(60) ;*/
}
int testMain()
{
fd1=open("/tyCo/3",O_RDWR,0) ;
if (ERROR==fd1)
{
printf("can not open device3!\n") ;
return 0 ;
}
fd2=open("/tyCo/4",O_RDWR,0) ;
if (ERROR==fd2)
{
printf("can not open device4!\n") ;
return 0 ;
}
taskSpawn("send",60,VX_FP_TASK,1024*40,(FUNCPTR)tySend,fd1,0,0,0,0,0,0,0,0,0) ;
/*taskDelay(60) ;*/
taskSpawn("recv",60,VX_FP_TASK,1024*40,(FUNCPTR)tyRecv,fd2,0,0,0,0,0,0,0,0,0) ;

}



按我的思路,打印出来的应该是szBuf=Hello, world!
但是程序运行后打印出来的直接就是Hello, world! 这应该不是通道4读出来的打印结果的。
请问大家这是怎么回事呢?


------解决方案--------------------
程序写的漂亮
------解决方案--------------------
驱动写好了吗
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: