⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 LMS软件是用来进行自适应滤波的最小均方误差算法
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}
//---------------------------------------------------------------------------

void __fastcall TF1::CB5Click(TObject *Sender)
{
    if(CB5->Checked)
    {
        E4->Enabled=true;
        E5->Enabled=true;
        L1->Enabled=true;
        L2->Enabled=true;
    }
    else
    {
        E4->Enabled=false;
        E5->Enabled=false;
        L1->Enabled=false;
        L2->Enabled=false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TF1::N18Click(TObject *Sender)
{
    if(FD1->Execute())
    {
        RE1->SelAttributes->Assign(FD1->Font);
    }
}
//---------------------------------------------------------------------------
void TF1::LoadIdentify()
{   int i,k,l;AnsiString tempa,tempb;
    i=0;
    while((M1->Lines->Strings[i++]!="[IDENTIFY]")&&(i<M1->Lines->Count));
    while((i<M1->Lines->Count-1)&&(M1->Lines->Strings[i].SubString(1,1)!="["))
    {
        k=M1->Lines->Strings[i].Pos("=");
        l=M1->Lines->Strings[i].Length();
        tempa=M1->Lines->Strings[i].SubString(1,k-1);tempa=tempa.Trim();
        tempb=M1->Lines->Strings[i].SubString(k+1,l-k);tempb=tempb.Trim();
        if(tempa=="CHINESE") {Identify[0].Description=tempa;Identify[0].Value=tempb;}
        if(tempa=="ONCMD") {Identify[1].Description=tempa;Identify[1].Value=tempb;}
        if(tempa=="OFFCMD") {Identify[2].Description=tempa;Identify[2].Value=tempb;}
        i++;
    }
    Identify[1].Value="0x"+Identify[1].Value;ParaFilter(&(Identify[1].Value),&k,&l);
    if(k!=1) Identify[1].Value=Identify[1].Value.SubString(1,Identify[1].Value.Pos(" ")-1);
    Identify[2].Value="0x"+Identify[2].Value;ParaFilter(&(Identify[2].Value),&k,&l);
    if(k!=1) Identify[2].Value=Identify[2].Value.SubString(1,Identify[2].Value.Pos(" ")-1);

    if(Identify[0].Value=="ON")  CB5->Checked=true; else CB5->Checked=false;
    E4->Text=Identify[1].Value.Delete(1,2);
    E5->Text=Identify[2].Value.Delete(1,2);
}
//---------------------------------------------------------------------------

void __fastcall TF1::BB1Click(TObject *Sender)
{
    if(OD1->Execute())
    {
        try
        {

            if(OD1->FilterIndex<3)
            {
                if(OD1->FilterIndex==1) RE1->PlainText=false;
                if(OD1->FilterIndex==2) RE1->PlainText=true;
                RE1->Clear();
                RE1->Lines->LoadFromFile(OD1->FileName);
                RB1->Checked=true;
                RE1->Visible=true;
                I1->Visible=false;
                RB1Click(Sender);
           }
            if(OD1->FilterIndex==3)
            {   int fp;long count;char *PRN,buf[]={0,0,0,0};
                fp=FileOpen(OD1->FileName,0);
                if(fp==-1) {ShowMessage("   "+OD1->FileName+"打开错误!  ");return;}
                count = FileSeek(fp,0,2);
                FileSeek(fp,0,0);
                if(count>(32768/2)) count=(32767/2);
                PRN=new char[count+1];
                if(TxBuf==NULL) {ShowMessage("   分配内存错误!  ");return;}
                count=FileRead(fp,PRN,count);
                for(int i=0;i<count;i++) {CharToHex(PRN[i],buf);buf[2]=0;E2->SetSelTextBuf(buf);}
                FileClose(fp);
                delete [] PRN;
            }
            if(OD1->FilterIndex==4)
            {
                I1->Picture->LoadFromFile(OD1->FileName);
                I1->Visible=true;
                RE1->Visible=false;
                RB2->Checked=true;
                RB4->Checked=true;
                RB3Click(Sender);
            }
        }
        catch(...)
        {
            ShowMessage("  "+OD1->FileName+"打开文件错误!  ");
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TF1::BB2Click(TObject *Sender)
{
    if(SD1->Execute())
    {  AnsiString temp;
        try
        {
            temp=SD1->FileName.UpperCase();
            if(SD1->FilterIndex==1)
            {
                if(temp.Pos(".RTF")==0)temp+=".RTF";
                RE1->PlainText=false;
            }
            else
            {
                if(temp.Pos(".TXT")==0)temp+=".TXT";
                RE1->PlainText=true;
            }
           RE1->Lines->SaveToFile(temp);
        }
        catch(...)
        {
            ShowMessage("  "+SD1->FileName+"文件存盘错误!    ");
        }
    }
}
//---------------------------------------------------------------------------


void __fastcall TF1::Label7DblClick(TObject *Sender)
{
    RXcount=0;
    L7->Caption="0";
}
//---------------------------------------------------------------------------

void __fastcall TF1::Label8DblClick(TObject *Sender)
{
    TXcount=0;
    L8->Caption="0";
}
//---------------------------------------------------------------------------

void __fastcall TF1::CB4Change(TObject *Sender)
{
    CB4->Hint=CMD[CB4->ItemIndex+1].Name;
    if(Sender==CB4) CMD[oldcmd+1].OldPara=E1->Text.Trim();
    oldcmd=CB4->ItemIndex;
    if(CMD[CB4->ItemIndex+1].Parameter=="")
    {
        L4->Enabled=false;
        E1->Text="No Parameter";
        E1->Enabled=false;
    }
    else
    {
        L4->Enabled=true;
        E1->Enabled=true;
        E1->Text=CMD[CB4->ItemIndex+1].OldPara;
    }
}
//---------------------------------------------------------------------------
void TF1::SaveCMD()
{
    M1->Lines->Add("[CMD]");
    for(int i=1;i<CMD[0].Count;i++) M1->Lines->Add(CMD[i].Name+"="+CMD[i].Value+" "+CMD[i].Parameter);
    M1->Lines->Add("DEFAULT="+IntToStr(CB4->ItemIndex));
}
//---------------------------------------------------------------------------
void TF1::SaveTool()
{
    M1->Lines->Add("[TOOL1]");
    M1->Lines->Add("BMP="+Tool[0].FileName);
    M1->Lines->Add("HINT="+Tool[0].Hint);
    M1->Lines->Add("VALUE="+Tool[0].Value.Delete(1,2));
    M1->Lines->Add("[TOOL2]");
    M1->Lines->Add("BMP="+Tool[1].FileName);
    M1->Lines->Add("HINT="+Tool[1].Hint);
    M1->Lines->Add("VALUE="+Tool[1].Value.Delete(1,2));
    M1->Lines->Add("[TOOL3]");
    M1->Lines->Add("BMP="+Tool[2].FileName);
    M1->Lines->Add("HINT="+Tool[2].Hint);
    M1->Lines->Add("VALUE="+Tool[2].Value.Delete(1,2));
    M1->Lines->Add("[TOOL4]");
    M1->Lines->Add("BMP="+Tool[3].FileName);
    M1->Lines->Add("HINT="+Tool[3].Hint);
    M1->Lines->Add("VALUE="+Tool[3].Value.Delete(1,2));
}
//---------------------------------------------------------------------------
void TF1::SavePort()
{
    M1->Lines->Add("[PORT]");
    for(int i=1;i<PORT[0].Value.ToIntDef(0);i++) M1->Lines->Add(PORT[i].Description+"="+PORT[i].Value);
    M1->Lines->Add("DEFAULT="+IntToStr(CB1->ItemIndex));
    M1->Lines->Add("[BAUD]");
    for(int i=1;i<BAUD[0].Value.ToIntDef(0);i++) M1->Lines->Add(BAUD[i].Description+"="+BAUD[i].Value);
    M1->Lines->Add("DEFAULT="+IntToStr(CB2->ItemIndex));
    M1->Lines->Add("[BYTE]");
    for(int i=1;i<BYTEs[0].Value.ToIntDef(0);i++) M1->Lines->Add(BYTEs[i].Description+"="+BYTEs[i].Value);
    M1->Lines->Add("DEFAULT="+IntToStr(CB3->ItemIndex));
    M1->Lines->Add("[PARITY]");
    M1->Lines->Add("PARITY="+IntToStr(Parity));
    M1->Lines->Add("[STOPBIT]");
    M1->Lines->Add("STOPBIT="+IntToStr(StopBit));
}
//---------------------------------------------------------------------------
void TF1::SaveIdentify()
{   AnsiString temp;int k;
    if(CB5->Checked) temp="NO"; else temp="OFF";
    M1->Lines->Add("[IDENTIFY]");
    M1->Lines->Add("CHINESE="+temp);
    temp=E4->Text.Trim();k=temp.Pos(" ");
    if(k==0) temp="0x"+temp;else temp="0x"+temp.SubString(1,k-1);
    ParaFilter(&temp,&k,&k);
    M1->Lines->Add("ONCMD="+temp.SubString(3,temp.Length()-2));
    temp=E5->Text.Trim();k=temp.Pos(" ");
    if(k==0) temp="0x"+temp;else temp="0x"+temp.SubString(1,k-1);
    ParaFilter(&temp,&k,&k);
    M1->Lines->Add("OFFCMD="+temp.SubString(3,temp.Length()-2));
}
//---------------------------------------------------------------------------

void __fastcall TF1::RB3Click(TObject *Sender)
{
    if(RB3->Checked)
    {
        RE1->Visible=true;
        I1->Visible=false;
    }
    else
    {
        RE1->Visible=false;
        I1->Visible=true;
    }
}
//---------------------------------------------------------------------------

void __fastcall TF1::Timer2Timer(TObject *Sender)
{
    static int c;
    if(portopen)
    {
        IL1->GetIcon(c++%3,F1->Icon);
        IL1->GetIcon(c++%3,Application->Icon);
    }
}
//---------------------------------------------------------------------------

void __fastcall TF1::L6Click(TObject *Sender)
{
    F2->ShowModal();
}
//---------------------------------------------------------------------------
void TF1::LoadWindow()
{
    int i,k,l;AnsiString tempa,tempb;
    i=0;
    while((M1->Lines->Strings[i++]!="[WINDOW]")&&(i<M1->Lines->Count));
    while((i<M1->Lines->Count-1)&&(M1->Lines->Strings[i].SubString(1,1)!="["))
    {
        k=M1->Lines->Strings[i].Pos("=");
        l=M1->Lines->Strings[i].Length();
        tempa=M1->Lines->Strings[i].SubString(1,k-1);tempa=tempa.Trim();
        tempb=M1->Lines->Strings[i].SubString(k+1,l-k);tempb=tempb.Trim();
        if(tempa=="TITLE") {F1->Caption=tempb;F2->Caption=tempb;Application->Title=tempb;}
        if(tempa=="PRINT")
        {
            if(tempb=="ON")
            {
                GroupBox3->Visible=true;
            }
            else
            {
                RB1->Checked=true;
                GroupBox3->Visible=false;
                OD1->Filter.Delete(70,22);
            }
        }
        i++;
    }

}
//---------------------------------------------------------------------------
void TF1::SaveWindow()
{
    M1->Lines->Add("[WINDOW]");
    M1->Lines->Add("TITLE="+F1->Caption);
    if(GroupBox3->Visible) M1->Lines->Add("PRINT=ON"); else M1->Lines->Add("PRINT=OFF");

}
//---------------------------------------------------------------------------

void __fastcall TF1::RE1KeyPress(TObject *Sender, char &Key)
{
    if(RB1->Checked)RE1->SelAttributes->Assign(font);
}
//---------------------------------------------------------------------------


void __fastcall TF1::topimgClick(TObject *Sender)
{
    static bool top=false;

    top=!top;
    if(top)
    {
//        F1->FormStyle=fsStayOnTop;
        IL1->GetBitmap(4,pic);
	SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
    }
    else
    {
//        F1->FormStyle=fsNormal;
        IL1->GetBitmap(3,pic);
	SetWindowPos(Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
    }
//    Comm->SetWindow(Handle);
        topimg->Picture->Assign(pic);
}
//---------------------------------------------------------------------------
void  __fastcall  TF1::WndProc(Messages::TMessage &Message)
{
    if((Message.Msg>=WM_COMM_RD_OK)&&(Message.Msg<=WM_COMM_WR_ERROR)) OnCommMsg(Message);
    TForm::WndProc(Message);
}
//---------------------------------------------------------------------------
void  __fastcall TF1::OnCommMsg(Messages::TMessage &Message)
{
 unsigned char buf[]={0,0,0,0};
 static bool Dhz=false;
 static char cha;
    switch(Message.Msg)
    {
       case WM_COMM_RD_OK:
            if(!StopDisplay)
            {
                if(N2->Checked)
                        CharToHex(RxChar,buf);
                else
                {
                    if(RxChar<0xa0)
                    {
                        buf[0]=RxChar;
                        if(Dhz) {buf[1]=cha;buf[2]=0;}else {buf[1]=0;}
                        Dhz=false;
                    }
                    else
                    {
                        if(Dhz)
                        {
                            Dhz=false;
                            buf[0]=cha;
                            buf[1]=RxChar;
                            buf[2]=0;
                        }
                        else
                        {
                            Dhz=true;
                            cha=RxChar;
                            buf[0]=0;
                        }
                    }
                }
                M1->SetSelTextBuf(buf);
            }
            RXcount+=Message.WParam;
            L7->Caption=IntToStr(RXcount);
            Comm->Read((char*)&RxChar,1,FALSE);
            break;
       case WM_COMM_WR_OK:
            TXcount+=Message.WParam;
            L8->Caption=IntToStr(TXcount);
            delete [] TxBuf;
            TxBuf=NULL;
            break;
       case WM_COMM_RD_ERROR:
//            Comm->ShowLastError();
            break;
       case WM_COMM_WR_ERROR:
            if(TxBuf!=NULL) delete[] TxBuf;
            TxBuf=NULL;
            ShowMessage(" 发送超时错误 ! ");
            break;
    }
}
//---------------------------------------------------------------------------


void __fastcall TF1::RG1Click(TObject *Sender)
{
    CBSUM->Enabled = (RG1->ItemIndex == 0);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -