?? waterctrl.~pas
字號:
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 + -