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

📄 main.~pas

📁 对钻井的数据采集 对钻井的数据采集
💻 ~PAS
字号:
unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls,usedll,globle;

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn_close: TBitBtn;
    Label1: TLabel;
    Timer1: TTimer;
    btnstart: TBitBtn;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Edit11: TEdit;
    Edit12: TEdit;
    Edit13: TEdit;
    Edit14: TEdit;
    Edit15: TEdit;
    Label17: TLabel;
    Label18: TLabel;
    Edit16: TEdit;
    Edit17: TEdit;
    Label19: TLabel;
    Edit18: TEdit;
    GroupBox2: TGroupBox;
    RadioGroup1: TRadioGroup;
    cb1: TCheckBox;
    cb2: TCheckBox;
    cb3: TCheckBox;
    cb4: TCheckBox;
    cb5: TCheckBox;
    cb6: TCheckBox;
    cb7: TCheckBox;
    cb8: TCheckBox;
    cb9: TCheckBox;
    cb10: TCheckBox;
    cb11: TCheckBox;
    cb12: TCheckBox;
    cb16: TCheckBox;
    cb15: TCheckBox;
    cb14: TCheckBox;
    cb13: TCheckBox;
    lbl_di1: TLabel;
    lbl_di2: TLabel;
    lbl_do1: TLabel;
    lbl_do2: TLabel;
    Label20: TLabel;
    Edt_delay: TEdit;
    btnset: TBitBtn;
    lbl_delaydisp: TLabel;
    var1: TEdit;
    var2: TEdit;
    var3: TEdit;
    edt_n: TEdit;
    Bevel1: TBevel;
    Bevel2: TBevel;
    RadioGroup2: TRadioGroup;
    di1: TCheckBox;
    di2: TCheckBox;
    di3: TCheckBox;
    di8: TCheckBox;
    di7: TCheckBox;
    di6: TCheckBox;
    di5: TCheckBox;
    di4: TCheckBox;
    di12: TCheckBox;
    di11: TCheckBox;
    di10: TCheckBox;
    di9: TCheckBox;
    di13: TCheckBox;
    di14: TCheckBox;
    di15: TCheckBox;
    di16: TCheckBox;
    Label21: TLabel;
    Label22: TLabel;
    procedure BitBtn_closeClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure btnstartClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnsetClick(Sender: TObject);
    procedure cb1Click(Sender: TObject);
    procedure cb2Click(Sender: TObject);
    procedure cb3Click(Sender: TObject);
    procedure cb4Click(Sender: TObject);
    procedure cb5Click(Sender: TObject);
    procedure cb6Click(Sender: TObject);
    procedure cb7Click(Sender: TObject);
    procedure cb8Click(Sender: TObject);
    procedure cb9Click(Sender: TObject);
    procedure cb10Click(Sender: TObject);
    procedure cb11Click(Sender: TObject);
    procedure cb12Click(Sender: TObject);
    procedure cb13Click(Sender: TObject);
    procedure cb14Click(Sender: TObject);
    procedure cb15Click(Sender: TObject);
    procedure cb16Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

{
procedure pcreg();stdcall; external 'HT-PC.dll';
procedure pcout(port:integer;data:integer;delay:integer);stdcall;external 'HT-PC.dll';

function pcin(port:integer;delay:integer):byte;stdcall;external 'HT-PC.dll';//使用byte作为返回值类型
}
 const Port=$310;
 const pre=16/(4096-819);
//定义全局变量和常量/////////////////////
var
  Form1: TForm1;

  //arr:array[1..3] of single;
  //arr2:array[1..3] of single;


////////////////////////////////////////
implementation

{$R *.dfm}
///关闭
procedure TForm1.BitBtn_closeClick(Sender: TObject);
begin
close;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
label1.Caption:='当前数值是: port is '+inttostr(port)+'  ;  pre is '+floattostr(pre);
end;
///用定时器进行数据采集////////////////////////////////////////////////////////
procedure TForm1.Timer1Timer(Sender: TObject);
var
//dh,dl,di1,di2,do1,do2:byte; //应该是一个byte,根据底层设计
n,n1 :integer;
//,dh,dl:integer;
//n,wdh,wdl:byte;
begin
///15通道的数据采集
for n:=0 to 15 do
begin
  pcout($310,n,delay);
   //引入空循环,提供模拟量转换通道所需要的时间//////
  for n1:=0 to 30000 do
  begin
  end;
  ///////////////////////
  pcout($311,0,delay);
  dh:=pcin($312,delay);
  dl:=pcin($313,delay);
  //array_channel[n,count]:= ((dh and 15)*256+dl)*pre+4.0;
  array_channel[n,count]:= ((dh and 15)*256+dl-819)*pre+4.0;
  if  array_channel[n,count]<4 then
  array_channel[n,count]:=array_channel[n,count]-4.0;
 end;



////显示count数值的变化
edt_n.Text:=inttostr(count);

////引入了滤波(5次取平均值)
if (count mod 5)=0 then
begin
data[0]:=(array_channel[0,1]+array_channel[0,2]+array_channel[0,3]+array_channel[0,4]+array_channel[0,5])/5.0;
data[1]:=(array_channel[1,1]+array_channel[1,2]+array_channel[1,3]+array_channel[1,4]+array_channel[1,5])/5.0;
data[2]:=(array_channel[2,1]+array_channel[2,2]+array_channel[2,3]+array_channel[2,4]+array_channel[2,5])/5.0;
data[3]:=(array_channel[3,1]+array_channel[3,2]+array_channel[3,3]+array_channel[3,4]+array_channel[3,5])/5.0;
data[4]:=(array_channel[4,1]+array_channel[4,2]+array_channel[4,3]+array_channel[4,4]+array_channel[4,5])/5.0;
//edit1.Text:=floattostr(data[0]);
///对数据的显示形式进行了规定,小数点后面显示3位 //////////
edit1.Text:=floattostrf(data[0],fffixed,7,3);
edit2.Text:=floattostrf(data[1],fffixed,7,3);
edit3.Text:=floattostrf(data[2],fffixed,7,3);
edit4.Text:=floattostrf(data[3],fffixed,7,3);
edit5.Text:=floattostrf(data[4],fffixed,7,3);
{edit6.Text:=floattostr(data[5]);
edit7.Text:=floattostr(data[6]);
edit8.Text:=floattostr(data[7]);
edit9.Text:=floattostr(data[8]);
edit10.Text:=floattostr(data[9]);
edit11.Text:=floattostr(data[10]);
edit12.Text:=floattostr(data[11]);
edit13.Text:=floattostr(data[12]);
edit14.Text:=floattostr(data[13]);
edit15.Text:=floattostr(data[14]);
}
count:=1;
end
  else
   count:=count+1;
///////////5次一个循环/////////////////////////
dib1:=pcin($116,3000);
dib2:=pcin($117,3000);
pcout($114,do1,3000);
pcout($115,do2,3000);
//对数字输入量进行显示

if (dib1 and $01)<>0 then
di1.Checked:=true
else
di1.Checked:=false;

if (dib1 and $02)<>0 then
di2.Checked:=true
else
di2.Checked:=false;

if (dib1 and $04)<>0 then
di3.Checked:=true
else
di3.Checked:=false;

if (dib1 and $08)<>0 then
di4.Checked:=true
else
di4.Checked:=false;

if (dib1 and $10)<>0 then
di5.Checked:=true
else
di5.Checked:=false;
if (dib1 and $20)<>0 then
di6.Checked:=true
else
di6.Checked:=false;
if (dib1 and $40)<>0 then
di7.Checked:=true
else
di7.Checked:=false;
if (dib1 and $80)<>0 then
di8.Checked:=true
else
di8.Checked:=false;
//////
if (dib2 and $01)<>0 then
di9.Checked:=true
else
di9.Checked:=false;
if (dib2 and $02)<>0 then
di10.Checked:=true
else
di10.Checked:=false;
if (dib2 and $04)<>0 then
di11.Checked:=true
else
di11.Checked:=false;
if (dib2 and $08)<>0 then
di12.Checked:=true
else
di12.Checked:=false;
if (dib2 and $10)<>0 then
di13.Checked:=true
else
di13.Checked:=false;
if (dib2 and $20)<>0 then
di14.Checked:=true
else
di14.Checked:=false;

if (dib2 and $40)<>0 then
di15.Checked:=true
else
di15.Checked:=false;
if (dib2 and $80)<>0 then
di16.Checked:=true
else
di16.Checked:=false;



lbl_di1.Caption:='di1 的数值是:  '+inttostr(dib1);
lbl_di2.Caption:='di2的数值是:  '+inttostr(dib2);


edit16.Text:=inttostr(dh);
edit17.Text:=inttostr(dl);
edit18.Text:=inttostr(dh and 15);


end;

procedure TForm1.btnstartClick(Sender: TObject);
begin
delay:=3000;
timer1.Enabled:=true;
end;
///////////////////////////初始化操作////////////////////////////////
procedure TForm1.FormCreate(Sender: TObject);
begin
 ///初始化
 pcreg();
 count:=1;
 do1:=0;/////输出都是0
 do2:=0;
 lbl_do1.Caption:=inttostr(do1);
 lbl_do2.Caption:=inttostr(do2);

end;
//////////////////////////结束//////////////////////////////////////////
procedure TForm1.btnsetClick(Sender: TObject);
begin
delay:=strtoint(edt_delay.Text);
lbl_delaydisp.Caption:=inttostr(delay);
end;

///////////////////////////////////数字量输出设置//////////////////////
procedure TForm1.cb1Click(Sender: TObject);
begin
  if cb1.Checked then
  do1:=do1+$01
  else
  do1:=do1-$01;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb2Click(Sender: TObject);
begin
if cb2.Checked then
  do1:=do1+$02
  else
  do1:=do1-$02;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb3Click(Sender: TObject);
begin
if cb3.Checked then
  do1:=do1+$04
  else
  do1:=do1-$04;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb4Click(Sender: TObject);
begin
if cb4.Checked then
  do1:=do1+$08
  else
  do1:=do1-$08;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb5Click(Sender: TObject);
begin
if cb5.Checked then
  do1:=do1+$10
  else
  do1:=do1-$10;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb6Click(Sender: TObject);
begin
if cb6.Checked then
  do1:=do1+$20
  else
  do1:=do1-$20;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb7Click(Sender: TObject);
begin
if cb7.Checked then
  do1:=do1+$40
  else
  do1:=do1-$40;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb8Click(Sender: TObject);
begin
if cb1.Checked then
  do1:=do1+$80
  else
  do1:=do1-$80;
  lbl_do1.Caption:=inttostr(do1);
end;

procedure TForm1.cb9Click(Sender: TObject);
begin
if cb9.Checked then
  do2:=do2+$01
  else
  do2:=do2-$01;
  lbl_do2.Caption:=inttostr(do2);
end;

procedure TForm1.cb10Click(Sender: TObject);
begin
if cb10.Checked then
  do2:=do2+$02
  else
  do2:=do2-$02;
  lbl_do2.Caption:=inttostr(do2);
end;

procedure TForm1.cb11Click(Sender: TObject);
begin
if cb11.Checked then
  do2:=do2+$04
  else
  do2:=do2-$04;
  lbl_do2.Caption:=inttostr(do2);
end;

procedure TForm1.cb12Click(Sender: TObject);
begin
if cb12.Checked then
  do2:=do2+$08
  else
  do2:=do2-$08;
  lbl_do2.Caption:=inttostr(do2);
end;

procedure TForm1.cb13Click(Sender: TObject);
begin
if cb13.Checked then
  do2:=do2+$10
  else
  do2:=do2-$10;
  lbl_do2.Caption:=inttostr(do2);
end;

procedure TForm1.cb14Click(Sender: TObject);
begin
if cb14.Checked then
  do2:=do2+$20
  else
  do2:=do2-$20;
  lbl_do2.Caption:=inttostr(do2);
end;

procedure TForm1.cb15Click(Sender: TObject);
begin
if cb15.Checked then
  do2:=do2+$40
  else
  do2:=do2-$40;
  lbl_do2.Caption:=inttostr(do2);
end;

procedure TForm1.cb16Click(Sender: TObject);
begin
if cb16.Checked then
  do2:=do2+$80
  else
  do2:=do2-$80;
  lbl_do2.Caption:=inttostr(do2);
end;

end.

⌨️ 快捷键说明

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