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

📄 unit3.~cpp

📁 一个串口测试程序
💻 ~CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
extern int data;
unsigned int a;
unsigned int i=0,y;
double delay;
String str ="";
AnsiString x[60];
bool button=false;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm3::Timer1Timer(TObject *Sender)
{
 
Chart1->Series[0]->AddXY(i,data,TimeToStr(Time()));
if(i<60)
 x[i]=TimeToStr(Time());
 else
  {x[i%60]=TimeToStr(Time());
  Form3->Chart1->BottomAxis->SetMinMax(y++,y+59);
  }
i+=1;
}



 //---------------------------------------------------------------------------

void __fastcall TForm3::Chart1MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{     double tmpX,tmpY;
   Chart1->Series[0]->GetCursorValues(tmpX,tmpY);
    a=tmpX;

    str ="";
    str=str+"时间为"+x[a%60]+"";
    str=str+"数值为"+FloatToStr(tmpY);
    //x[a%60]
}
//---------------------------------------------------------------------------


void __fastcall TForm3::Button1Click(TObject *Sender)
{
  if (Timer1->Enabled ==true)
    {Timer1->Enabled =false;
    Button1->Caption ="继续";
    }
  else
    {Timer1->Enabled =true;
     Button1->Caption ="停止";
     }
}
//---------------------------------------------------------------------------

void __fastcall TForm3::Button2Click(TObject *Sender)
{
   if (button==false)
      {button=true;
       Button2->Caption ="停止取值";
      }
      else
    {button=false;
     Button2->Caption ="鼠标取值";
     }
}
//---------------------------------------------------------------------------

void __fastcall TForm3::Chart1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{

  Chart1->Repaint();
  Chart1->Canvas->TextOut(X+20,Y+20,"");
   if (button==true)
  { Chart1->Canvas->TextOut(X+15,Y-20,str);
  }


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


⌨️ 快捷键说明

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