请教各位,我的开发环境是Tornado2.2+Vxworks5.5,硬件用的是串口1 ,将串口1的2,3脚短接,编写的程序如下:
[code=c]#include <ioLib.h>
#include <stdio.h>
#include <taskLib.h>
#include <sioLib.h>
#include <string.h>
#include <strLib.h>
#include <types/vxTypesold.h>
unsigned long recvcnt[] = {0};
char readbuf[512];
int fd;
int tyRecv(int fd)
{
int readCnt1;
char rd;
char buff[512];
int i;
FOREVER
{
i=0;
taskDelay(50);
ioctl(fd,FIONREAD,(int) &readCnt1); /* 判断com2接收数据缓冲区是否有数据到来 */
if(readCnt1>0)
{
while(readCnt1>0)
{
read(fd,&rd,1);
readCnt1--;
buff[i++]=rd;
}
buff[i]='\0';
printf("read '%s' from com2 whose data were sent by com1\n",buff);
}
}
}
int tySend()
{
int wrtCount;
char buff[]="I am god of war!"; /* 发送内容 */
wrtCount = write(fd,buff,strlen(buff));
}
int test()
{
fd = open("/tyCo/0",O_RDWR,0); /*O_RDWR=2*/
if ( ERROR==ioctl(fd,FIOBAUDRATE,115200) )
{
printf("can not set com1 BAUDRATE!/n") ;
return ERROR ;
}
if(ERROR == ioctl(fd, SIO_HW_OPTS_SET, CS8|CLOCAL))
{
printf("Can not set Options");
return ERROR;
}
ioctl(fd,FIOFLUSH,0);
/* 发起接受数据的任务 */
taskSpawn("recv",100,VX_FP_TASK,0x6000,(FUNCPTR)tyRecv,fd,0,0,0,0,0,0,0,0,0);
taskSpawn("send",90,VX_FP_TASK,0x6000,(FUNCPTR)tySend,fd,0,0,0,0,0,0,0,0,0);
}
运行后的界面如图所示:
请问:为什么第一次输入函数名test,运行正常,第二次就没有数据,第三、四次只能读到“I ”?是我程序哪里有问题吗?
请大家帮我看看吧,谢谢了!