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

📄 dztp.~cpp

📁 电子天平测量数据处理系统
💻 ~CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "DZTP.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "MSCommLib_OCX"
#pragma resource "*.dfm"
#pragma link "Excel_2K_SRVR"

TDZTPForm *DZTPForm;
//---------------------------------------------------------------------------
__fastcall TDZTPForm::TDZTPForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TDZTPForm::StringGridDblClick(TObject *Sender)
{
     if (MSComm->PortOpen)
     {
         //发送命令
         AnsiString CL = "\n";  //CL
         AnsiString RF( = "\r";  //RF
         AnsiString Command = "S" + CL + RF;       //查询当前稳定的净重值
         MSComm->Output = StringToOleStr(Command); //把AnsiString型转化成//Ole形式。

         AnsiString debug;
         debug.printf ("当前位置是 %d, %d", StringGrid->Row, StringGrid->Col);
         ShowMessage(debug);
     }
}
//---------------------------------------------------------------------------

void __fastcall TDZTPForm::Com1RadioButtonClick(TObject *Sender)
{
     s_ComPortNum = 1;

     if(MSComm->PortOpen)     //关闭串口
     	MSComm->PortOpen = false;
        
     MSComm->CommPort = s_ComPortNum;  //选择串口
     MSComm->Settings = SETTINGS_STRING; //设置串口通信参数

     if(!MSComm->PortOpen)     //打开串口
     	MSComm->PortOpen = true;

     MSComm->InputMode = INPUT_MODE;   //设置输入模式为二进制方式
     MSComm->RThreshold = 1; //当串口接收缓冲区中有>=1个字符时将引发一个关于接收数据的事件
     MSComm->InputLen = 0;
     MSComm->Input;       //先清除缓冲区残留数据
}
//---------------------------------------------------------------------------

void __fastcall TDZTPForm::Com2RadioButtonClick(TObject *Sender)
{
     s_ComPortNum = 2;

     if(MSComm->PortOpen)     //关闭串口
     	MSComm->PortOpen = false;

     MSComm->CommPort = s_ComPortNum;  //选择串口
     MSComm->Settings = SETTINGS_STRING; //设置串口通信参数

     if(!MSComm->PortOpen)     //打开串口
     	MSComm->PortOpen = true;

     MSComm->InputMode = INPUT_MODE;   //设置输入模式为二进制方式
     MSComm->RThreshold = 1; //当串口接收缓冲区中有>=1个字符时将引发一个关于接收数据的事件
     MSComm->InputLen = 0;
     MSComm->Input;       //先清除缓冲区残留数据
}
//---------------------------------------------------------------------------


void __fastcall TDZTPForm::FormClose(TObject *Sender, TCloseAction &Action)
{
     if (MSComm->PortOpen)
         MSComm->PortOpen = false;
}
//---------------------------------------------------------------------------




void __fastcall TDZTPForm::MSCommComm(TObject *Sender)
{
     VARIANT vResponse; 
     Byte *Barray;
     AnsiString Str;
     if(MSComm->CommEvent == comEvReceive)
     {
        if(MSComm->InBufferCount > 3)  //是否有字符驻留在接收缓冲区等待被取出
        {
           vResponse = MSComm->Input;   //接收数据
           Barray = (BYTE *)vResponse.parray->pvData;
           Str.printf ("%s", Barray);
           //处理数据
           ShowMessage(Str);   //显示接收到的数据
           int i = 3;  //从S S后开始
           while (Barray[i] == ' ')   //如果是空格
                  i++;
           //总长减去前面S空格S空格...空格减去最后的CRLF
           AnsiString DataString = Str.SubString(i, Str.Length() - i - 1);
           DataLabel->Caption = DataString;
           //填写表格
           if (StringGrid->Col > 0 && StringGrid->Col < 3)
           {
               StringGrid->Cells[StringGrid->Col][StringGrid->Row] =
                     Str.SubString(i, Str.Length() - i - 3);

              //如果是填写被检砝码示值且标准砝码示值已经不为空
              if (StringGrid->Col == 2 && !StringGrid->Cells[1][StringGrid->Row].IsEmpty())
              {
                  //计算该误差数据
                  int iRow = StringGrid->Row;
                  //计算a = Ia - Ib
                  StringGrid->Cells[3][iRow] =
                       StringGrid->Cells[2][iRow].ToDouble() - StringGrid->Cells[1][iRow].ToDouble();
                  //计算Ka = a *1000 + Kb
                  StringGrid->Cells[5][iRow] =
                       StringGrid->Cells[3][iRow].ToDouble() * 1000 + StringGrid->Cells[4][iRow].ToDouble();
              }
           }
        }
     }
}
//---------------------------------------------------------------------------


void __fastcall TDZTPForm::FormCreate(TObject *Sender)
{
     StringGrid->Cells [0][0] = "被检砝码标称值";
     StringGrid->ColWidths[1] = 105;
     StringGrid->ColWidths[2] = 105;
     StringGrid->ColWidths[3] = 105;
     StringGrid->Cells [1][0] = "标准砝码示值Ib(g)";
     StringGrid->Cells [2][0] = "被检砝码示值Ia(g)";
     StringGrid->Cells [3][0] = "被检值减标准值(g)";
     StringGrid->ColWidths[4] = 115;
     StringGrid->ColWidths[5] = 115;
     StringGrid->Cells [4][0] = "标准砝码修正值(mg)";
     StringGrid->Cells [5][0] = "被检砝码修正值(mg)";
     StringGrid->ColWidths[6] = 150;
     StringGrid->Cells [6][0] = "被检砝码法定允差(±)(mg)";
     StringGrid->Cells[0][1] = "200g";
     StringGrid->Cells[0][2] = "*200g";
     StringGrid->Cells[0][3] = "100g";
     StringGrid->Cells[0][4] = "*100g";
     StringGrid->Cells[0][5] = "50g";
     StringGrid->Cells[0][6] = "20g";
     StringGrid->Cells[0][7] = "*20g";
     StringGrid->Cells[0][8] = "10g";
     StringGrid->Cells[0][9] = "5g";
     StringGrid->Cells[0][10] = "2g";
     StringGrid->Cells[0][11] = "*2g";
     StringGrid->Cells[0][12] = "1g";
     StringGrid->Cells[0][13] = "500mg";
     StringGrid->Cells[0][14] = "200mg";
     StringGrid->Cells[0][15] = "*200mg";
     StringGrid->Cells[0][16] = "100g";
     StringGrid->Cells[0][17] = "50g";
     StringGrid->Cells[0][18] = "20g";
     StringGrid->Cells[0][19] = "*20g";
     StringGrid->Cells[0][20] = "10mg";
     StringGrid->Cells[0][21] = "5mg";
     StringGrid->Cells[0][22] = "2mg";
     StringGrid->Cells[0][23] = "*2mg";
     StringGrid->Cells[0][24] = "1mg";
     StringGrid->Cells[0][25] = "10mg";
     StringGrid->Cells[0][26] = "5mg";

     //连接数据库,取数据
     ADOTable->TableName = "ErrorOption";
     ADOTable->Active = true;
     StringGrid->Cells[4][1] = ADOTable->Fields->Fields[0]->AsString;
     StringGrid->Cells[4][2] = ADOTable->Fields->Fields[1]->AsString;
     StringGrid->Cells[4][3] = ADOTable->Fields->Fields[2]->AsString;
     StringGrid->Cells[4][4] = ADOTable->Fields->Fields[3]->AsString;
     StringGrid->Cells[4][5] = ADOTable->Fields->Fields[4]->AsString;
     StringGrid->Cells[4][6] = ADOTable->Fields->Fields[5]->AsString;
     StringGrid->Cells[4][7] = ADOTable->Fields->Fields[6]->AsString;
     StringGrid->Cells[4][8] = ADOTable->Fields->Fields[7]->AsString;
     StringGrid->Cells[4][9] = ADOTable->Fields->Fields[8]->AsString;
     StringGrid->Cells[4][10] = ADOTable->Fields->Fields[9]->AsString;
     StringGrid->Cells[4][11] = ADOTable->Fields->Fields[10]->AsString;
     StringGrid->Cells[4][12] = ADOTable->Fields->Fields[11]->AsString;
     StringGrid->Cells[4][13] = ADOTable->Fields->Fields[12]->AsString;
     StringGrid->Cells[4][14] = ADOTable->Fields->Fields[13]->AsString;
     StringGrid->Cells[4][15] = ADOTable->Fields->Fields[14]->AsString;
     StringGrid->Cells[4][16] = ADOTable->Fields->Fields[15]->AsString;
     StringGrid->Cells[4][17] = ADOTable->Fields->Fields[16]->AsString;
     StringGrid->Cells[4][18] = ADOTable->Fields->Fields[17]->AsString;
     StringGrid->Cells[4][19] = ADOTable->Fields->Fields[18]->AsString;
     StringGrid->Cells[4][20] = ADOTable->Fields->Fields[19]->AsString;
     StringGrid->Cells[4][21] = ADOTable->Fields->Fields[20]->AsString;
     StringGrid->Cells[4][22] = ADOTable->Fields->Fields[21]->AsString;
     StringGrid->Cells[4][23] = ADOTable->Fields->Fields[22]->AsString;
     StringGrid->Cells[4][24] = ADOTable->Fields->Fields[23]->AsString;
     StringGrid->Cells[4][25] = ADOTable->Fields->Fields[24]->AsString;
     StringGrid->Cells[4][26] = ADOTable->Fields->Fields[25]->AsString;
     ADOTable->Active = false;

     ADOTable->TableName = "ErrorOption2";
     ADOTable->Active = true;
     StringGrid->Cells[6][1] = ADOTable->Fields->Fields[0]->AsString;
     StringGrid->Cells[6][2] = ADOTable->Fields->Fields[1]->AsString;
     StringGrid->Cells[6][3] = ADOTable->Fields->Fields[2]->AsString;
     StringGrid->Cells[6][4] = ADOTable->Fields->Fields[3]->AsString;
     StringGrid->Cells[6][5] = ADOTable->Fields->Fields[4]->AsString;
     StringGrid->Cells[6][6] = ADOTable->Fields->Fields[5]->AsString;
     StringGrid->Cells[6][7] = ADOTable->Fields->Fields[6]->AsString;
     StringGrid->Cells[6][8] = ADOTable->Fields->Fields[7]->AsString;
     StringGrid->Cells[6][9] = ADOTable->Fields->Fields[8]->AsString;
     StringGrid->Cells[6][10] = ADOTable->Fields->Fields[9]->AsString;
     StringGrid->Cells[6][11] = ADOTable->Fields->Fields[10]->AsString;
     StringGrid->Cells[6][12] = ADOTable->Fields->Fields[11]->AsString;
     StringGrid->Cells[6][13] = ADOTable->Fields->Fields[12]->AsString;
     StringGrid->Cells[6][14] = ADOTable->Fields->Fields[13]->AsString;
     StringGrid->Cells[6][15] = ADOTable->Fields->Fields[14]->AsString;
     StringGrid->Cells[6][16] = ADOTable->Fields->Fields[15]->AsString;
     StringGrid->Cells[6][17] = ADOTable->Fields->Fields[16]->AsString;
     StringGrid->Cells[6][18] = ADOTable->Fields->Fields[17]->AsString;
     StringGrid->Cells[6][19] = ADOTable->Fields->Fields[18]->AsString;
     StringGrid->Cells[6][20] = ADOTable->Fields->Fields[19]->AsString;
     StringGrid->Cells[6][21] = ADOTable->Fields->Fields[20]->AsString;
     StringGrid->Cells[6][22] = ADOTable->Fields->Fields[21]->AsString;
     StringGrid->Cells[6][23] = ADOTable->Fields->Fields[22]->AsString;
     StringGrid->Cells[6][24] = ADOTable->Fields->Fields[23]->AsString;
     StringGrid->Cells[6][25] = ADOTable->Fields->Fields[24]->AsString;
     StringGrid->Cells[6][26] = ADOTable->Fields->Fields[25]->AsString;
     ADOTable->Active = false;
}
//---------------------------------------------------------------------------



void __fastcall TDZTPForm::OtherInfoBitBtnClick(TObject *Sender)
{
     OKBottomDlg->ADOTable->Active = true;
     OKBottomDlg->ShowModal();
     OKBottomDlg->ADOTable->Active = false;
}
//---------------------------------------------------------------------------

void __fastcall TDZTPForm::BitBtn1Click(TObject *Sender)
{
     OKRightDlg->ADOTable->Active = true;
     OKRightDlg->ShowModal();

⌨️ 快捷键说明

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