用 Victor 串口控件出现程序死掉,甚至电脑死机,蓝屏的问题.
void __fastcall TForm14::btn_searchClick(TObject *Sender)
{
TCommSerialPortInfo spi ;
String s ;
int com , rc ;
int r_len ;
unsigned char check,temp[] = { 0x55,0xaa,0x90,0x09,0,0,0, 1 , 0 , 1 ,0xff } ;
unsigned char r_data[1024] ;
pb1->Max = spi.PortList->Count ;
for(int i=0; i<spi.PortList->Count ; i++)
{
com = spi.PortNo(spi.PortList->Strings[i]) ;
pb1->Position = i+1 ;
try
{
if( Form9->ybc1->Active )
Form9->ybc1->Active = false ;
Application->ProcessMessages();
Form9->ybc1->PortNo = com ;
Form9->ybc1->Active = true;
{
lbl_info->Caption = ( "查找串口: "+ spi.PortList->Strings[i]) ;
}
Form9->ybc1->Write(temp,10) ;
for(int i=0 ; i < 30 ; i++ )
{
Sleep(10);
Application->ProcessMessages();
}
r_len = Form9->ybc1->Read(r_data,1024) ; //收到 n 个字节
if(r_len > 128)
{
}
Form9->ybc1->Active = false ;
}
catch(Exception &e)
{
{
lbl_info->Caption = ("无法打开: "+ spi.PortList->Strings[i]) ;
}
}
Application->ProcessMessages();
}
lbl_info->Caption = ("搜索结束!") ;
}