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

📄 main.~cpp

📁 平台:c++ builder V6.0 功能:利用串口设备通讯,
💻 ~CPP
📖 第 1 页 / 共 3 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "main.h"
#include "about.h"
#include "Unit_Set_Comm.h"
#include "Unit_Link.h"
#include "Unit_File.h"
#include "Unit_Print.h"
#include "Unit_Company.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm_Main *Form_Main;
//---------------------------------------------------------------------------
__fastcall TForm_Main::TForm_Main(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm_Main::Timer1Timer(TObject *Sender)
{
AnsiString CMD,RS,rs;
int M;
static bool F=false;
int Y;

if(F){StatusBar1->Panels->Items[0]->Text=" ●";}
else {StatusBar1->Panels->Items[0]->Text=" ○";}
StatusBar1->Refresh();
F=!F;

if(!COMM.Linked) Link_Device();
if(!COMM.Linked) {
   Close_All_Lamp();
   Panel3->Enabled=false;
   return;
   }
Panel3->Enabled=true;

CMD="01010ABC0001";
Label_Com_Hint->Caption="发送联机询问:检查M700";
SendString(CMD);//发送联机询问:读取M700(地址\X0ABC)检查是否设备运行中
RS=ReadString();

if(!Is_Running(RS)){
   Shape_1_Stop->Brush->Color=clRed;    Shape_2_Stop->Brush->Color=clRed;
   Shape_3_Stop->Brush->Color=clRed;    Shape_1_Running->Brush->Color=clGreen;
   Shape_2_Running->Brush->Color=clGreen;       Shape_3_Running->Brush->Color=clGreen;
   Shape_1_Warning->Brush->Color=clOlive;       Shape_2_Warning->Brush->Color=clOlive;
   Shape_3_Warning->Brush->Color=clOlive;
   BitBtn_Set->Enabled=true;
   BitBtn_Reset->Enabled=true;          BitBtn_Start_All->Enabled=true;
   BitBtn_Start1->Enabled=REPORT.CHECK_1;        BitBtn_Start2->Enabled=REPORT.CHECK_2;
   BitBtn_Start3->Enabled=REPORT.CHECK_3;        BitBtn_StopAll->Enabled=false;
   BitBtn_Stop1->Enabled=false;         BitBtn_Stop2->Enabled=false;
   BitBtn_Stop3->Enabled=false;         BitBtn_Report->Enabled=false;
   BitBtn_End->Enabled=false;
   Label_Com_Hint->Caption=Label_Com_Hint->Caption+"\nM700=0";
   //发送总循环次数到各工位D1,D2,D3
   int TMS;
   if(CHK.Info_Send){
   String tms;
   TMS=CHK.Total_Times-1;
   tms=tms.IntToHex(TMS,4);
   CMD="01061001"+tms;//->D1
   SendString(CMD);
   RS=ReadString();
   CMD="01061002"+tms;//->D2
   SendString(CMD);
   RS=ReadString();
   CMD="01061003"+tms;//->D3
   SendString(CMD);
   RS=ReadString();
   //发送吹粉尘时间
   TMS=CHK.Spray_Time;
   tms=tms.IntToHex(TMS,4);
   CMD="01061004"+tms;//->D4
   SendString(CMD);
   RS=ReadString();
   CMD="01061005"+tms;//->D5
   SendString(CMD);
   RS=ReadString();
   CMD="01061006"+tms;//->D6
   SendString(CMD);
   RS=ReadString();
   //发送但次循环进出次数
   TMS=CHK.InOut_Time-1;
   tms=tms.IntToHex(TMS,4);
   CMD="01061007"+tms;//->D7
   SendString(CMD);
   RS=ReadString();
   CMD="01061008"+tms;//->D8
   SendString(CMD);
   RS=ReadString();
   CMD="01061009"+tms;//->D9
   SendString(CMD);
   RS=ReadString();
   //发送间歇时间
   TMS=CHK.Break_Time;
   tms=tms.IntToHex(TMS,4);
   CMD="0106100A"+tms;//->D10
   SendString(CMD);
   RS=ReadString();
   CMD="0106100B"+tms;//->D11
   SendString(CMD);
   RS=ReadString();
   CMD="0106100C"+tms;//->D12
   SendString(CMD);
   RS=ReadString();
   CHK.Checking=false;
   CHK.Info_Send=false;
   }
   return;
   }
else if(CHK.Info_Read){


   //读取总进度限D1
   CMD="010310010001";
   SendString(CMD);
   RS=ReadString();
   Y=Read_Value(RS);
   CHK.Total_Times=Y+1;
   ProgressBar_Total->Max=Y+1;
   //读取粉尘限D4
   CMD="010310040001";
   SendString(CMD);
   RS=ReadString();
   Y=Read_Value(RS);
   CHK.Spray_Time=Y;
   ProgressBar_Air->Max=Y;
   //读取卷收限D7
   CMD="010310070001";
   SendString(CMD);
   RS=ReadString();
   Y=Read_Value(RS);
   CHK.InOut_Time =Y+1;
   ProgressBar_In_Out->Max=Y+1;
   //读取间歇限D10
   CMD="0103100A0001";
   SendString(CMD);
   RS=ReadString();
   Y=Read_Value(RS);
   CHK.Break_Time=Y;
   ProgressBar_Pause->Max=Y;
   CHK.Checking=true;
   CHK.Info_Read=false;
   }
 if(F) Shape_Running->Brush->Color=clLime;
 else  Shape_Running->Brush->Color=clGreen;

   //BitBtn_Set->Enabled=false; BitBtn_Reset->Enabled=false;
   if(BitBtn_Start_All->Enabled)
      BitBtn_Start_All->Enabled=false;
   //BitBtn_Start1->Enabled=false;BitBtn_Start2->Enabled=false;BitBtn_Start3->Enabled=false;
   BitBtn_StopAll->Enabled=true;
   BitBtn_Stop1->Enabled=REPORT.CHECK_1;         BitBtn_Stop2->Enabled=REPORT.CHECK_2;
   BitBtn_Stop3->Enabled=REPORT.CHECK_3;         //BitBtn_Report->Enabled=false;

   CHK.ERR=false;
   CHK.Done=true;
   if(REPORT.CHECK_1) REPORT.E1=false;
   if(REPORT.CHECK_2) REPORT.E2=false;
   if(REPORT.CHECK_3) REPORT.E3=false;
   if(REPORT.CHECK_1) REPORT.F1=false;
   if(REPORT.CHECK_2) REPORT.F2=false;
   if(REPORT.CHECK_3) REPORT.F3=false;
CMD="010108C90001";
Label_Com_Hint->Caption="询问工位一是否运行:检查M201";
SendString(CMD);//发送工位一是否运行:读取M201(地址\X08C9)检查是否设备运行中
RS=ReadString();
if(!Is_Running(RS)){
  Shape_1_Stop->Brush->Color=clRed;
  Shape_1_Running->Brush->Color=clGreen;
  Shape_1_Warning->Brush->Color=clOlive;
  }
else{
  Shape_1_Running->Brush->Color=clLime;
  Shape_1_Stop->Brush->Color=clMaroon;
  Shape_1_Warning->Brush->Color=clOlive;
  REPORT.CHECK_1=true;
  }
CMD="010108330001";
SendString(CMD);//发送工位一是否故障:读取M51(地址\X0833)
RS=ReadString();
if(Is_Running(RS)){
  Shape_1_Stop->Brush->Color=clRed;
  Shape_1_Running->Brush->Color=clGreen;
  Shape_1_Warning->Brush->Color=clYellow;
  Label_Hint1->Caption="故障";
  REPORT.E1=true;
  REPORT.EE1.T=ProgressBar_Total->Position;
  REPORT.EE1.S=ProgressBar_In_Out->Position;
  CMD="010310320001";//读取D50
  SendString(CMD);
  RS=ReadString();
  Y=Read_Value(RS);
  REPORT.EE1.S=Y;
  CMD="010310330001";//读取D51
  SendString(CMD);
  RS=ReadString();
  Y=Read_Value(RS);
  REPORT.EE1.T=Y;
  CHK.ERR=CHK.ERR||REPORT.E1;
  }

CMD="010108CA0001";
SendString(CMD);//发送工位二是否运行:读取M202(地址\X08CA)检查是否设备运行中
RS=ReadString();
if(!Is_Running(RS)){
  Shape_2_Stop->Brush->Color=clRed;
  Shape_2_Running->Brush->Color=clGreen;
  Shape_2_Warning->Brush->Color=clOlive;
  }
else{
  Shape_2_Running->Brush->Color=clLime;
  Shape_2_Stop->Brush->Color=clMaroon;
  Shape_2_Warning->Brush->Color=clOlive;
  REPORT.CHECK_2=true;
  }
CMD="010108340001";
SendString(CMD);//发送工位二是否故障:读取M52(地址\X0834)
RS=ReadString();
if(Is_Running(RS)){
  Shape_2_Stop->Brush->Color=clRed;
  Shape_2_Running->Brush->Color=clGreen;
  Shape_2_Warning->Brush->Color=clYellow;
  Label_Hint2->Caption="故障";
  REPORT.E2=true;
  REPORT.EE2.T=ProgressBar_Total->Position;
  REPORT.EE2.S=ProgressBar_In_Out->Position;
  CMD="010310340001";//读取D52
  SendString(CMD);
  RS=ReadString();
  Y=Read_Value(RS);
  REPORT.EE2.S=Y;
  CMD="010310350001";//读取D53
  SendString(CMD);
  RS=ReadString();
  Y=Read_Value(RS);
  REPORT.EE2.T=Y;
  CHK.ERR=CHK.ERR||REPORT.E2;
  }
CMD="010108CB0001";
SendString(CMD);//发送工位三是否运行:读取M203(地址\X08CB)检查是否设备运行中
RS=ReadString();
if(!Is_Running(RS)){
  Shape_3_Stop->Brush->Color=clRed;
  Shape_3_Running->Brush->Color=clGreen;
  Shape_3_Warning->Brush->Color=clOlive;
  }
else{
  Shape_3_Running->Brush->Color=clLime;
  Shape_3_Stop->Brush->Color=clMaroon;
  Shape_3_Warning->Brush->Color=clOlive;
  REPORT.CHECK_3=true;
  }
CMD="010108350001";
SendString(CMD);//发送工位三是否故障:读取M53(地址\X0835)
RS=ReadString();
if(Is_Running(RS)){
  Shape_3_Stop->Brush->Color=clRed;
  Shape_3_Running->Brush->Color=clGreen;
  Shape_3_Warning->Brush->Color=clYellow;
  Label_Hint3->Caption="故障";
  REPORT.E3=true;
  REPORT.EE3.T=ProgressBar_Total->Position;
  REPORT.EE3.S=ProgressBar_In_Out->Position;
  CMD="010310360001";//读取D54
  SendString(CMD);
  RS=ReadString();
  Y=Read_Value(RS);
  REPORT.EE3.S=Y;
  CMD="010310370001";//读取D55
  SendString(CMD);
  RS=ReadString();
  Y=Read_Value(RS);
  REPORT.EE3.T=Y;
  CHK.ERR=CHK.ERR||REPORT.E3;
  }


//以下读进度
int SINGLE,X;
SINGLE=0;

CMD="01030E040001";
SendString(CMD);//:读取C4(地址\X0E04)---总进度
RS=ReadString();
X=Read_Value(RS);
ProgressBar_Total->Position=X;
Label_Total->Caption=String(X)+"/"+String(CHK.Total_Times);
Label_Com_Hint->Caption="读取总进度:C4"+String(Read_Value(RS));
//////


CMD="010306010001";
SendString(CMD);//:读取T1(地址\X0601)---吹粉尘
RS=ReadString();
X=Read_Value(RS);
ProgressBar_Air->Position=X;
SINGLE=X;
Label_Com_Hint->Caption="读取粉尘时间T1="+String(SINGLE);
Label_Air->Caption=String(X)+"/"+String(CHK.Spray_Time);

int xxx;
X=0;
if(REPORT.CHECK_1){
   CMD="01030E010001";
   SendString(CMD);//:读取C1(地址\X0E01)---拉回
   RS=ReadString();
   }
xxx=Read_Value(RS);
if(xxx>0) X=xxx;
if(REPORT.CHECK_2){
   CMD="01030E020001";
   SendString(CMD);//:读取C2(地址\X0E02)---拉回
   RS=ReadString();
   }
xxx=Read_Value(RS);
if(xxx>0) X=xxx;
if(REPORT.CHECK_3){
   CMD="01030E030001";
   SendString(CMD);//:读取C3(地址\X0E03)---拉回
   RS=ReadString();
   }
xxx=Read_Value(RS);
if(xxx>0) X=xxx;
ProgressBar_In_Out->Position=X;
Label_In_Out->Caption=String(X)+"/"+String(CHK.InOut_Time);
Label_Com_Hint->Caption="读取织带进出进度"+String(X);
SINGLE+=X;

//
if(REPORT.CHECK_1){
   CMD="010306040001";
   SendString(CMD);//:读取T4(地址\X0604)---间歇时间
   RS=ReadString();
   }
if(REPORT.CHECK_2){
   CMD="010306050001";
   SendString(CMD);//:读取T5(地址\X0605)---间歇时间
   RS=ReadString();
   }
if(REPORT.CHECK_3){
   CMD="010306060001";
   SendString(CMD);//:读取T6(地址\X0606)---间歇时间
   RS=ReadString();
   }
X=Read_Value(RS);
ProgressBar_Pause->Position=X;

⌨️ 快捷键说明

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