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

📄 caiji.~pas

📁 成都研究院全直径测试仪控制软件 delphi开发
💻 ~PAS
字号:
unit caiji;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, OleCtrls, MSCommLib_TLB;

type
  Tcjfrm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Timer1: TTimer;
    MSComm1: TMSComm;
    MSComm2: TMSComm;
    MSComm3: TMSComm;
    MSComm4: TMSComm;
    Button1: TButton;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  cjfrm: Tcjfrm;

implementation

{$R *.dfm}

procedure delay;
var i,j: integer;
begin
  for i:=1 to 20000000 do
  j:=i;
end;

Function HextoInt(HexChar: string): Integer;
begin
  if HexChar='0' then Result:=0
  else if HexChar='1' then Result:=1
  else if HexChar='2' then Result:=2
  else if HexChar='3' then Result:=3
  else if HexChar='4' then Result:=4
  else if HexChar='5' then Result:=5
  else if HexChar='6' then Result:=6
  else if HexChar='7' then Result:=7
  else if HexChar='8' then Result:=8
  else if HexChar='9' then Result:=9
  else if HexChar='A' then Result:=10
  else if HexChar='B' then Result:=11
  else if HexChar='C' then Result:=12
  else if HexChar='D' then Result:=13
  else if HexChar='E' then Result:=14
  else if HexChar='F' then Result:=15
  else ShowMessage('仪表返回数据有误!');
end;

procedure Tcjfrm.Timer1Timer(Sender: TObject);
var
  i,j: integer;
  R1,R2,R3,R4:string;
  Result,Result1,Result2,Result3:real;
  LH,LL,HH,HL,Dot,LH1,LL1,HH1,HL1,Dot1,LH2,LL2,HH2,HL2,Dot2,LH3,LL3,HH3,HL3,Dot3:string;
begin

  MSComm1.Output:=#64'01RD'#49#55#13;
  sleep(50);
  If MSComm1.InBufferCount>=13
  Then R1:=MSComm1.Input;
  LH:=Copy(R1,8,1);
  LL:=Copy(R1,9,1);
  HH:=Copy(R1,10,1);
  HL:=Copy(R1,11,1);
  Dot:=Copy(R1,13,1);
  j:=HextoInt(HH);
  if j<8 then  result:=HextoInt(HH)*4096+HextoInt(HL)*256+HextoInt(LH)*16+HextoInt(LL)
  else result:=((-1)* HextoInt(HL)*256+HextoInt(LH)*16+HextoInt(LL));
  for i:=1 to HextoInt(Dot) do result:=result/10;
  Edit1.Text:=formatfloat('0.000',result);

  MSComm2.Output:=#64'01RD'#49#55#13;
  sleep(50);
  If MSComm2.InBufferCount>=13
  Then R2:=MSComm2.Input;
  LH1:=Copy(R2,8,1);
  LL1:=Copy(R2,9,1);
  HH1:=Copy(R2,10,1);
  HL1:=Copy(R2,11,1);
  Dot1:=Copy(R2,13,1);
  j:=HextoInt(HH1);
  if j<8 then  result1:=HextoInt(HH1)*4096+HextoInt(HL1)*256+HextoInt(LH1)*16+HextoInt(LL1)
  else result1:=((-1)* HextoInt(HL1)*256+HextoInt(LH1)*16+HextoInt(LL1));
  for i:=1 to HextoInt(Dot1) do result1:=result1/10;
  Edit2.Text:=formatfloat('0.000',result1);

  MSComm3.Output:=#64'01RD'#49#55#13;
  sleep(50);
  If MSComm3.InBufferCount>=13
  Then R3:=MSComm3.Input;
  LH2:=Copy(R3,8,1);
  LL2:=Copy(R3,9,1);
  HH2:=Copy(R3,10,1);
  HL2:=Copy(R3,11,1);
  Dot2:=Copy(R3,13,1);
  j:=HextoInt(HH2);
  if j<8 then  result2:=HextoInt(HH2)*4096+HextoInt(HL2)*256+HextoInt(LH2)*16+HextoInt(LL2)
  else result2:=((-1)* HextoInt(HL2)*256+HextoInt(LH2)*16+HextoInt(LL2));
  for i:=1 to HextoInt(Dot2) do result2:=result2/10;
  Edit3.Text:=formatfloat('0.000',result2);

  MSComm4.Output:=#64'01RD'#49#55#13;
  sleep(50);
  If MSComm4.InBufferCount>=13
  Then R4:=MSComm4.Input;
  LH3:=Copy(R4,8,1);
  LL3:=Copy(R4,9,1);
  HH3:=Copy(R4,10,1);
  HL3:=Copy(R4,11,1);
  Dot3:=Copy(R4,13,1);
  j:=HextoInt(HH3);
  if j<8 then  result3:=HextoInt(HH3)*4096+HextoInt(HL3)*256+HextoInt(LH3)*16+HextoInt(LL3)
  else result3:=((-1)* HextoInt(HL3)*256+HextoInt(LH3)*16+HextoInt(LL3));
  for i:=1 to HextoInt(Dot3) do result3:=result3/10;
  Edit4.Text:=formatfloat('0.000',result3);
end;

procedure Tcjfrm.FormCreate(Sender: TObject);
begin
   timer1.Enabled := true;
   if mscomm1.PortOpen = false then
      mscomm1.PortOpen := true;
   if mscomm2.PortOpen = false then
      mscomm2.PortOpen := true;
   if mscomm3.PortOpen = false then
      mscomm3.PortOpen := true;
   if mscomm4.PortOpen = false then
      mscomm4.PortOpen := true;
    mscomm1.InBufferCount := 0;
    mscomm2.InBufferCount := 0;
    mscomm3.InBufferCount := 0;
    mscomm4.InBufferCount := 0;
    mscomm1.OutBufferCount := 0;
    mscomm2.OutBufferCount := 0;
    mscomm3.OutBufferCount := 0;
    mscomm4.OutBufferCount := 0;
end;

procedure Tcjfrm.Button1Click(Sender: TObject);
begin
   timer1.Enabled := true;
end;

end.

⌨️ 快捷键说明

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