{------------------------------------------------------------------------------} {µ¥ÔªÃû³Æ£ºinterceptThread.pas } {Ä£¿éÃû³Æ£º¼ÆËã½Ø¾àÏß³Ì } {Ä£¿é˵Ã÷£ºÏ̴߳´½¨ºó×Ô¶¯ÔËÐУ¬Íê³ÉÒ»´Îº¬Ë®ÂʼìÑ飬¹²Èý´Î } {½¨Á¢ÈÕÆÚ£º2025-01-15 } {ÐÞ¸ÄÐ޸ģº2025-01-20 } {°æÈ¨ËùÓУºÀîÁ¼Í¥ liangtingli@outlook.com } {------------------------------------------------------------------------------} unit interceptThread; interface uses Windows, Classes, SysUtils, PubUtils, DateUtils, sBitBtn, ActuatorLib; type TInterceptThread = class(TThread) private { Private declarations } t_ret : Integer; //·µ»ØÖµ t_nDatas : array[0..3] of Word; //ÔÝ´æË®·ÖÒÇÊý¾Ý t_faultCode : Word; //Ë®·ÖÒǹÊÕÏÂë procedure UpdateStartClock; procedure UpdateStopClock; procedure UpdateTest; procedure UpdateTestError; procedure UpdateFaultCode; procedure UpdateCaption; protected procedure StartIntercept(); procedure Execute; override; public constructor Create(param: Boolean=false); procedure Terminate; end; implementation uses uMain, uDM, uInit, uSaveData, Global, log4me; { TInterceptThread } //--------Ï̳߳õʼ»¯---------------------------------------- //Ï̳߳õʼ»¯ constructor TInterceptThread.Create(param: Boolean=false); begin //Ïß³ÌÍ£Ö¹ºó×Ô¶¯ÊÍ·Å inherited Create(param); //ÉèÖÃÏß³ÌÔËÐÐ, False-×Ô¶¯ÔËÐÐ, True-ÊÖ¶¯Æô¶¯ FreeOnTerminate := True; //ÉèÖÃÏß³ÌÍ˳ö×Ô¶¯Ïú t_ret := 0; t_nDatas[0] := 0; //³õʼ»¯Ë®·ÖÒÇÊý×é t_nDatas[1] := 0; t_nDatas[2] := 0; t_nDatas[3] := 0; end; //Ïß³ÌÏú»Ùʼþ procedure TInterceptThread.Terminate; begin inherited; m_InterceptThread := 0; //ÇåÀíÏ߳̾ä±ú end; //--------½çÃæ´¦Àíº¯Êý-------------------------------------- //¼ÆÊýÆ÷¿ªÊ¼ procedure TInterceptThread.UpdateStartClock; begin //Æô¶¯¼ì²â¼ÆÊ±Æ÷¶¯»­ glStartTest := GetMillisecondTimeStamp; dm.tmInter.Enabled := true; end; //¼ÆÊýÆ÷½áÊø procedure TInterceptThread.UpdateStopClock; begin dm.tmInter.Enabled := false; frmMain.mtInterClock.Value := 0; end; //Õý³£ÏÔʾ--Ö´Ðмì²â procedure TInterceptThread.UpdateTest; begin frmMain.lblInter.Caption := '¼ì²âÒ»×éË®·Ö³É¹¦£¡'; end; //³ö´íÏÔʾ procedure TInterceptThread.UpdateTestError; begin frmMain.lblInter.Caption := '¼ì²âʧ°Ü£¬Ë®·ÖÒǹÊÕÏ£¡'; end; //¸üйÊÕÏÂë procedure TInterceptThread.UpdateFaultCode; begin RefashFaultCode(t_faultCode); end; //¸üмì²â½á¹ûµ½½çÃæ procedure TInterceptThread.UpdateCaption; var nMois : double; x0,x1,x2,x3,x4 : double; begin //³õʼ»¯ÏµÊý x0 := StrToFloat(Grain.coef[0]); x1 := StrToFloat(Grain.coef[1]); x2 := StrToFloat(Grain.coef[2]); x3 := StrToFloat(Grain.coef[3]); x4 := StrToFloat(Grain.coef[4]); //¼ÆË㺬ˮÂÊ {nMois := (x0 + (x1 * t_nDatas[0]) + (x2 * t_nDatas[0] * t_nDatas[0]) + (x3 * t_nDatas[0] * t_nDatas[0] * t_nDatas[0]) ); (x4 * t_nDatas[0] * t_nDatas[0] * t_nDatas[0] * t_nDatas[0])); } nMois := CalcValue(t_nDatas[0], x0,x1,x2,x3,x4); with frmMain do begin case glBtnTag1 of 1: edtInter1.Text := FloatToStr(nMois); 2: edtInter2.Text := FloatToStr(nMois); 3: edtInter3.Text := FloatToStr(nMois); end; end; end; //------- Ö´ÐÐÏß³Ì ---------------------------------------- procedure TInterceptThread.StartIntercept(); begin //Ï·¢Ë®·ÖÒÇÆô¶¯Ö¸Áî Synchronize(UpdateStartClock); t_ret := SendCommands(hWrDev, WR_DETECT, 0, glTime2); Synchronize(UpdateStopClock); //¼ÆËãºÍÊä³ö if t_ret<>0 then Synchronize(UpdateTestError) else begin //Êä³öÒ»×麬ˮÂÊÖµ£¨ÕâÀï²»¼Ó½Ø¾à£© //0-µçѹ¡¢1-ÖØÁ¿¡¢2-ζȡ¢3-ʪ¶È t_ret := ReadDatas(hWrDev, @t_nDatas); Synchronize(UpdateTest); Synchronize(UpdateCaption); end; //¼ì²éË®·ÖÒǹÊÕÏÂë ReadFaultCode(hWrDev, @t_faultCode); Synchronize(UpdateFaultCode); end; //------- Ïß³ÌÈë¿Ú ---------------------------------------- procedure TInterceptThread.Execute; begin { Place thread code here } try //Ö´Ðнؾàµ÷Õû´úÂë StartIntercept(); //·ÀÖ¹Ïß³Ì×èÈûCPU Sleep(1000); finally //Ïú»ÙÏß³Ì Terminate; end; end; end.