【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit4-Form4系统设置界面

简介: 【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit4-Form4系统设置界面

下面介绍Unit4系统设置界面的实现。

 


orm4主要实现的就是系统的设置,系统的设置主要包含:1.设置串口,2.增、删、改负载特征矩阵,3.下传负载特征矩阵,4.设置数据库路径。

其中第2点再后续的form6,form7,form8中讲解。

1.下传负载特征矩阵

先来展示所有源码:

procedure TForm4.TeButton1Click(Sender: TObject);
var
  i,j,flag,k : integer; //改maxIndex为全局变量了
  tempVal : single;
  hex,strHex : string;
begin
    form1.IBdatabase1.Connected:=true;
    form1.IBquery1.Close;
    form1.ibquery1.SQL.Clear;
    form1.ibquery1.SQL.Add('select max(loadIndex) from loadmatrix');
    form1.ibquery1.Open;  //这时值已经放到IBQuery中了
    maxIndex := form1.IBQuery1.FieldByName('max').AsInteger ;//取出最大的矩阵行号
    teprogressbar1.Position := 0;
    teprogressbar1.Min :=0;
    teprogressbar1.Max :=maxIndex * 6 * 10 * 3;//计算最大量
    teprogressbar1.Step := 1;
    form1.comport1.Port := ckCombo.Items[ckCombo.ItemIndex];//由unit4选择串口号
    form1.comport1.BaudRate := br9600;
    if form1.ComPort1.Connected = false then
    begin
      flag := 0;//记录串口的初始状态 0表示初始串口关着呢
      form1.ComPort1.Open;
    end
    else
      flag := 1;//1表示初始串口开着呢
    for k := 0 to 2 do //为了保险,矩阵数据下传3遍
    begin
      for i := 1 to maxIndex do //i代表矩阵行号
      begin
        form1.ibquery1.SQL.Clear;
        form1.IBQuery1.SQL.Add('select * from loadMatrix where loadIndex = :A');
        Form1.IBQuery1.Params.ParamByName('A').Value := i;
        form1.ibquery1.Open;  //这时值已经放到IBQuery中了
        //发相位
        tempVal := form1.ibquery1.FieldByName('phase').AsFloat ;//取得相位
        hex := FloatToHex(tempVal);//将float数据转成4字节十六进制字符串
        for j := 0 to 9 do//j代表表号0~9
        begin
          strHex := '68 0'+inttostr(j)+' 30 00 00 00 00 68 04 08 fe fd '+inttostr(i-1)+'0'+hex+' 13 16';
          form1.comport1.WriteStr(Hexstrtostr(strHex));//发送数据 调用Hexstrtostr函数
          tememo1.Text := tememo1.Text + strHex + #13#10;//#13 #10 memo换行
          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text ); //一直让memo显示最后一行
          teprogressbar1.StepIt;//进度条加1
          Delay(500);
        end;
        //发谐波1
        tempVal := form1.ibquery1.FieldByName('har1').AsFloat ;//取得相位
        hex := FloatToHex(tempVal);//将float数据转成4字节十六进制字符串
        for j := 0 to 9 do//j代表表号0~9
        begin
          strHex := '68 0'+inttostr(j)+' 30 00 00 00 00 68 04 08 fe fd '+inttostr(i-1)+'1'+hex+' 13 16';
          form1.comport1.WriteStr(Hexstrtostr(strHex));//发送数据
          tememo1.Text := tememo1.Text + strHex+ #13#10;
          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text );
          teprogressbar1.StepIt;//进度条加1
          Delay(500);
        end;
        //发谐波3
        tempVal := form1.ibquery1.FieldByName('phase').AsFloat ;//取得相位
        hex := FloatToHex(tempVal);//将float数据转成4字节十六进制字符串
        for j := 0 to 9 do//j代表表号0~9
        begin
          strHex := '68 0'+inttostr(j)+' 30 00 00 00 00 68 04 08 fe fd '+inttostr(i-1)+'2'+hex+' 13 16';
          form1.comport1.WriteStr(Hexstrtostr(strHex));//发送数据
          tememo1.Text := tememo1.Text + strHex+ #13#10;
          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text );
          teprogressbar1.StepIt;//进度条加1
          Delay(500);
        end;
        //发谐波5
        tempVal := form1.ibquery1.FieldByName('har1').AsFloat ;//取得相位
        hex := FloatToHex(tempVal);//将float数据转成4字节十六进制字符串
        for j := 0 to 9 do//j代表表号0~9
        begin
          strHex := '68 0'+inttostr(j)+' 30 00 00 00 00 68 04 08 fe fd '+inttostr(i-1)+'3'+hex+' 13 16';
          form1.comport1.WriteStr(Hexstrtostr(strHex));//发送数据
          tememo1.Text := tememo1.Text + strHex+ #13#10;
          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text );
          teprogressbar1.StepIt;//进度条加1
          Delay(500);
        end;
        //发谐波7
        tempVal := form1.ibquery1.FieldByName('phase').AsFloat ;//取得相位
        hex := FloatToHex(tempVal);//将float数据转成4字节十六进制字符串
        for j := 0 to 9 do//j代表表号0~9
        begin
          strHex := '68 0'+inttostr(j)+' 30 00 00 00 00 68 04 08 fe fd '+inttostr(i-1)+'4'+hex+' 13 16';
          form1.comport1.WriteStr(Hexstrtostr(strHex));//发送数据
          tememo1.Text := tememo1.Text + strHex+ #13#10;
          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text );
          teprogressbar1.StepIt;//进度条加1
          Delay(500);
        end;
        //发谐波9
        tempVal := form1.ibquery1.FieldByName('har1').AsFloat ;//取得相位
        hex := FloatToHex(tempVal);//将float数据转成4字节十六进制字符串
        for j := 0 to 9 do//j代表表号0~9
        begin
          strHex := '68 0'+inttostr(j)+' 30 00 00 00 00 68 04 08 fe fd '+inttostr(i-1)+'5'+hex+' 13 16';
          form1.comport1.WriteStr(Hexstrtostr(strHex));//发送数据
          tememo1.Text := tememo1.Text + strHex+ #13#10;
          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text );
          teprogressbar1.StepIt;//进度条加1
          Delay(500);
        end;
      end;
    end;
    ShowMessage('下载完成');
    if flag = 0 then
      form1.ComPort1.Connected := false; //恢复串口的初始状态
end;

上面的结构大体如下:

for k//传3遍
  for i//矩阵的行号
  1.发相位
    for j 0~9//代表表号
  2.发谐波1
    for j 0~9//代表表号
  3.发谐波3
    for j 0~9//代表表号
  4.发谐波5
    for j 0~9//代表表号
  5.发谐波7
    for j 0~9//代表表号
  6.发谐波9
    for j 0~9//代表表号

以发送相位为例详细讲解:

        //发相位
        tempVal := form1.ibquery1.FieldByName('phase').AsFloat ;//取得相位
        hex := FloatToHex(tempVal);//将float数据转成4字节十六进制字符串
        for j := 0 to 9 do//j代表表号0~9
        begin
          strHex := '68 0'+inttostr(j)+' 30 00 00 00 00 68 04 08 fe fd '+inttostr(i-1)+'0'+hex+' 13 16';
          form1.comport1.WriteStr(Hexstrtostr(strHex));//发送数据 调用Hexstrtostr函数
          tememo1.Text := tememo1.Text + strHex + #13#10;//#13 #10 memo换行
          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text ); //一直让memo显示最后一行
          teprogressbar1.StepIt;//进度条加1
          Delay(500);
        end;

同样使用 ibquery1.FieldByName('phase').AsFloat 得到数据库中字段名为“phase”的数据内容,使用FloatToHex函数将float数据转为4字节十六进制。


根据645规约,将传输帧补齐,即strHex字符串,使用函数Hexstrtostr将字符串转为16进制,最后使用语句form1.comport1.WriteStr(Hexstrtostr(strHex));将命令帧下传。


最后,按一般习惯,显示窗口要一直显示当前发送的最后一帧数据,那么就要使用下面两句,使显示保持在最后一行:

          tememo1.SelStart := length(tememo1.Text );
          tememo1.SelLength := length(tememo1.Text ); //一直让memo显示最后一行

2.设置数据库路径

使用openDialog控件来打开文件。

使用如下语句即可得到文件的完整路径,其返回值是包含文件名的完整路径:

  if opendialog1.Execute  then
  begin
    tememo2.Text := opendialog1.FileName  ;
  end;
相关文章
|
3月前
|
安全 Java 测试技术
在线音乐播放系统的设计与实现(论文+源码)_kaic
在线音乐播放系统的设计与实现(论文+源码)_kaic
|
3月前
|
前端开发
问题解答:SAP UI5 应用设置禁止被其他应用嵌入运行的工作原理解析试读版
问题解答:SAP UI5 应用设置禁止被其他应用嵌入运行的工作原理解析试读版
西门子S7-200 SMART如何使用状态图表,如何创建、监视、强制、趋势显示
上篇文章中我们学习了S7-200 SMART系统块的组态,本篇我们来介绍在编程软件STEP7-Micro/WIN SMART中如何使用状态图表,以及如何创建、监视、强制、趋势显示。在STEP7-Micro/WIN SMART与PLC之间成功建立通信,并且将程序下载到PLC后,就可以监控和调试程序了。程序状态监控可以监视程序的运行情况,但是如果需要监控的变量较多,不能在程序编辑器中同时显示的时候就需要使用状态图表监控。接下来我们来介绍在STEP7-Micro/WIN SMART如何使用状态图表监控和调试程序。
西门子S7-200 SMART如何使用状态图表,如何创建、监视、强制、趋势显示
|
存储 SQL 监控
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit1-Form1主界面
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit1-Form1主界面
113 0
|
SQL 监控 数据库
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit2-Form2用户电量查询显示界面
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit2-Form2用户电量查询显示界面
|
监控
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit3-Form3用户负载类型查询界面
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之Unit3-Form3用户负载类型查询界面
|
存储 监控 网络协议
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之 总述
【乌拉喵.教程】“多负载识别监控平台(上位机)”技术细节 之 总述
105 0
|
存储 BI 数据安全/隐私保护
PACS系统源码 大型医院PACS/RIS源码 支持专业三维影像后处理功能,演示文档齐全
PACS系统可实现检查预约、病人信息登记、计算机阅片、电子报告书写、胶片打印、报表统计、数据备份等一系列满足影像科室日常工作的功能,并且由于影像数字化存储,用户可利用影像处理与测量技术辅助诊断、方便快捷地查找资料或利用网络将资料传输至临床科室,还可与医院HIS、LIS无缝连接。集成专业三维影像后处理功能:三维多平面重建、三维容积重建、三维表面重建、三维虚拟内窥镜、最大/小密度投影、心脏动脉钙化分析等。
PACS系统源码 大型医院PACS/RIS源码 支持专业三维影像后处理功能,演示文档齐全
|
存储 搜索推荐 算法
​医学影像管理(PACS/RIS)系统源码,实现对不同设备、不同图像信息的处理
支持WORKLIST功能,自动化工作流程。 ·强大的个性化设计,提供大量用户自定义和数据预设置功能,用户可根据实际的需求对系统进行个性化设置和调整。 ·采用VC++编程语言,提供先进图像处理和算法,实现对医学图像信息的快速采集、传输、存储、显示和后处理。 ·有效解决大容量图像存储问题,支持多种存储方式和多种备份方式。