-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepf.pas
434 lines (374 loc) · 10.5 KB
/
stepf.pas
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
unit StepF;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, DividerBevel, Forms, Controls, Graphics, Dialogs,
StdCtrls, ComCtrls, ExtCtrls;
type
eStepMode = (sBoth, sFrequency, sAmplitude);
{ TStepForm }
TStepForm = class(TForm)
btCancel: TButton;
btPause: TButton;
btFinish: TButton;
DividerBevel1: TDividerBevel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
AmplitudeReading: TLabel;
FrequencyReading: TLabel;
Label4: TLabel;
Label5: TLabel;
lTotalSteps: TLabel;
lStep: TLabel;
Label7: TLabel;
Label8: TLabel;
Elapsed: TLabel;
ProgressBar: TProgressBar;
Timer: TTimer;
procedure btCancelClick(Sender: TObject);
procedure btFinishClick(Sender: TObject);
procedure btPauseClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TimerTimer(Sender: TObject);
private
{ private declarations }
public
Finished: boolean;
function CalcSteps: longint;
{ public declarations }
end;
var
Frequency, Amplitude, f, a, StartF, StartA, StopF, StopA, FStep, AStep: double;
StartTime, ElapsedTime, PauseTime, PauseLength: TDateTime;
StepNumber: longword;
StepMode: eStepMode;
StepForm: TStepForm;
implementation
uses
math, DeviceF, MainF, DetControlF, TempControlF, LogModule, ReadingThreads, BaseConF;
{$R *.lfm}
{ TStepForm }
function TStepForm.CalcSteps: longint;
var
t: qword;
s: string;
begin
StartF:= MainForm.eStepStartF.Value;
StartA:= MainForm.eStepStartA.Value;
FStep:= MainForm.eFStep.Value;
AStep:= MainForm.eAStep.Value;
StopF:= MainForm.eStepStopF.Value;
StopA:= MainForm.eStepStopA.Value;
if StartF > StopF then FStep:= - FStep;
if StartA > StopA then AStep:= - AStep;
if (Fstep = 0) then
begin
StepNumber:= abs(trunc((StopA - StartA) / AStep));
StepMode:= sAmplitude;
with DetControlForm do
begin
LogAmpl:= true;
LogFreq:= false;
end;
with TempControlForm do
begin
LogAmpl:= true;
LogFreq:= false;
end;
MainForm.eTimeStep.MinValue:= 150;
end
else
if (AStep = 0) then
begin
StepNumber:= abs(trunc((StopF - StartF) / FStep));
StepMode:= sFrequency;
with DetControlForm do
begin
LogAmpl:= false;
LogFreq:= true;
end;
with TempControlForm do
begin
LogAmpl:= false;
LogFreq:= true;
end;
MainForm.eTimeStep.MinValue:= 150;
end
else
begin
StepMode:= sBoth;
with DetControlForm do
begin
LogAmpl:= true;
LogFreq:= true;
end;
with TempControlForm do
begin
LogAmpl:= true;
LogFreq:= true;
end;
MainForm.eTimeStep.MinValue:= 300;
StepNumber:= abs(trunc((StopA - StartA) / AStep));
if abs(trunc(StopF - StartF) / FStep) > StepNumber then
StepNumber:= abs(trunc((StopF - StartF) / FStep));
end;
CalcSteps:= StepNumber;
t:= StepNumber * MainForm.eTimeStep.Value;
str(t div 3600000, s);
MainForm.TotalTime.Caption:= s + ' ч ';
str((t mod 3600000) div 60000, s);
MainForm.TotalTime.Caption:= MainForm.TotalTime.Caption + s + ' м ';
str((t mod 60000) div 1000, s);
MainForm.TotalTime.Caption:= MainForm.TotalTime.Caption + s + ' с, ';
str(StepNumber, s);
MainForm.TotalTime.Caption:= MainForm.TotalTime.Caption + s;
case StepNumber mod 10 of
1: MainForm.TotalTime.Caption:= MainForm.TotalTime.Caption + ' шаг';
2, 3, 4: MainForm.TotalTime.Caption:= MainForm.TotalTime.Caption + ' шага';
else MainForm.TotalTime.Caption:= MainForm.TotalTime.Caption + ' шагов';
end;
end;
procedure TStepForm.FormShow(Sender: TObject);
var
s: string;
Result: integer;
begin
with MainForm do
begin
if eStepStartF.Value = eStepStopF.Value then
eFStep.Value:= 0;
if eStepStartA.Value = eStepStopA.Value then
eAStep.Value:= 0;
end;
CalcSteps;
Frequency:= StartF;
Amplitude:= StartA;
case StepMode of
sBoth: Label7.Caption:= 'Проход по частоте и амплитуде';
sFrequency: Label7.Caption:= 'Проход по частоте';
sAmplitude: Label7.Caption:= 'Проход по амплитуде';
end;
writeprogramlog(Label7.Caption);
str(Amplitude:0:2, s);
AmplitudeReading.Caption:= s;
str(Frequency:19:6, s);
FrequencyReading.Caption:= s;
with MainForm do
begin
EnableControls(false);
pnConnection.Enabled:= false;
btQuery.Enabled:= true;
btStatus.Enabled:= true;
btCustomCommand.Enabled:= true;
btStop.Enabled:= true;
Cursor:= crAppStart;
EnterCriticalSection(CommCS);
AddCommand(gSweepEnable, false, 0);
AddCommand(gFrequency, false, Frequency, uNone);
AddCommand(gAmplitude, false, Amplitude, AmplitudeUnit);
AddCommand(gOffset, false, Params.Offset, uNone);
PassCommands;
LeaveCriticalSection(CommCS);
end;
if Config.AutoReadingStep then
begin
with DetControlForm do
if ConnectionKind <> cNone then
begin
btStartPauseLog.Enabled:= false;
btStopLog.Enabled:= false;
end;
with TempControlForm do
if ConnectionKind <> cNone then
begin
btStartPauseLog.Enabled:= false;
btStopLog.Enabled:= false;
end;
end;
btCancel.Enabled:= true;
btPause.Enabled:= true;
btFinish.Enabled:= false;
Timer.Interval:= MainForm.eTimeStep.Value;
ProgressBar.Max:= StepNumber;
str(ProgressBar.max, s);
lTotalSteps.Caption:= '/' + s;
lStep.Caption:= '0';
ProgressBar.Position:= 0;
PauseTime:= 0;
Finished:= false;
Cursor:= crHourGlass;
if Config.AutoReadingStep then
begin
Result:= MainForm.StartLogs;
if Result <> 0 then
begin
Hide;
exit;
end;
{if MainForm.cbPointPerStepDet.Checked then
DetControlForm.UpdateTimer.Enabled:= false; }
end;
sleep(Params.TimeStep);
Cursor:= crDefault;
Timer.Enabled:= true;
StartTime:= Now;
end;
procedure TStepForm.TimerTimer(Sender: TObject);
var
s: string;
begin
if Finished then
begin
ProgressBar.StepIt;
btCancel.Enabled:= false;
btPause.Enabled:= false;
btFinish.Enabled:= true;
Timer.Enabled:= false;
btPause.Caption:= 'Пауза';
Sleep(Timer.Interval);
if Config.AutoReadingStep then
MainForm.StopLogs;
end
else
begin
with DetControlForm do
if OnePointPerStep and (ConnectionKind <> cNone) then
Log.ReadingsThread:= tDetOnePerStepThread.Create;
with TempControlForm do
if OnePointPerStep and (ConnectionKind <> cNone) then
Log.ReadingsThread:= tTempOnePerStepThread.Create;
ElapsedTime:= Now - StartTime - PauseLength;
DateTimeToString(s, 'hh:mm:ss', ElapsedTime);
Elapsed.Caption:= s;
ProgressBar.StepIt;
str(Amplitude:0:2, s);
AmplitudeReading.Caption:= s;
str(Frequency:10:6, s);
FrequencyReading.Caption:= s;
str(ProgressBar.Position, s);
lStep.Caption:= s;
with DetControlForm do
if OnePointPerStep and (ConnectionKind <> cNone) then
begin
Log.ReadingsThread.WaitFor;
freeandnil(Log.ReadingsThread);
end;
with TempControlForm do
if OnePointPerStep and (ConnectionKind <> cNone) then
begin
Log.ReadingsThread.WaitFor;
freeandnil(Log.ReadingsThread);
end;
f:= Frequency;
a:= Amplitude;
if (Amplitude = StopA) and (Frequency = StopF) then
Finished:= true
else
begin
Frequency+= FStep;
Amplitude+= AStep;
if (AStep > 0) and (Amplitude > StopA) then Amplitude:= StopA
else
if (AStep < 0) and (Amplitude < StopA) then Amplitude:= StopA;
if (FStep > 0) and (Frequency > StopF) then Frequency:= StopF
else
if (FStep < 0) and (Frequency < StopF) then Frequency:= StopF;
case StepMode of
sBoth:
begin
MainForm.AddCommand(gFrequency, false, Frequency, uNone);
MainForm.AddCommand(gAmplitude, false, Amplitude, AmplitudeUnit);
end;
sFrequency:
begin
MainForm.AddCommand(gFrequency, false, Frequency, uNone);
StopA:= Amplitude;
end;
sAmplitude:
begin
MainForm.AddCommand(gAmplitude, false, Amplitude, AmplitudeUnit);
StopF:= Frequency;
end;
end;
end;
with DetControlForm do
if OnePointPerStep and (ConnectionKind <> cNone) then
Log.ProcessBuffers;
with TempControlForm do
if OnePointPerStep and (ConnectionKind <> cNone) then
Log.ProcessBuffers;
MainForm.PassCommands;
end;
end;
procedure TStepForm.FormHide(Sender: TObject);
begin
MainForm.CommandString:= '';
Timer.Enabled:= false;
MainForm.EnableControls(true);
MainForm.pnConnection.Enabled:= true;
MainForm.Cursor:= crDefault;
DetControlForm.btStartPauseLog.Enabled:= true;
DetControlForm.btStopLog.Enabled:= true;
TempControlForm.btStartPauseLog.Enabled:= true;
TempControlForm.btStopLog.Enabled:= true;
Finished:= true;
end;
procedure TStepForm.btPauseClick(Sender: TObject);
begin
if Timer.Enabled then
begin
PauseTime:= Now;
Timer.Enabled:= false;
with DetControlForm do
if Config.AutoReadingStep and (ConnectionKind <> cNone) then
Log.Pause;
with TempControlForm do
if Config.AutoReadingStep and (ConnectionKind <> cNone) then
Log.Pause;
btPause.Caption:= 'Продолжить';
end
else
begin
PauseLength+= Now - PauseTime;
Timer.Enabled:= true;
with DetControlForm do
if Config.AutoReadingStep and (ConnectionKind <> cNone) then
Log.Continue;
with TempControlForm do
if Config.AutoReadingStep and (ConnectionKind <> cNone) then
Log.Continue;
btPause.Caption:= 'Пауза';
end;
end;
procedure TStepForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
if (DetControlForm.Log.State <> lInActive) and
(TempControlForm.Log.State <> lInActive) then
CanClose:= false
else
CanClose:= true;
end;
procedure TStepForm.FormCreate(Sender: TObject);
begin
Finished:= true;
end;
procedure TStepForm.btCancelClick(Sender: TObject);
begin
Finished:= true;
Timer.Enabled:= true;
with DetControlForm do
if Config.AutoReadingStep and (ConnectionKind <> cNone) then
Log.Stop;
with TempControlForm do
if Config.AutoReadingStep and (ConnectionKind <> cNone) then
Log.Stop;
end;
procedure TStepForm.btFinishClick(Sender: TObject);
begin
StepForm.Close;
end;
end.