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

📄 waterctrl.pas

📁 delphi+access,水位控制系统
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit waterctrl;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ComCtrls, ToolWin, ExtCtrls, StdCtrls, TeeProcs,
  TeEngine, Chart, DbChart, ADODB, DB, OleCtrls, VCFI, Series, TeeFunci, Math,
  DBTables, ActnList, Grids, DBGrids, DBCtrls, Spin, Inifiles;

type
  TFormWaterControl = class(TForm)
    Panel_TOP: TPanel;
    MainMenu1: TMainMenu;
    MenuFile: TMenuItem;
    Menu_Exit: TMenuItem;
    N1: TMenuItem;
    Menu_PrintSetup: TMenuItem;
    N2: TMenuItem;
    Menu_SaveAs: TMenuItem;
    MenuHelp: TMenuItem;
    Menu_About: TMenuItem;
    MenuSetting: TMenuItem;
    Menu_Parameters: TMenuItem;
    N4: TMenuItem;
    Menu_PID: TMenuItem;
    N5: TMenuItem;
    Menu_Address: TMenuItem;
    MenuExp: TMenuItem;
    Menu_Begin: TMenuItem;
    Menu_Stop: TMenuItem;
    N9: TMenuItem;
    Menu_Redo: TMenuItem;
    StatusBar1: TStatusBar;
    Panel_Chart: TPanel;
    Panel_A: TPanel;
    Panel_B: TPanel;
    CK_A_Measure: TCheckBox;
    CK_A_Flux: TCheckBox;
    Gp_A: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Edit_A_Position: TEdit;
    Edit_A_Flux: TEdit;
    Label3: TLabel;
    Shape1: TShape;
    Gp_B: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Shape2: TShape;
    CK_B_Measure: TCheckBox;
    CK_B_Flux: TCheckBox;
    Edit_B_Position: TEdit;
    Edit_B_Flux: TEdit;
    Shape_A: TShape;
    Shape_B: TShape;
    Chart1: TChart;
    Series1: TFastLineSeries;
    Series2: TFastLineSeries;
    ActionList1: TActionList;
    Action_Exit: TAction;
    Action_Setting: TAction;
    ADOConnection1: TADOConnection;
    ADODataSet1: TADODataSet;
    TimerRedo: TTimer;
    TimerControl: TTimer;
    SEdit_A_HP: TSpinEdit;
    SEdit_B_HP: TSpinEdit;
    ADODataSet1LabTime: TFloatField;
    ADODataSet1X1Value: TFloatField;
    ADODataSet1X2Value: TFloatField;
    ADODataSet1X1Ctrl: TFloatField;
    ADODataSet1X2Ctrl: TFloatField;
    ADODataSet1X1Flux: TFloatField;
    ADODataSet1X2Flux: TFloatField;
    CoolBar1: TCoolBar;
    ToolBar1: TToolBar;
    BTN_Begin: TButton;
    BTN_Setting: TButton;
    BRN_Stop: TButton;
    BTN_Redo: TButton;
    BTN_DataView: TButton;
    BTN_About: TButton;
    BTN_Help: TButton;
    Action_Start: TAction;
    Action_Stop: TAction;
    Action_ReDo: TAction;
    Action_DataView: TAction;
    Action_About: TAction;
    Action_Help: TAction;
    Action_Clear: TAction;
    BTN_DataClear: TButton;
    Menu_Open: TMenuItem;
    Menu_ChartSave: TMenuItem;
    Menu_Help: TMenuItem;
    N6: TMenuItem;
    Menu_DataView: TMenuItem;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Menu_Clear: TMenuItem;
    Action_Preview: TAction;
    Timer_MaxTime: TTimer;
    Timer_Stable: TTimer;
    DataSource1: TDataSource;
    procedure FormCreate(Sender: TObject);
    procedure Action_ExitExecute(Sender: TObject);
    procedure TimerRedoTimer(Sender: TObject);
    procedure TimerControlTimer(Sender: TObject);
    procedure Action_SettingExecute(Sender: TObject);
    procedure Action_DataViewExecute(Sender: TObject);
    procedure Action_AboutExecute(Sender: TObject);
    procedure Action_HelpExecute(Sender: TObject);
    procedure Action_ClearExecute(Sender: TObject);
    procedure Action_ReDoExecute(Sender: TObject);
    procedure Action_StartExecute(Sender: TObject);
    procedure Action_StopExecute(Sender: TObject);
    procedure Timer_MaxTimeTimer(Sender: TObject);
    procedure Timer_StableTimer(Sender: TObject);
    procedure Menu_SaveAsClick(Sender: TObject);
    procedure Menu_OpenClick(Sender: TObject);
    procedure Menu_ChartSaveClick(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
    
  end;
    function PortIn(IOAddr : WORD) : BYTE;   //从端口读入数据,仅对win98系统
    procedure PortOut(IOAddr : WORD; Data : BYTE); //从输出数据到端口,仅对win98系统
    function readadc(ch : Integer):Double; stdcall; //采样
    procedure senddac(dahope : Double);  //输出控制

var
  FormWaterControl: TFormWaterControl;
  WaterHeightLeft, WaterHeightRight : Integer;
  Shape3Top : Integer;  //绘图控制
  StableTime_HP : Integer;  //稳定控制
  Stable_tmp : TDateTime; //判断稳定的时间
  h2_real_real : Real; //实际水位值
  StableValue2 : Real; //期望的稳定水位
  ErrorValue2 : Real ; //期望的误差范围

implementation

uses Setting, DataView, about, help;
{$R *.dfm}

function PortIn(IOAddr : WORD) : BYTE;
begin
	asm
    push dx;
    push ax;
		mov dx,IOAddr;
	  in  al,dx;
  	mov Result,al;
    pop ax;
    pop dx;
  end;
end;                                                             

procedure PortOut(IOAddr : WORD; Data : BYTE);
begin
  asm
    push dx;
    push ax;
  	mov  dx,IOAddr;
    mov  al,Data;
    out  dx,al;
    pop  ax;
    pop  dx;
  end;
end;

procedure senddac(dahope : Double);
var
  base, dd1, dh, dl, dh1 : Integer;
  dd : Double;
begin
  base := $100;  //0x100
  if (dahope > 10.0) then dahope := 10.0;
  if (dahope < 0.0) then dahope := 0.0;
  dd := (dahope) * 4095.0/10.0;
	dd1 := round(dd);  //圆整函数
	dl:= dd1 and 15;
	dh1 := dd1 - dl;
	dh := dh1 div 16;
  PortOut(base+4,dh);
  PortOut(base+5,dl);
end;

function readadc(ch : Integer):Double;stdcall;
var
  i,base: Integer;
  adc: array[0..1] of Integer;
  output : array[0..9] of Double;
  ac : array[0..1] of Double;
  lTime :TDateTime;
begin
 base := $100;  //0x100
 ac[1] := PortIn(base+3);  //ac[0] is high,ac[1] is low!!
 PortOut(base,ch);
 lTime:= GetTickCount;
if ((GetTickCount-lTime) / 1000 > 0.1)
       // 延时0.1秒;
then
begin
 PortOut(base+1,0);
 i := 0;
 repeat
    i := i+1;
    if (i > 20) then break;
 until (PortIn(base+2) and 255 >= 128);
 lTime := GetTickCount;
 if ((GetTickCount-lTime) / 1000 > 0.1)
       // 延时0.1秒;
 then
   begin
    adc[0] := PortIn(base+2) and 255;
    adc[1] := PortIn(base+3) and 255;
    ac[0] := adc[0];
    ac[1] := adc[1];
    output[0] := (ac[0] * 256 + ac[1]) * 10.0/4095.0;
    Result := output[0];
   end;
end;
end;

procedure TFormWaterControl.FormCreate(Sender: TObject);
var tmpINI : TInifile;
begin
   Shape3Top := Shape_A.Top;
   tmpINI :=  Tinifile.create(ExtractFilePath(paramstr(0))+'Fuzzy.Ini');
     //初始化
   CK_A_Measure.Checked := tmpINI.ReadBool('液位传感器','A',True);
   CK_B_Measure.Checked := tmpINI.ReadBool('液位传感器','A',True);
   CK_A_Flux.Checked := tmpINI.ReadBool('流量传感器','A',True);
   CK_B_Flux.Checked := tmpINI.ReadBool('流量传感器','B',True);
   SEdit_A_HP.Value := tmpINI.ReadInteger('水位','期望A',120);
   SEdit_B_HP.Value := tmpINI.ReadInteger('水位','期望B',120);
   Gp_A.Enabled := tmpINI.ReadBool('水箱启用','A',True);
   Gp_B.Enabled := tmpINI.ReadBool('水箱启用','B',False);
   TimerControl.Interval := tmpINI.ReadInteger('时间','采样',1500);
   Timer_MaxTime.Interval := 1000000*tmpINI.ReadInteger('时间','最长实验时间',30);
   StableTime_HP := 1000*tmpINI.ReadInteger('时间','稳定时间',30);
   StableValue2 := SEdit_A_HP.Value /12;  //相对稳定水位
   ErrorValue2 := tmpINI.ReadInteger('水位','误差范围',5)/100;
end;

procedure TFormWaterControl.Action_ExitExecute(Sender: TObject);
begin
if Application.MessageBox('你确定要退出水箱控制系统实验吗?',
    '水箱模糊控制系统',MB_OKCANCEL+MB_ICONINFORMATION+MB_SYSTEMMODAL

⌨️ 快捷键说明

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