请帮帮忙!程序运行通过,但是收到数据后不执行解算函数,帮我看看是什么问题好么?谢谢!
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
bReceivedEnable=false;
iWorkMode=0; //默认工作模式为实战模式
nCount = 0;
Receivedn=0;
ptr=0;
CountNumber=0;
AllData[CountNumber][0]=0;
AllData[CountNumber][1]=0;
try
{
YbCommDevice1->Active = true;
}
catch(Exception &e)
{
Application->Terminate();
}
if(bReceivedEnable)
{
Timer1->Enabled=true;
Timer1->Interval=1000;
Timer1->OnTimer;
}
}
void __fastcall TForm1::YbCommDevice1CommNotify(TObject *Sender,int NotifyType) //串口已收到数据就执行此过程
{
if(NotifyType & EV_RXCHAR)
{
int n;
char *Buf=new char[1024];
while((n=YbCommDevice1->Read(Buf,1000))>0)
{
bReceivedEnable=true;
for(int i=0;i<n;i++)
{
cData[ptr++]=Buf[i]; //将收到的数据存到一个数组里;ptr、CountNumber和Receivedn在FormCreat里初始化为0
}
if(ptr%40==0 & ptr!=0) CountNumber+=1; //每40个字节为一组数据,共10个通道,每通道4个字节
if(CountNumber>2000) CountNumber=0;
Receivedn=n; //每次收到字节的个数
}
delete[]Buf;
}
}
void TForm1::GetNewData() //自编的字节转换成数据且按照通道号存到相应的数组中
{
int t,m=ptr-Receivedn;
for(int i=0; i<Receivedn; i++)
{
if(i%4==0) //单位:us
{
t=cData[m+i]; //每4个字节的第一个字节为通道号;后三个字节为高位在前低位在后表示一个整数
cDelay[t][mBuf[t]++]=2500000-2*(cData[m+i+1]*256*256+cData[m+i+2]*256+cData[m+i+3]);
} //cDelay[10][8640]
}
if((ptr+1)==8640) ptr=0;
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(Receivedn>0)
{
GetNewData(); //取数
TDa->Locating(); //解算目标位置
display();
Receivedn=0;
}
}
现在的问题是程序运行收到数据后,不执行定时器程序。我的总体思想是按发射按钮之后,通过串口发出命令EE,硬件经过一系列过程后,定期给我传送40字节的数据,我想在第一次收到数据后,启动定时器程序,每隔一秒自动取数、解算、显示。
我现在搞不懂得时,这些功能执行时,它们该怎样联系起来?上面的程序好像就没联系上。
请各位高手帮忙看看该怎样做。搞不懂急死人了!
感谢!敬请早些回复!期盼!