📄 unit1.~cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "bsSkinData"
#pragma link "BusinessSkinForm"
#pragma link "YbCommDevice"
#pragma link "bsSkinCtrls"
#pragma link "bsSkinTabs"
#pragma link "bsSkinBoxCtrls"
#pragma resource "*.dfm"
TForm1 *Form1;
byte Rcvbuf[256];
byte Sndbuf[256];
unsigned int RbufLength;
unsigned int SbufLength=5;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
this->bsSkinButton3->Enabled=false;
this->bsSkinButton4->Enabled=false;
this->bsSkinButton5->Enabled=false;
this->channel1=false;
this->channel2=false;
this->channel3=false;
Series1->LinePen->Width = 1;
Series1->AutoRepaint = false;
Series2->LinePen->Width = 1;
Series2->AutoRepaint = false;
Series3->LinePen->Width = 1;
Series3->AutoRepaint = false;
Series4->LinePen->Width = 1;
Series4->AutoRepaint = false;
Series5->LinePen->Width = 1;
Series5->AutoRepaint = false;
Series6->LinePen->Width = 1;
Series6->AutoRepaint = false;
Tempe1Chart->BackColor = clBlack;
Tempe1Chart->BottomAxis->Automatic = false;
Tempe1Chart->BottomAxis->Minimum = 0;
Tempe1Chart->BottomAxis->Maximum = 50;
Tempe1Chart->BottomAxis->Increment = 0;
Tempe1Chart->BottomAxis->Grid->Visible = true;
Tempe1Chart->BottomAxis->Grid->Color = TColor(0x202020);
Tempe1Chart->LeftAxis->Automatic = false;
Tempe1Chart->LeftAxis->Minimum = -40;
Tempe1Chart->LeftAxis->Maximum = 100;
Tempe1Chart->LeftAxis->Increment = 0;
Tempe1Chart->LeftAxis->Grid->Visible = true;
Tempe1Chart->LeftAxis->Grid->Color = TColor(0x202020);
Tempe2Chart->BackColor = clBlack;
Tempe2Chart->BottomAxis->Automatic = false;
Tempe2Chart->BottomAxis->Minimum = 0;
Tempe2Chart->BottomAxis->Maximum = 50;
Tempe2Chart->BottomAxis->Increment = 0;
Tempe2Chart->BottomAxis->Grid->Visible = true;
Tempe2Chart->BottomAxis->Grid->Color = TColor(0x202020);
Tempe2Chart->LeftAxis->Automatic = false;
Tempe2Chart->LeftAxis->Minimum = -40;
Tempe2Chart->LeftAxis->Maximum = 100;
Tempe2Chart->LeftAxis->Increment = 0;
Tempe2Chart->LeftAxis->Grid->Visible = true;
Tempe2Chart->LeftAxis->Grid->Color = TColor(0x202020);
Tempe3Chart->BackColor = clBlack;
Tempe3Chart->BottomAxis->Automatic = false;
Tempe3Chart->BottomAxis->Minimum = 0;
Tempe3Chart->BottomAxis->Maximum = 50;
Tempe3Chart->BottomAxis->Increment = 0;
Tempe3Chart->BottomAxis->Grid->Visible = true;
Tempe3Chart->BottomAxis->Grid->Color = TColor(0x202020);
Tempe3Chart->LeftAxis->Automatic = false;
Tempe3Chart->LeftAxis->Minimum = -40;
Tempe3Chart->LeftAxis->Maximum = 100;
Tempe3Chart->LeftAxis->Increment = 0;
Tempe3Chart->LeftAxis->Grid->Visible = true;
Tempe3Chart->LeftAxis->Grid->Color = TColor(0x202020);
TempeChart->BackColor = clBlack;
TempeChart->BottomAxis->Automatic = false;
TempeChart->BottomAxis->Minimum = 0;
TempeChart->BottomAxis->Maximum = 50;
TempeChart->BottomAxis->Increment = 0;
TempeChart->BottomAxis->Grid->Visible = true;
TempeChart->BottomAxis->Grid->Color = TColor(0x202020);
TempeChart->LeftAxis->Automatic = false;
TempeChart->LeftAxis->Minimum = -40;
TempeChart->LeftAxis->Maximum = 100;
TempeChart->LeftAxis->Increment = 0;
TempeChart->LeftAxis->Grid->Visible = true;
TempeChart->LeftAxis->Grid->Color = TColor(0x202020);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bsSkinButton2Click(TObject *Sender)
{
Comm->SettingsDialog(this,true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bsSkinButton1Click(TObject *Sender)
{
try
{
Comm->Active = true;
}
catch(Exception &e)
{
Application->MessageBox(e.Message.c_str(),"错误信息",MB_OK|MB_ICONSTOP);
}
//判断是否打开
if(Comm->Active)
{
bsSkinStatusPanel1->Caption="通信状态:COM"+IntToStr(Comm->PortNo)+"打开";
this->bsSkinButton3->Enabled=true;
this->bsSkinButton4->Enabled=true;
this->bsSkinButton5->Enabled=true;
Comm->PackageType = cptFrameTimeout;
Comm->UsePackage=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CommPackage(TObject *Sender, int NotifyType)
{
unsigned int i;
float Redvalue;
AnsiString viewstring;
viewstring="";
RbufLength=Comm->ReadPackage(Rcvbuf,256);;
if(RbufLength>=5)
{
viewstring=IntToStr(Rcvbuf[2])+"."+IntToStr(Rcvbuf[3]);
Redvalue=Rcvbuf[2]+(float)(Rcvbuf[3])/100;
switch(Rcvbuf[1])
{
case 0x01:
Label1->Caption="通道1温度:"+viewstring+"℃";
Series1->Add(Redvalue);
Series4->Add(Redvalue);
break;
case 0x02:
Label2->Caption="通道2温度:"+viewstring+"℃";
Series2->Add(Redvalue);
Series5->Add(Redvalue);
break;
case 0x03:
Label3->Caption="通道3温度:"+viewstring+"℃";
Series3->Add(Redvalue);
Series6->Add(Redvalue);
break;
default:
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Click(TObject *Sender)
{
if(N4->Checked)
{
N4->Checked=false;
bsSkinExPanel1->Visible=false;
}
else
{
N4->Checked=true;
bsSkinExPanel1->Visible=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bsSkinExPanel1Close(TObject *Sender)
{
N4->Checked=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
try
{
Comm->Active = false;
}
catch(Exception &e)
{
Application->MessageBox(e.Message.c_str(),"错误信息",MB_OK|MB_ICONSTOP);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bsSkinButton3Click(TObject *Sender)
{
AnsiString viewstring;
Sndbuf[0]=0x55;
Sndbuf[1]=0x01;
Sndbuf[3]=0x00;
Sndbuf[4]=0xff;
channel1=!channel1;
if(this->channel1)
Sndbuf[2]=0x01;
else
Sndbuf[2]=0x02;
Comm->WritePackage(Sndbuf,SbufLength);
if(channel1)
viewstring="通道1:开";
else
viewstring="通道1:关";
if(channel2)
viewstring+=";通道2:开";
else
viewstring+=";通道2:关";
if(channel3)
viewstring+=";通道3:开";
else
viewstring+=";通道3:关";
this->bsSkinStatusPanel4->Caption=viewstring;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bsSkinButton4Click(TObject *Sender)
{
AnsiString viewstring;
Sndbuf[0]=0x55;
Sndbuf[1]=0x02;
Sndbuf[3]=0x00;
Sndbuf[5]=0xff;
channel2=!channel2;
if(this->channel2)
Sndbuf[2]=0x01;
else
Sndbuf[2]=0x02;
Comm->WritePackage(Sndbuf,SbufLength);
if(channel1)
viewstring="通道1:开";
else
viewstring="通道1:关";
if(channel2)
viewstring+=";通道2:开";
else
viewstring+=";通道2:关";
if(channel3)
viewstring+=";通道3:开";
else
viewstring+=";通道3:关";
this->bsSkinStatusPanel4->Caption=viewstring;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bsSkinButton5Click(TObject *Sender)
{
AnsiString viewstring;
Sndbuf[0]=0x55;
Sndbuf[1]=0x03;
Sndbuf[3]=0x00;
Sndbuf[5]=0xff;
channel3=!channel3;
if(this->channel3)
Sndbuf[2]=0x01;
else
Sndbuf[2]=0x02;
Comm->WritePackage(Sndbuf,SbufLength);
if(channel1)
viewstring="通道1:开";
else
viewstring="通道1:关";
if(channel2)
viewstring+=";通道2:开";
else
viewstring+=";通道2:关";
if(channel3)
viewstring+=";通道3:开";
else
viewstring+=";通道3:关";
this->bsSkinStatusPanel4->Caption=viewstring;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bsSkinButton6Click(TObject *Sender)
{
try
{
Comm->Active = false;
}
catch(Exception &e)
{
Application->MessageBox(e.Message.c_str(),"错误信息",MB_OK|MB_ICONSTOP);
}
//判断是否打开
if(!Comm->Active)
{
bsSkinStatusPanel1->Caption="通信状态:COM"+IntToStr(Comm->PortNo)+"关闭";
this->bsSkinButton3->Enabled=false;
this->bsSkinButton4->Enabled=false;
this->bsSkinButton5->Enabled=false;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -