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

📄 unit1.cpp

📁 LMS软件是用来进行自适应滤波的最小均方误差算法
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    }
    i=0; StopBit = 0;
    while((M1->Lines->Strings[i++]!="[STOPBIT]")&&(i<M1->Lines->Count));
    while((i<M1->Lines->Count-1)&&(M1->Lines->Strings[i].SubString(1,1)!="["))
    {
        AnsiString tmp;
        tmp = M1->Lines->Strings[i].SubString(1,M1->Lines->Strings[i].Pos("=")-1);
        if(tmp == "STOPBIT")
        {
            tmp=M1->Lines->Strings[i++].SubString(M1->Lines->Strings[i].Pos("=")+1,M1->Lines->Strings[i].Length()-M1->Lines->Strings[i].Pos("="));
            StopBit = StrToInt(tmp);
        }
    }

    for(i=1;i<PORT[0].Value.ToInt();i++) CB1->Items->Add(PORT[i].Description);
    CB1->ItemIndex=StrToInt(PORT[0].Description);
    for(i=1;i<BAUD[0].Value.ToInt();i++) CB2->Items->Add(BAUD[i].Description);
    CB2->ItemIndex=StrToInt(BAUD[0].Description);
    for(i=1;i<BYTEs[0].Value.ToInt();i++) CB3->Items->Add(BYTEs[i].Description);
    CB3->ItemIndex=StrToInt(BYTEs[0].Description);
}
//---------------------------------------------------------------------------
void TF1::LoadTool()
{   int i,j,k,l;AnsiString tempa,tempb,TM[]={"[TOOL1]","[TOOL2]","[TOOL3]","[TOOL4]"};
    for(j=0;j<4;j++)
    {
        i=0;Tool[j].Value="";
        while((M1->Lines->Strings[i++]!=TM[j])&&(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=="BMP") Tool[j].FileName=tempb;
            if(tempa=="HINT") Tool[j].Hint=tempb;
            if(tempa=="VALUE")
            {
                Tool[j].Value="0x"+tempb;
                ParaFilter(&(Tool[j].Value),&k,&l);
                if(k!=1) Tool[j].Value=Tool[j].Value.SubString(1,Tool[j].Value.Pos(" ")-1);
            }
            i++;
        }
    }
    try{SB1->Hint=Tool[0].Hint;SB1->Glyph->LoadFromFile(Tool[0].FileName);} catch (...){SB1->Caption=SB1->Hint;}
    try{SB2->Hint=Tool[1].Hint;SB2->Glyph->LoadFromFile(Tool[1].FileName);} catch (...){SB2->Caption=SB2->Hint;}
    try{SB3->Hint=Tool[2].Hint;SB3->Glyph->LoadFromFile(Tool[2].FileName);} catch (...){SB3->Caption=SB3->Hint;}
    try{SB4->Hint=Tool[3].Hint;SB4->Glyph->LoadFromFile(Tool[3].FileName);} catch (...){SB4->Caption=SB4->Hint;}
}
//---------------------------------------------------------------------------
void TF1::LoadCMD()
{
    int  i=0,j=1;AnsiString temp;
    CMD[0].Name="0";CMD[0].Count=0;
    while((M1->Lines->Strings[i++]!="[CMD]")&&(i<M1->Lines->Count));
    while((i<M1->Lines->Count-1)&&(M1->Lines->Strings[i].SubString(1,1)!="[")&&(j<CmdMax))
    {   int k=M1->Lines->Strings[i].Pos("=");
        CMD[j].Name=M1->Lines->Strings[i].SubString(1,k-1);
        CMD[j].Value="0X"+M1->Lines->Strings[i].SubString(k+1,M1->Lines->Strings[i].Length()-k+1);
        ParaFilter(&(CMD[j].Value),&(CMD[j].Count),&(CMD[j].Size));
        CMD[j].Count--;
        CMD[j].Value=CMD[j].Value.Trim();
        CMD[j].Value=CMD[j].Value.Delete(1,2);
        k=CMD[j].Value.Pos(" ");
        if(k)
        {
            CMD[j].Parameter=CMD[j].Value.SubString(k,CMD[j].Value.Length()-k+1);
            CMD[j].Value=CMD[j].Value.SubString(1,k-1);
            CMD[j].Parameter=CMD[j].Parameter.Trim();
        }
        if(CMD[j].Name.Trim()!="DEFAULT") j++; else CMD[0].Size=StrToInt("0x"+CMD[j].Value.SubString(1,2));
        i++;
    }
    CMD[0].Count=j;
    for(i=1;i<CMD[0].Count;i++)
    {   temp=temp.StringOfChar((char)((char)i+0x30),1);
        CB4->Items->Add(temp+CMD[i].Name);
        CMD[i].OldPara=CMD[i].Parameter;
    }
    if(CMD[0].Count>CMD[0].Size) CB4->ItemIndex=CMD[0].Size; else  CB4->ItemIndex=0;
    CB4->Hint=CMD[CB4->ItemIndex+1].Name;
}
//---------------------------------------------------------------------------
void TF1::ParaFilter(AnsiString *a,int *count,int *byte)
{   int i;AnsiString temp,temp1;
    *count=0;*byte=0;
    temp=a->Trim();
    temp=temp.UpperCase();
    *a="";
    while(temp.Length()!=0)
    {
        if(temp.Pos(" ")!=0)
        {
            temp1=temp.SubString(1,temp.Pos(" ")-1);
            temp=temp.Delete(1,temp.Pos(" "));
        }
        else
        {
            temp1=temp;
            temp="";
        }
        temp=temp.Trim();
        if(temp1.SubString(1,2)=="0X")
        {
            for(int i=3;i<=temp1.Length();i++)
            {
                if((temp1.SubString(i,1)>="0")&&(temp1.SubString(i,1)<="9")) continue;
                if((temp1.SubString(i,1)>="A")&&(temp1.SubString(i,1)<="F")) continue;
                temp1=temp1.Delete(i--,1);
            }
            *byte=temp1.Length()/2-1;
            if(temp1.Length()==0) temp1="0";else temp1="0x"+temp1.Delete(1,2);
        }
        else
        {
            for(int i=1;i<=temp1.Length();i++)
            {
                if(temp1.SubString(i,1)=="-") continue;
                if((temp1.SubString(i,1)>="0")&&(temp1.SubString(i,1)<="9")) continue;
                temp1=temp1.Delete(i--,1);
            }
            *byte=temp1.Length()/2;
            if(temp1.Length()==0) temp1="0";
        }
        (*a)+=temp1+" ";
        (*count)++;
    }
    if(*a=="") *a="0";
    if(*byte<=0) *byte=1;
}
//---------------------------------------------------------------------------


void __fastcall TF1::B2Click(TObject *Sender)
{
    int i,j,k,count,byte;AnsiString temp,temp1,temp2;
    char buf[1000];
    k=CB4->ItemIndex+1;
    buf[0]='\\';
    buf[1]='C';
    buf[2]='M';
    buf[3]='D';
    buf[4]=k+0x30;
    temp="";
    if(CMD[k].Count)
    {
        temp1=E1->Text;
        ParaFilter(&temp1,&count,&byte);
        if(CMD[k].Count>count) {ShowMessage("   参数有误!  ");return;}
        for(i=0;i<CMD[k].Count;i++)
        {
            j=temp1.Pos(" ");
            if(j!=0)
                temp2=IntToHex(StrToInt(temp1.SubString(1,j-1)),CMD[k].Size*2);
            else
                temp2=IntToHex(StrToInt(temp1),CMD[k].Size*2);
            for(int x=0;x<CMD[k].Size;x++)
            {
                temp=temp+temp2.SubString(temp2.Length()-1,2);
                temp2=temp2.Delete(temp2.Length()-1,2);
            }
            temp1=temp1.Delete(1,j);
            temp1=temp1.Trim();
            if(j==0) break;
        }
    }
    StrPCopy(&buf[5],temp);
    if(Sender==B2)
    {   TColor temp;
        RE1->SelAttributes->Style=TFontStyles()<< fsBold;
        temp=RE1->SelAttributes->Color;RE1->SelAttributes->Color=clBlue;
        RE1->SetSelTextBuf(buf);
        RE1->SelAttributes->Color=temp;
        RE1->SelAttributes->Style=TFontStyles()>> fsBold;
    }
    if(Sender==B1)
    {
        if(!TxBuf==NULL) return;
        if(!portopen) {ShowMessage(" 端口未打开 ! "); return;}
        StrPCopy(buf,CMD[k].Value);
        for(i=0;i<CMD[k].Value.Length()/2;i++) buf[i]=HexToChar(&buf[i*2]);
        StrPCopy(&buf[i],temp);
        for(j=0;j<temp.Length()/2;j++) buf[i+j]=HexToChar(&buf[i+j*2]);
        TxBuf=new char[i+j+1];
        if(TxBuf==NULL) {ShowMessage("   分配内存错误!  ");return;}
        memcpy(TxBuf,buf,i+j+1);
        if(Comm->Write(TxBuf,i+j,FALSE)==(DWORD)-1)
        {
            ShowMessage(" 发送错误 !  ");
            delete [] TxBuf;
            TxBuf=NULL;
        }
    }
}
//---------------------------------------------------------------------------


void __fastcall TF1::SB1Click(TObject *Sender)
{
    int i;AnsiString temp;
    if(TxBuf!=NULL) return;
    if(!portopen) {ShowMessage(" 端口未打开 ! "); return;}
    if(Sender==SB1) temp=Tool[0].Value;
    if(Sender==SB2) temp=Tool[1].Value;
    if(Sender==SB3) temp=Tool[2].Value;
    if(Sender==SB4) temp=Tool[3].Value;
    temp=temp.Delete(1,2);temp=temp.Trim();
    TxBuf=new char[temp.Length()+1];
    if(TxBuf==NULL) {ShowMessage("   分配内存错误!  ");return;}
    StrPCopy(TxBuf,temp);
    for(i=0;i<(temp.Length()/2);i++) TxBuf[i]=HexToChar(&TxBuf[i*2]);
    if(Comm->Write(TxBuf,i,FALSE)==(DWORD)-1)
    {
        ShowMessage(" 发送错误 !  ");
        delete [] TxBuf;
        TxBuf=NULL;
    }
}
//---------------------------------------------------------------------------

void __fastcall TF1::SB5Click(TObject *Sender)
{
    if(TxBuf!=NULL) return;
    if(!portopen) {ShowMessage(" 端口未打开 ! "); return;}
    if(RB1->Checked)
    {
        unsigned char temp[500];
        unsigned char *buf1;
        int i,j,k,c=0;bool hz=false;
        i=0;j=0;
        k=RE1->Text.Length();
        buf1=new unsigned char[k+1];
        if(buf1==NULL) {ShowMessage("   分配内存错误!   ");return;}
        StrPCopy(buf1,RE1->Text);
        for(int q=0;q<k;q++) if((buf1[q]<=0xa0)&&(buf1[q+1]>0xa0)&&(buf1[q+2]>0xa0)) c++;
        TxBuf=new unsigned char[k+c*6];
        if(TxBuf==NULL) {delete[] buf1;ShowMessage("   分配内存错误!   ");delete[] buf1;return;}
        while((j<(k))&&(i<(k+1000)))
        {
            if((buf1[j]=='\\')&&(buf1[j+1]=='C')&&(buf1[j+2]=='M')&&(buf1[j+3]=='D'))
            {   j+=4;
                c=(int)buf1[j++]-0x30;
                StrPCopy(temp,CMD[c].Value);
                for(int l=0;l<CMD[c].Value.Length()/2;l++) TxBuf[i++]=HexToChar(&temp[l*2]);
                for(int l=0;l<CMD[c].Count*CMD[c].Size;l++) TxBuf[i++]=HexToChar(&buf1[j+l*2]);
                j+=CMD[c].Count*2*CMD[c].Size;
            }
            else
            {
                if((CB5->Checked)&&(buf1[j]>0xa0)&&(buf1[j+1]>0xa0)&&(hz==false))
                {   AnsiString atemp;int mm,mn;
                    hz=true;atemp="0X"+E4->Text.Trim();ParaFilter(&atemp,&mm,&mn);
                    if(mm!=1) atemp=atemp.SubString(1,atemp.Pos(" ")-1);
                    atemp=atemp.Delete(1,2); StrPCopy(temp,atemp);
                    for(int l=0;l<atemp.Length()/2;l++) TxBuf[i++]=HexToChar(&temp[l*2]);
                }
                if((CB5->Checked)&&(buf1[j]<=0xa0)&&(hz==true))
                {   AnsiString atemp;int mm,mn;
                    hz=false;atemp="0X"+E5->Text.Trim();ParaFilter(&atemp,&mm,&mn);
                    if(mm!=1) atemp=atemp.SubString(1,atemp.Pos(" ")-1);
                    atemp=atemp.Delete(1,2);StrPCopy(temp,atemp);
                    for(int l=0;l<atemp.Length()/2;l++) TxBuf[i++]=HexToChar(&temp[l*2]);
                }
                TxBuf[i++]=buf1[j];
                j++;
            }
        }
        if(Comm->Write(TxBuf,i,FALSE)==(DWORD)-1)
        {
            ShowMessage(" 发送错误 !  ");
            delete [] TxBuf;
            TxBuf=NULL;
        }
        delete[] buf1;
    }
    if(RB2->Checked)
    {
        if(RB3->Checked) RE1->Print(F1->Caption);
        else
        {   Printer()->Title=OD1->FileName;
            Printer()->BeginDoc();
            Printer()->Canvas->CopyRect(I1->ClientRect,I1->Canvas,I1->ClientRect);
            Printer()->EndDoc();
        }
    }
}
//---------------------------------------------------------------------------


void __fastcall TF1::N17Click(TObject *Sender)
{
    RE1->SelectAll();
}
//---------------------------------------------------------------------------

void __fastcall TF1::N11Click(TObject *Sender)
{
    RE1->Undo();
}
//---------------------------------------------------------------------------

void __fastcall TF1::N13Click(TObject *Sender)
{
    RE1->CutToClipboard();
}
//---------------------------------------------------------------------------

void __fastcall TF1::N14Click(TObject *Sender)
{
    RE1->CopyToClipboard();
}
//---------------------------------------------------------------------------

void __fastcall TF1::N15Click(TObject *Sender)
{
    RE1->PasteFromClipboard();
}
//---------------------------------------------------------------------------

void __fastcall TF1::D1Click(TObject *Sender)
{
    RE1->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TF1::PM2Popup(TObject *Sender)
{
    if(RB1->Checked) N18->Enabled=false; else N18->Enabled=true;
    if(RE1->SelLength==0){N14->Enabled=false;N13->Enabled=false;}else{N14->Enabled=true;N13->Enabled=true;}
    if(RE1->Text.Length()==0){N17->Enabled=false;D1->Enabled=false;}else{N17->Enabled=true;D1->Enabled=true;}
    if(Clipboard()->HasFormat(CF_TEXT)) N15->Enabled=true;else N15->Enabled=false;

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



void __fastcall TF1::B3Click(TObject *Sender)
{
    PD1->Execute();
}
//---------------------------------------------------------------------------

void __fastcall TF1::RB1Click(TObject *Sender)
{
    if(RB1->Checked)
    {
        AnsiString temp;unsigned char a;
        int start,length;
        I1->Visible=false;
        RE1->Visible=true;
        B3->Enabled=false;
        CB5->Enabled=true;
        CB5->OnClick(Sender);
        L3->Enabled=true;
        L4->Enabled=true;
        CB4->Enabled=true;
        E1->Enabled=true;
        B1->Enabled=true;
        B2->Enabled=true;
        RE1->SelectAll();
        RE1->SelAttributes->Assign(font);
        RE1->SelStart=1;
        RE1->SelLength=0;
        RB3->Enabled=false;
        RB4->Enabled=false;
        start=0;length=RE1->Text.Length();
        while((start=RE1->FindTextA("\\CMD",start,length,TSearchTypes()<<stMatchCase))!=-1)
        {
             temp=RE1->Text.SubString(start+5,1);
             StrPCopy(&a,temp);
             RE1->SelStart=start;
             RE1->SelLength=CMD[a-0x30].Count*CMD[a-0x30].Size*2+5;
             RE1->SelAttributes->Style=TFontStyles()<< fsBold;
             RE1->SelAttributes->Color=clBlue;
             start+=RE1->SelLength;
             length=RE1->Text.Length()-start;
        }
        RE1->SelStart=1;
        RE1->SelLength=0;
        RE1->SelAttributes->Assign(font);
    }
    else
    {
        B3->Enabled=true;
        CB5->Enabled=false;
        E4->Enabled=false;
        E5->Enabled=false;
        L1->Enabled=false;
        L2->Enabled=false;
        L3->Enabled=false;
        L4->Enabled=false;
        CB4->Enabled=false;
        E1->Enabled=false;
        B1->Enabled=false;
        B2->Enabled=false;
        RB3->Enabled=true;
        RB4->Enabled=true;
        RB3Click(Sender);
    }

⌨️ 快捷键说明

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