|
int CVICALLBACK ComRecvThreadFunction (void *functionData)
{
int i;
char *matchedchar;
unsigned int value;
while (g_FinishFlag)
{
char buf[451] = {0};
if (0 == 1)
{
Delay(0.2);
continue;
}
int len = GetInQLen(1);
int count = ComRd (1, buf, 451);
//未读到数据,延时200毫秒,继续监听
if (0 == count)
{
Delay(0.2);
continue;
}
for(i=0;i<count;i++)
{
if(buf[i]==0x61) //当字符为‘a’时,执行以下代码。
{
matchedchar=buf+i+1; //将matchedchar的指针对准字符'a'的下一位,即指向接收的数据
Fmt(&value,"%d<%s",matchedchar); //数据格式转换:字符型转换成整型
SetCtrlVal(panelHandle,PANEL_NUMERIC,value);
FlushInQ(1); //清空指定端口的输入队列
}
else if(buf[i]==0x62)
{
matchedchar=buf+i+1;
Fmt(&value,"%d<%s",matchedchar);
SetCtrlVal(panelHandle,PANEL_NUMERIC_2,value);
FlushInQ(1);
}
else if(buf[i]==0x63)
{
matchedchar=buf+i+1;
Fmt(&value,"%d<%s",matchedchar);
SetCtrlVal(panelHandle,PANEL_NUMERIC_3,value);
FlushInQ(1);
}
}
}
return 0;
}
代码可以正常运行,但是接收到的数据和发送的数据结果不同,无论发送什么接收到的都是1754439612,请指教怎样可以将接收到的数据和发送的数据一致 |
|