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

📄 tv_form.~cpp

📁 一款通过串口控制Tuner的工具
💻 ~CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TV_FORM.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "YbCommDevice"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
        try
        {
                YbCommDevice1->PortNo=1;
                YbCommDevice1->Active=true;
        }
        catch(Exception &e)
        {
                ShowMessage("COM Device: "+e.Message);
        }
         if(YbCommDevice1->Active==True)
        {
            Button9->Visible=false;
            Button10->Visible=true;
        }
        else
        {
            Button10->Visible=false;
            Button9->Visible=true;
        }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
        char  Buf[8192];
        int i;
        int n=YbCommDevice1->Read(Buf,8192);
        if(n>0)  //Received char number
        {
            Buf[n]=0;
            Memo1->Text=Memo1->Text+Buf;
            if(ReadIF)
            {
                ReadIF=false;
                Panel41->Caption=Buf[0];
                Panel42->Caption=Buf[1];
                Panel43->Caption=Buf[2];
                Panel44->Caption=Buf[3];
                Panel45->Caption=Buf[5];
                Panel46->Caption=Buf[6];
                Panel47->Caption=Buf[7];
                Panel48->Caption=Buf[8];
            }
            if(ReadTuner)
            {
                ReadTuner=false;
                Panel17->Caption=Buf[0];
                Panel18->Caption=Buf[1];
                Panel19->Caption=Buf[2];
                Panel20->Caption=Buf[3];
                Panel21->Caption=Buf[5];
                Panel22->Caption=Buf[6];
                Panel23->Caption=Buf[7];
                Panel24->Caption=Buf[8];
            }
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button5Click(TObject *Sender)
{
        YbCommDevice1->Active==false;
        Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
YbCommDevice1->SettingsDialog(this,true);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
  int nBytes = 0;
  char Buffer[1000], *EndPtr;
  AnsiString t,s = Edit7->Text.Trim();
  while(s.Length()>0)
   {
     int p = s.Pos(' '); //????
     if(p>0)
      {
        t = s.SubString(1,p-1);
        s = s.SubString(p+1,s.Length()).Trim();
        Buffer[nBytes++] = strtol(t.c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
     else //?1ê£??×?oóò???×??ú
      {
        t = s;
        s = "";
        Buffer[nBytes++] = strtol(t.c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
   }
   Buffer[0]=Buffer[0]|0x20;
  YbCommDevice1->Write(Buffer,nBytes);
  
  ReadIF=true;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button6Click(TObject *Sender)
{
        Memo1->Lines->Clear();        
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button10Click(TObject *Sender)
{
        if(YbCommDevice1->Active==true)
        {
            YbCommDevice1->Active=false;
            Button10->Visible=false;
            Button9->Visible=true;
            }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button9Click(TObject *Sender)
{
         if(YbCommDevice1->Active==false)
        {
            YbCommDevice1->Active=true;
            Button9->Visible=false;
            Button10->Visible=true;
            }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  int nBytes = 0;
  char Buffer[1000], *EndPtr;
  AnsiString t,s = Edit7->Text.Trim();
  while(s.Length()>0)
   {
     int p = s.Pos(' '); //????
     if(p>0)
      {
        t = s.SubString(1,p-1);
        s = s.SubString(p+1,s.Length()).Trim();
        Buffer[nBytes++] = strtol(t.c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
     else //?1ê£??×?oóò???×??ú
      {
        t = s;
        s = "";
        Buffer[nBytes++] = strtol(t.c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
   }
   Buffer[0]=Buffer[0]|0x20;
  YbCommDevice1->Write(Buffer,nBytes);
  
  ReadTuner=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int nBytes = 0;
  int i;
  char Buffer[1000], *EndPtr;
  AnsiString s[5],t[5];
  //AnsiString t,s;
 t[1]= s[1] = Edit1->Text.Trim();
 t[2]= s[2] = Edit2->Text.Trim();
 t[3]= s[3] = Edit3->Text.Trim();
  t[4]=s[4] = Edit4->Text.Trim();
 t[0]= s[0]= Edit5->Text.Trim();
  //s=s5+s1=s2+s3+s4;
 // s=s5;
 // t=s;
   for(i=0;i<5 ;i++)
   { nBytes = 0;
      while(s[i].Length()>0)
   {
     int p = s[i].Pos(' '); //????
     if(p>0)
      {
        t[i] = s[i].SubString(1,p-1);
        s[i] = s[i].SubString(p+1,s[i].Length()).Trim();
        Buffer[nBytes++] = strtol(t[i].c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
     else //?1ê£??×?oóò???×??ú
      {
        t[i] = s[i];
        s[i] = "";
        Buffer[nBytes++] = strtol(t[i].c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
   }
    if(i==0)
   Buffer[0]=Buffer[0]|0xa0;
  YbCommDevice1->Write(Buffer,nBytes);
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button8Click(TObject *Sender)
{
  int nBytes = 0;
  int i;
  char Buffer[1000], *EndPtr;
  AnsiString s[4],t[4];
  //AnsiString t,s;
 t[1]= s[1] = Edit8->Text.Trim();
 t[2]= s[2] = Edit9->Text.Trim();
 t[3]= s[3] = Edit10->Text.Trim();
 t[0]= s[0]= Edit11->Text.Trim();
  //s=s5+s1=s2+s3+s4;
 // s=s5;
 // t=s;
   for(i=0;i<4 ;i++)
   { nBytes = 0;
      while(s[i].Length()>0)
   {
     int p = s[i].Pos(' '); //????
     if(p>0)
      {
        t[i] = s[i].SubString(1,p-1);
        s[i] = s[i].SubString(p+1,s[i].Length()).Trim();
        Buffer[nBytes++] = strtol(t[i].c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
     else //?1ê£??×?oóò???×??ú
      {
        t[i] = s[i];
        s[i] = "";
        Buffer[nBytes++] = strtol(t[i].c_str(), &EndPtr, 16); //ê?áù????×?·?′?×a3é×??ú
      }
   }
   if(i==0)
   Buffer[0]=Buffer[0]|0x80;
  YbCommDevice1->Write(Buffer,nBytes);
   }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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