?? testcontrol.~pas
字號(hào):
procedure TForm1.N2Click(Sender: TObject);
begin
Self.ListView1.Clear;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
tempIni:Tinifile;
begin
tempIni:=TIniFile.Create( GetCurrentDir+ '\TestControl.ini');
try
self.FUnitMaxNumber:=StrToInt(tempIni.ReadString('config','單元總數(shù)','50'));
self.FCabinetControler:=TCabinetControler.Create(tempIni.ReadString('config','端口號(hào)','COM1'));
// Self.FCabinetControler:=TCabinetControler.Create('COM3');
// showmessage(IntToStr(Self.FUnitMaxNumber));
finally
tempIni.free;
end;
end;
procedure TForm1.ButtonQueryClick(Sender: TObject);
begin
Self.QueryCabinet;
end;
//查詢
procedure TForm1.QueryCabinet;
var
tempControl:TCabinetControler;
tempState:DiskBoxOpenState;
i:integer;
tempItem:TListItem;
begin
self.ListView1.Clear;
if ((self.ComboBoxCom.Text='') or (self.ComboBoxCabinet.Text='')) then
begin
ShowMessage('未選擇串口、柜子');
exit;
end;
for i:=0 to 15 do
begin
tempState[i]:=1;
end;
// {
if (self.FCabinetControler.GetIsDiskBoxOpen(Self.ComboBoxCabinet.ItemIndex,tempState)) then
begin
for i:=0 to 15 do
begin
tempItem:=Self.ListView1.Items.Add;
tempItem.Caption:='抽屜'+IntToStr(i+1);
if tempState[i]<>0 then
tempItem.SubItems.Add('開啟')
else
tempItem.SubItems.Add('關(guān)閉');
end;
ShowMessage(Self.ComboBoxCabinet.Text+'查詢成功');
end
else
begin
ShowMessage(Self.ComboBoxCabinet.Text+'查詢失敗')
end;
// }
{
tempControl:=TCabinetControler.Create(self.ComboBoxCom.Text);
try
if (tempControl.GetIsDiskBoxOpen(Self.ComboBoxCabinet.ItemIndex,tempState)) then
begin
for i:=0 to 15 do
begin
tempItem:=Self.ListView1.Items.Add;
tempItem.Caption:='抽屜'+IntToStr(i+1);
if tempState[i]<>0 then
tempItem.SubItems.Add('開啟')
else
tempItem.SubItems.Add('關(guān)閉');
end;
ShowMessage(Self.ComboBoxCabinet.Text+'查詢成功');
end
else
begin
ShowMessage(Self.ComboBoxCabinet.Text+'查詢失敗')
end;
finally
tempControl.Destroy;
end;
}
end;
procedure TForm1.ButtonClearClick(Sender: TObject);
begin
Self.ListView1.Clear;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Self.FCabinetControler.Free;
end;
//遍歷所有抽屜,并點(diǎn)亮所有指示燈。
procedure TForm1.ButtonLightAllUnitClick(Sender: TObject);
var
ErrorMessage:String;
begin
if (Self.ComboBoxCabinet.Text='') then
begin
ShowMessage('未選擇柜子');
exit;
end;
//判斷線程是否運(yùn)行,如運(yùn)行則終止線程并重新運(yùn)行。
if (Self.FMyThread<>nil) then
begin
Self.FMyThread.Terminate;
Self.FMyThread.WaitFor;
Self.FMyThread.Destroy;
Self.FMyThread:=nil;
end;
if (Self.FMyThread=nil) then
begin
Self.FMyThread:=LightAllBoxThread.Create(False);
if (Self.FMyThread<>nil) then
begin
Self.ButtonQuery.Enabled:=False;
Self.ButtonOpenOneBox.Enabled:=False;
Self.ButtonLightOneUnit.Enabled:=False;
Self.ButtonLightOneBox.Enabled:=False;
Self.ButtonQuery.Enabled:=False;
Self.ButtonLightAllUnit.Enabled:=False;
Self.ButtonStopLightAllUnit.Enabled:=True;
Self.ButtonStopLightOneBox.Enabled:=False;
Self.ButtonOpenAllBox.Enabled:=False;
end
else
begin
ShowMessage('點(diǎn)亮所有單元失敗');
Self.FMyThread.Terminate;
Self.FMyThread.WaitFor;
Self.FMyThread.Destroy;
Self.FMyThread:=nil;
end;
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// CanClose:=False;
if (Self.FMyThread<>nil) then
begin
Self.FMyThread.Terminate;
Self.FMyThread.WaitFor;
Self.FMyThread.Destroy;
Self.FMyThread:=nil;
CanClose:=True;
end;
if (Self.FLightOneBoxThread<>nil) then
begin
Self.FLightOneBoxThread.Terminate;
Self.FLightOneBoxThread.WaitFor;
Self.FLightOneBoxThread.Destroy;
Self.FLightOneBoxThread:=nil;
CanClose:=True;
end;
if ((Self.FMyThread=nil) and (Self.FLightOneBoxThread=nil)) then
CanClose:=True
else
CanClose:=False;
end;
procedure TForm1.ButtonStopLightAllUnitClick(Sender: TObject);
begin
if (Self.FMyThread<>nil) then
begin
Self.FMyThread.Terminate;
Self.FMyThread.WaitFor;
Self.FMyThread.Destroy;
Self.FMyThread:=nil;
Self.FLightOneBoxThread:=nil;
Self.ButtonQuery.Enabled:=False;
Self.ButtonOpenOneBox.Enabled:=True;
Self.ButtonLightOneUnit.Enabled:=True;
Self.ButtonLightOneBox.Enabled:=True;
Self.ButtonQuery.Enabled:=True;
Self.ButtonLightAllUnit.Enabled:=True;
Self.ButtonStopLightAllUnit.Enabled:=False;
Self.ButtonStopLightOneBox.Enabled:=False;
Self.ButtonOpenAllBox.Enabled:=True;
end;
end;
//開啟所有抽屜,檢測(cè)開門機(jī)構(gòu)是否正常
procedure TForm1.ButtonOpenAllBoxClick(Sender: TObject);
var
i:integer;
ErrorMessage:string;
bOK:Boolean;
begin
if (Self.ComboBoxCabinet.Text='') then
begin
ShowMessage('沒有選擇柜子');
exit;
end;
Self.ButtonQuery.Enabled:=False;
Self.ButtonOpenOneBox.Enabled:=False;
Self.ButtonLightOneUnit.Enabled:=False;
Self.ButtonLightOneBox.Enabled:=False;
Self.ButtonLightAllUnit.Enabled:=False;
Self.ButtonStopLightAllUnit.Enabled:=False;
Self.ButtonStopLightOneBox.Enabled:=False;
Self.ButtonOpenAllBox.Enabled:=False;
Self.ButtonClear.Enabled:=False;
for i:=0 to 15 do
begin
if not (Self.FCabinetControler.OpenDiskBox(i,Self.ComboBoxCabinet.ItemIndex)) then
begin
ErrorMessage:='開啟抽屜'+IntToStr(i)+'失敗';
Self.ButtonQuery.Enabled:=True;
Self.ButtonOpenOneBox.Enabled:=True;
Self.ButtonLightOneUnit.Enabled:=True;
Self.ButtonLightOneBox.Enabled:=True;
Self.ButtonQuery.Enabled:=True;
Self.ButtonLightAllUnit.Enabled:=True;
Self.ButtonStopLightAllUnit.Enabled:=False;
Self.ButtonStopLightOneBox.Enabled:=False;
Self.ButtonOpenAllBox.Enabled:=True;
Self.ButtonClear.Enabled:=True;
exit;
end;
Sleep(1000);
end;
ShowMessage('開啟所有抽屜完成');
Self.ButtonQuery.Enabled:=True;
Self.ButtonOpenOneBox.Enabled:=True;
Self.ButtonLightOneUnit.Enabled:=True;
Self.ButtonLightOneBox.Enabled:=True;
Self.ButtonLightAllUnit.Enabled:=True;
Self.ButtonStopLightAllUnit.Enabled:=False;
Self.ButtonStopLightOneBox.Enabled:=False;
Self.ButtonOpenAllBox.Enabled:=True;
Self.ButtonClear.Enabled:=True;
end;
procedure TForm1.ButtonStopLightOneBoxClick(Sender: TObject);
begin
if (Self.FLightOneBoxThread<>nil) then
begin
Self.FLightOneBoxThread.Terminate;
Self.FLightOneBoxThread.WaitFor;
Self.FLightOneBoxThread.Destroy;
Self.FLightOneBoxThread:=nil;
Self.ButtonQuery.Enabled:=False;
Self.ButtonOpenOneBox.Enabled:=True;
Self.ButtonLightOneUnit.Enabled:=True;
Self.ButtonLightOneBox.Enabled:=True;
Self.ButtonQuery.Enabled:=True;
Self.ButtonLightAllUnit.Enabled:=True;
Self.ButtonStopLightAllUnit.Enabled:=False;
Self.ButtonStopLightOneBox.Enabled:=False;
Self.ButtonOpenAllBox.Enabled:=True;
end;
end;
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -