HP\李良庭
2025-07-08 868daf94f29ce1ffdd799a68c07bb668cd373bcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{------------------------------------------------------------------------------}
{µ¥ÔªÃû³Æ£ºinterceptThread.pas                                                 }
{Ä£¿éÃû³Æ£º¼ÆËã½Ø¾àÏ̠߳                                                       }
{Ä£¿é˵Ã÷£ºÏ̴߳´½¨ºó×Ô¶¯ÔËÐУ¬Íê³ÉÒ»´Îº¬Ë®ÂʼìÑ飬¹²Èý´Î                      }
{½¨Á¢ÈÕÆÚ£º2025-01-15                                                          }
{ÐÞ¸ÄÐ޸ģº2025-01-15                                                          }
{°æÈ¨ËùÓУºÀîÁ¼Í¥ 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; //ÔÝ´æË®·ÖÒÇÊý¾Ý
 
    procedure UpdateStartClock;
    procedure UpdateStopClock;
    procedure UpdateTest;
    procedure UpdateTestError;
    procedure UpdateReadDatasError;
    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;
 
//³ö´íÏÔʾ--ReadDatas()³ö´í
procedure TInterceptThread.UpdateReadDatasError;
begin
  //¸üнçÃæÐÅÏ¢
  frmMain.lblManTest.Caption := 'Ë®·ÖÒÇ·µ»Ø¼ì²â½á¹ûʧ°Ü£¡';
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
  //·µ»ØÖµ
  t_ret := 0;
 
  //Ï·¢Ë®·ÖÒÇÆô¶¯Ö¸Áî
  Synchronize(UpdateStartClock);
  t_ret := SendCommands(hWrDev, WR_DETECT, glTime2);     
  Synchronize(UpdateStopClock);
  if t_ret<0 then begin
    Synchronize(UpdateTestError);
    Exit;
  end;
 
   //´ÓË®·ÖÒǶÁÈ¡Êý¾Ý
  t_ret := 0;
  //0-µçѹ¡¢1-ÖØÁ¿¡¢2-ζȡ¢3-ʪ¶È
  t_ret := ReadDatas(hWrDev, @t_nDatas);
  Synchronize(UpdateTest);
 
  //Êä³öÒ»×麬ˮÂÊÖµ£¨ÕâÀï²»¼Ó½Ø¾à£©
  if t_ret<0 then
    Synchronize(UpdateReadDatasError)
  else
    Synchronize(UpdateCaption);
end;
 
//------- Ïß³ÌÈë¿Ú ----------------------------------------
procedure TInterceptThread.Execute;
begin
  { Place thread code here }
  try
    //Ö´Ðнؾàµ÷Õû´úÂë
    StartIntercept();
    //·ÀÖ¹Ïß³Ì×èÈûCPU
    Sleep(1000);
  finally
    //Ïú»ÙÏß³Ì
    Terminate;
  end;
end;
end.