void CTestDlg::OnTimer(UINT nIDEvent)
{
unsigned char readOrder1[5]={0x01,0x01,0x01,0x0d,0x0a};
unsigned char readOrder2[5]={0x01,0x01,0x02,0x0d,0x0a};
unsigned char readOrder3[5]={0x01,0x01,0x03,0x0d,0x0a};
unsigned char readOrder4[5]={0x01,0x01,0x04,0x0d,0x0a};
unsigned char readOrder5[5]={0x01,0x01,0x05,0x0d,0x0a};
unsigned char readOrder6[5]={0x01,0x01,0x07,0x0d,0x0a};
int i,j,t;
CTime TimeS;
VARIANT variant_inp;
COleSafeArray safearray_inp;
CString tempstr0,tempstr1;
CByteArray array,array2;
LONG len,k;
CString strtemp;
char rxdata[2048];
short fgh=0;
switch(nIDEvent)
{
case 0x0001:
array.RemoveAll();
array.SetSize(5);
array2.RemoveAll();
array2.SetSize(5);
for(i=0;i<5;i++)
{
array.SetAt(i, readOrder1[i]);
}
UpdateData(true);
m_ctrlComm.SetOutput(COleVariant(array));
while(fgh!=2)
{
fgh=m_ctrlComm.GetCommEvent();
//m_ctrlComm.SetOutput(COleVariant(array));
}
Sleep(50);
variant_inp=m_ctrlComm.GetInput();
safearray_inp=variant_inp;
len=safearray_inp.GetOneDimSize();
for(k=0;k<len;k++)
safearray_inp.GetElement(&k,rxdata+k);
USART_TX_STA=0;
for(k=0;k<len;k++)
{
USART_TX_BUF[USART_TX_STA&0X3FFF]=*(rxdata+k) ;
USART_TX_STA++;
}
这是上位机中定时器程序的一小部分,该定时器设置为1S触发一次,nIDEvent返回为1,即表示定时器1,在定时器1中,每秒通过串口向单片机发送可以array5个字节的数据,然后单片机会自动返回数据上位机的串口,而上位机则一直在判断m_ctrlComm.GetCommEvent()的值是否为2,即判断上位机串口接收缓冲区有没有数据,但程序一旦执行,就卡死在while(fgh!=2)
{
fgh=m_ctrlComm.GetCommEvent();
//m_ctrlComm.SetOutput(COleVariant(array));
}
这个语句中,导致程序直接死机,请问有人知道是什么回事吗?
一周热门 更多>