-
Notifications
You must be signed in to change notification settings - Fork 0
/
DetControlF.pas
1727 lines (1521 loc) · 45.9 KB
/
DetControlF.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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit DetControlF;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, TAGraph, TASeries, TASources, TATools,
TATransformations, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Spin, PairSplitter, Buttons, ComCtrls, Menus, EditBtn, MainF,
BaseConF, ReadingThreads, TACustomSource, AxisSource, Types, LogModule;
type
{ TDetControlForm }
TDetControlForm = class(tConnectionForm)
btAutoPhase: TButton;
btAutoRange: TButton;
btAutoReserve1: TButton;
btAutoReserve2: TButton;
btAutoSensitivity: TButton;
btStartPauseLog: TButton;
btStopLog: TButton;
btClear: TButton;
btOffset: TButton;
cbChart1Show: TComboBox;
cbChart2Show: TComboBox;
cbInputRange: TComboBox;
cbReserve1: TComboBox;
cbReserve2: TComboBox;
cbSampleRate: TComboBox;
cbSensitivity: TComboBox;
cbShowPoints: TCheckBox;
cbCh1: TComboBox;
cbCh2: TComboBox;
cbTimeConstant: TComboBox;
cbXAxis: TComboBox;
cbReadingsMode: TComboBox;
cgTransfer: TCheckGroup;
cbUseGenFreq: TCheckBox;
cbRatio1: TComboBox;
cbRatio2: TComboBox;
ChartToolset: TChartToolset;
DataPointHintTool: TDataPointHintTool;
deDataFileStub: TDirectoryEdit;
ZoomDragTool: TZoomDragTool;
PanDragTool: TPanDragTool;
eDelay: TSpinEdit;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label2: TLabel;
Label29: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label9: TLabel;
GraphSplitter: TPairSplitter;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
ZoomOut: TMenuItem;
ZoomIn: TMenuItem;
RestoreScale: TMenuItem;
Divider: TMenuItem;
PairSplitterSide1: TPairSplitterSide;
PairSplitterSide2: TPairSplitterSide;
eUpdateInterval: TSpinEdit;
Chart1: TChart;
Chart2: TChart;
Chart1LineSeries1: TLineSeries;
Chart2LineSeries1: TLineSeries;
pnGraphControl: TPanel;
pnConnection: TPanel;
pmChart: TPopupMenu;
sbParamScroll: TScrollBox;
sbSettingScroll: TScrollBox;
Source1: TUserDefinedChartSource;
Source2: TUserDefinedChartSource;
UpdateTimer: TTimer;
procedure btAutoPhaseClick(Sender: TObject);
procedure btAutoRangeClick(Sender: TObject);
procedure btAutoReserve1Click(Sender: TObject);
procedure btAutoReserve2Click(Sender: TObject);
procedure btAutoSensitivityClick(Sender: TObject);
procedure btClearClick(Sender: TObject);
procedure btnConnectClick(Sender: TObject); override;
procedure btApplyClick(Sender: TObject);
procedure btOffsetClick(Sender: TObject);
procedure btQueryClick(Sender: TObject); override;
procedure btStartPauseLogClick(Sender: TObject);
procedure btStatusClick(Sender: TObject);
procedure btStopLogClick(Sender: TObject);
procedure cbChart1ShowChange(Sender: TObject);
procedure cbChart2ShowChange(Sender: TObject);
procedure cbReadingsModeChange(Sender: TObject);
procedure ChartMenuItemClick(Sender: TObject);
procedure DataPointHintToolHint(ATool: TDataPointHintTool;
const APoint: TPoint; var AHint: String);
procedure deDataFileStubAcceptDirectory(Sender: TObject; var Value: String
);
procedure deDataFileStubEditingDone(Sender: TObject);
procedure ParamsChange(Sender: TObject);
procedure cbShowPointsChange(Sender: TObject);
procedure cbUseGenFreqChange(Sender: TObject);
procedure cbXAxisChange(Sender: TObject);
procedure cgTransferItemClick(Sender: TObject; Index: integer);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure GraphSplitterResize(Sender: TObject);
procedure pmChartPopup(Sender: TObject);
procedure RestoreScaleClick(Sender: TObject);
procedure Source1GetChartDataItem(ASource: TUserDefinedChartSource;
AIndex: Integer; var AItem: TChartDataItem);
procedure Source2GetChartDataItem(ASource: TUserDefinedChartSource;
AIndex: Integer; var AItem: TChartDataItem);
procedure UpdateTimerTimer(Sender: TObject);
procedure ZoomInClick(Sender: TObject);
procedure ZoomOutClick(Sender: TObject);
private
{ private declarations }
ForceStop: boolean;
DrawnBuffers: longword;//for continuous buffer (not implemented)
t, SampleRate: double; //t for buffer and writing to sources
ReadingMode: eReadMode;
MaxSimultPars, TotalPars,
ReferenceIndex, CH1Index, CH2Index: shortint; { TODO 2 -cImprovement : to device record }
PointsInBuffer: longword;
iTC, iSe, iPa, iCH1, iCH2, iRCH1, iRCH2, iBF, iCR, iWR, iRa{, iOf}: array of string;
ReadPars: array of boolean;
srcFreq, srcAmpl, srcCH1, srcCH2: TAxisSource;
procedure CheckTransferCount;
//methods for logmodule events
procedure BeforeStart(Sender: tLogModule);
procedure Start(Sender: tLogModule);
procedure Pause(Sender: tLogModule);
procedure Continue(Sender: tLogModule);
procedure Stop(Sender: tLogModule);
//Also createFile
function SaveLog(Sender: tLogModule):integer;
procedure StateChange(Sender: tLogModule);
procedure ProcessBuffers(Sender: tLogModule);
public
{ public declarations }
LogStub, LogExtension, DataFolder: string;
Log: tLogModule;
ParToRead: array of shortint;
LogTime, LogFreq, LogAmpl, UseGenFreq, OnePointPerStep, OffsetTracked,
AutoApply: boolean;
TimeStep: double;
//for logmodule event
procedure CreateFile(Sender: tLogModule);
procedure EnableControls(Enable: boolean); override;
procedure GetDeviceParams; override;
procedure AfterConnect; override;
function RecvSnap(p: array of shortint): PBuffer;
end;
var
DetControlForm: TDetControlForm;
implementation
uses
DateUtils, StrUtils, TAChartUtils, stepf, optionf, DeviceF, TempControlF,
OffsetF
{$IFOPT D+}
,synaser
{$ENDIF}
;
procedure TDetControlForm.Source1GetChartDataItem(
ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
var
i: word;
Src: TAxisSource;
begin
case cbXAxis.ItemIndex of
0: if LogTime then
AItem.X:= Log.srcTime.Values[Aindex];
1: if LogFreq then
begin
if UseGenFreq then
AItem.X:= srcFreq.Values[Aindex]
else
AItem.X:= Log.CoordinateSources[ReferenceIndex].Values[Aindex];
end;
2: if LogAmpl then
AItem.X:= srcAmpl.Values[Aindex];
end;
{ TODO 3 -cFeature : show gen freq? }
if (ReadingMode = rBuffer) then
i:= 0
else
i:= cbChart1Show.ItemIndex;
Src:= Log.CoordinateSources[i];
if Src <> nil then
AItem.Y:= Src.Values[Aindex]
else Source1.PointsNumber:= 0;
end;
procedure TDetControlForm.Source2GetChartDataItem(
ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
var
i: word;
Src: TAxisSource;
begin
case cbXAxis.ItemIndex of
0: if LogTime then
AItem.X:= Log.srcTime.Values[Aindex];
1: if logFreq then
begin
if UseGenFreq then
AItem.X:= srcFreq.Values[Aindex]
else
AItem.X:= Log.CoordinateSources[ReferenceIndex].Values[Aindex];
end;
2: if LogAmpl then
AItem.X:= srcAmpl.Values[Aindex];
end;
if ReadingMode = rBuffer then
i:= 1
else
i:= cbChart2Show.ItemIndex;
Src:= Log.CoordinateSources[i];
if Src <> nil then
AItem.Y:= Src.Values[Aindex]
else Source2.PointsNumber:= 0;
end;
procedure TDetControlForm.FormCreate(Sender: TObject);
var
i: longint;
begin
WriteProgramLog('Creating Readings form');
Top:= MainForm.Top;
Left:= MainForm.Left + MainForm.Width + 8;
btQuery.Caption:= 'Запрос' + LineEnding + 'текущих' + LineEnding + 'значений';
btReset.Caption:= 'Сбросить' + LineEnding + 'настройки'+ LineEnding + 'прибора';
btCustomCommand.Caption:= 'Польз.' + LineEnding + 'команда';
btStatus.Caption:= 'Состояние' + LineEnding + ' прибора';
DisplayMessages:= true;
ParamsApplied:= false;
MaxSimultPars:= -1;
DeviceKind:= dDetector;
DeviceIndex:= iDefaultDevice;
ConnectionKind:= cNone;
DrawnBuffers:= 0;
t:= 0;
DataFolder:= DefaultLogFolder;
LogStub:= '';
LogFreq:= false;
LogTime:= true;
LogAmpl:= false;
for i:= 0 to PortCount - 1 do
cbPortSelect.AddItem(MainForm.cbPortSelect.Items[i], nil);
if cbPortSelect.ItemIndex < 0 then
cbPortSelect.ItemIndex:= 0;
if PortCount = 1 then
StatusBar.Panels[spStatus].Text:= 'Нет доступных COM-портов';
Log:= tLogModule.Create;
Log.OnBeforeStart:= @BeforeStart;
Log.OnStart:= @Start;
Log.OnPause:= @Pause;
Log.OnContinue:= @Continue;
Log.OnStop:= @Stop;
Log.OnCreateFile:= @CreateFile;
Log.OnSaveLog:= @SaveLog;
Log.OnStateChange:= @StateChange;
Log.OnProcessBuffers:= @ProcessBuffers;
InitCriticalSection(CommCS);
end;
procedure TDetControlForm.FormDestroy(Sender: TObject);
begin
Log.Stop;
btClearClick(Self);
btnDisconnectClick(Self);
Log.Free;
DoneCriticalSection(CommCS);
end;
procedure TDetControlForm.FormShow(Sender: TObject);
begin
GetSupportedDevices(DeviceKind);
if cbRatio1.ItemIndex < 0 then
cbRatio1.ItemIndex:= 0;
if cbRatio2.ItemIndex < 0 then
cbRatio2.ItemIndex:= 0;
end;
procedure TDetControlForm.GraphSplitterResize(Sender: TObject);
begin
with GraphSplitter do
Position:= Width div 2;
end;
procedure TDetControlForm.pmChartPopup(Sender: TObject);
var
i: integer;
cb: tCombobox;
begin
with TChart(pmChart.PopupComponent) do
case Name of
'Chart1': cb:= cbChart1Show;
'Chart2': cb:= cbChart2Show;
else cb:= cbChart1Show;
end;
with cb do
begin
if ItemIndex >= 0 then
begin
for i:= 0 to pmChart.Items.Count - 1 do
pmChart.Items[i].Checked:= false;
if ItemIndex + 4 < pmChart.Items.Count then
pmChart.Items[ItemIndex + 4].Checked:= true;
end;
end;
end;
procedure TDetControlForm.EnableControls(Enable: boolean); //+++
begin
btOffset.Enabled:= Enable;
btApply.Enabled:= Enable;
btStartPauseLog.Enabled:= Enable;
btStopLog.Enabled:= Enable;
btCustomCommand.Enabled:= Enable;
btReset.Enabled:= Enable;
btStatus.Enabled:= Enable;
btQuery.Enabled:= Enable;
cbReadingsMode.Enabled:= Enable;
cbUseGenFreq.Enabled:= Enable;
cbSampleRate.Enabled:= Enable;
cbTimeConstant.Enabled:= Enable;
cbSensitivity.Enabled:= Enable;
cbReserve1.Enabled:= Enable;
cbReserve2.Enabled:= Enable;
cbInputRange.Enabled:= Enable;
btAutoPhase.Enabled:= Enable;
btAutoSensitivity.Enabled:= Enable;
btAutoReserve1.Enabled:= Enable;
btAutoReserve2.Enabled:= Enable;
btAutoRange.Enabled:= Enable;
cbUseGenFreq.Enabled:= Enable;
cbCh1.Enabled:= Enable;
cbCh2.Enabled:= Enable;
cbRatio1.Enabled:= Enable;
cbRatio2.Enabled:= Enable;
eDelay.Enabled:= Enable;
end;
procedure TDetControlForm.GetDeviceParams;
var
i, c: integer;
s: string;
begin
{$IFOPT D+}
if Debug then
if DeviceIndex = 0 then
begin
deviceindex:= 1;
connectionkind:= cserial;
DetControlForm.serport:= tblockserial.create;
end;
{$ENDIF}
for i:= 4 to pmChart.Items.Count - 1 do
pmChart.Items.Delete(4);
with DeviceForm.sgDetCommands do
begin
SeparateIndices(Cells[DeviceIndex, integer(hTimeConstOptions)], cbTimeConstant.Items, iTC);
SeparateIndices(Cells[DeviceIndex, integer(hSensitivityOptions)], cbSensitivity.Items, iSe);
SeparateIndices(Cells[DeviceIndex, integer(hTransferParams)], cgTransfer.Items, iPa);
if cgTransfer.Width < 90 then
begin
cgTransfer.Columns:= 2;
end
else
begin
cgTransfer.Columns:= 1;
end;
cbChart1Show.Items:= cgTransfer.Items;
cbChart2Show.Items:= cgTransfer.Items;
for i:= 0 to cgTransfer.Items.Count - 1 do
with pmChart do
begin
Items.Add(tMenuItem.Create(pmChart));
Items[Items.Count - 1].Caption:= cgTransfer.Items[i];
Items[Items.Count - 1].OnClick:= @ChartMenuItemClick;
end;
SeparateIndices(Cells[DeviceIndex, integer(hCH1Options)], cbCh1.Items, iCH1);
SeparateIndices(Cells[DeviceIndex, integer(hCH2Options)], cbCh2.Items, iCH2);
SeparateIndices(Cells[DeviceIndex, integer(hRatio1Options)], cbRatio1.Items, iRCH1);
SeparateIndices(Cells[DeviceIndex, integer(hRatio2Options)], cbRatio2.Items, iRCH2);
SeparateIndices(Cells[DeviceIndex, integer(hBufferRateOptions)], cbSampleRate.Items, iBF);
SeparateIndices(Cells[DeviceIndex, integer(hCloseReserveOptions)], cbReserve1.Items, iCR);
SeparateIndices(Cells[DeviceIndex, integer(hWideReserveOptions)], cbReserve2.Items, iWR);
SeparateIndices(Cells[DeviceIndex, integer(hRangeOptions)], cbInputRange.Items, iRa);
MinDelay:= valf(Cells[DeviceIndex, integer(hMinDelay)]);
eDelay.MinValue:= MinDelay;
TotalPars:= cgTransfer.Items.Count;
setlength(ReadPars, TotalPars);
MaxSimultPars:= valf(Cells[DeviceIndex, integer(hMaxSimultPars)]);
setlength(ParToRead, MaxSimultPars);
PointsInBuffer:= valf(Cells[DeviceIndex, integer(hPointsInBuffer)]);
s:= Cells[DeviceIndex, integer(hIndices)];
i:= pos(',', s);
if i = 0 then
ReferenceIndex:= valf(s)
else
begin
ReferenceIndex:= valf(copy(s, 1, i - 1));
delete(s, 1, i);
i:= pos(',', s);
CH1Index:= valf(copy(s, 1, i - 1));
delete(s, 1, i);
CH2Index:= valf(s);
end;
end;
if OffsetForm.GetParams > 0 then
btOffset.Show
else
btOffset.Hide;
if cbRatio1.Items.Count = 0 then
begin
cbRatio1.Hide;
Label14.Hide;
cbRatio2.Hide;
Label15.Hide;
end
else
begin
cbRatio1.Show;
Label14.Show;
cbRatio2.Show;
Label15.Show;
end;
if cbReserve1.Items.Count = 0 then
begin
cbReserve1.Hide;
btAutoReserve1.Hide;
Label16.Hide;
end
else
begin
cbReserve1.Show;
btAutoReserve1.Show;
Label16.Show;
end;
if cbReserve2.Items.Count = 0 then
begin
cbReserve2.Hide;
btAutoReserve2.Hide;
Label17.Hide;
end
else
begin
cbReserve2.Show;
btAutoReserve2.Show;
Label17.Show;
end;
if cbInputRange.Items.Count = 0 then
begin
cbInputRange.Hide;
btAutoRange.Hide;
Label18.Hide;
end
else
begin
cbInputRange.Show;
btAutoRange.Show;
Label18.Show;
end;
c:= 0;
for i:= 0 to cgTransfer.Items.Count - 1 do
if cgTransfer.Checked[i] then
inc(c);
if c < 2 then
begin
cgTransfer.Checked[ReferenceIndex]:= true;
if CH1Index >= 0 then
cgTransfer.Checked[CH1Index]:= true;
if (CH2Index >= 0) and (c + 2 < MaxSimultPars) then
cgTransfer.Checked[CH2Index]:= true;
end;
deDataFileStubEditingDone(Self);
end;
procedure TDetControlForm.AfterConnect;
begin
inherited AfterConnect;
Params.DetectorPort:= DetControlForm.CurrentDevice^.Port;
Params.LastDetector:= DetControlForm.CurrentDevice^.Model;
OptionForm.eDevice1.ItemIndex:= DeviceIndex - 1;
cbReadingsModeChange(Self);
CheckTransferCount; //this needs to happen after restorestate
EnterCriticalSection(CommCS);
AddCommand(dResetStorage);
PassCommands;
LeaveCriticalSection(CommCS);
end;
procedure TDetControlForm.UpdateTimerTimer(Sender: TObject);
begin
Log.ProcessBuffers;
end;
procedure TDetControlForm.ZoomInClick(Sender: TObject);
var
c: tChart;
Rect: tDoubleRect;
Center: tDoublePoint;
begin
c:= tChart(pmChart.PopupComponent);
with c do
begin
Rect:= CurrentExtent;
Center.x:= (Rect.a.x + Rect.b.x) / 2;
Center.y:= (Rect.a.y + Rect.b.y) / 2;
Rect.a.x:= (Rect.a.x - Center.X) / ChartZoomFactor + Center.X;
Rect.b.x:= (Rect.b.x - Center.X) / ChartZoomFactor + Center.X;
Rect.a.y:= (Rect.a.y - Center.y) / ChartZoomFactor + Center.Y;
Rect.b.y:= (Rect.b.y - Center.y) / ChartZoomFactor + Center.Y;
LogicalExtent:= Rect;
end;
end;
procedure TDetControlForm.ZoomOutClick(Sender: TObject);
var
c: tChart;
Rect: tDoubleRect;
Center: tDoublePoint;
begin
c:= tChart(pmChart.PopupComponent);
with c do
begin
Rect:= CurrentExtent;
Center.x:= (Rect.a.x + Rect.b.x) / 2;
Center.y:= (Rect.a.y + Rect.b.y) / 2;
Rect.a.x:= (Rect.a.x - Center.X) * ChartZoomFactor + Center.X;
Rect.b.x:= (Rect.b.x - Center.X) * ChartZoomFactor + Center.X;
Rect.a.y:= (Rect.a.y - Center.y) * ChartZoomFactor + Center.Y;
Rect.b.y:= (Rect.b.y - Center.y) * ChartZoomFactor + Center.Y;
LogicalExtent:= Rect;
end;
end;
procedure TDetControlForm.CheckTransferCount;
var
i, ParNum: word;
begin
ParNum:= 0;
with cgTransfer do
begin
for i:= 0 to Items.Count - 1 do
if Checked[i] then
inc(ParNum);
if ParNum = MaxSimultPars then
begin
for i:= 0 to Items.Count - 1 do
if not Checked[i] then
CheckEnabled[i]:= false;
end
else
if ParNum < MaxSimultPars then
begin
for i:= 0 to Items.Count - 1 do
CheckEnabled[i]:= true;
end
else
begin
Showmessage('Превышено максимальное число параметров - сброс');
for i:= 0 to Items.Count - 1 do
Checked[i]:= false;
cgTransfer.Checked[ReferenceIndex]:= true;
if CH1Index >= 0 then
cgTransfer.Checked[CH1Index]:= true
else
cgTransfer.Checked[0]:= true;
for i:= 0 to Items.Count - 1 do
CheckEnabled[i]:= true;
end;
if ParNum < 2 then
begin
cbReadingsMode.ItemIndex:= 0;
cgTransfer.Enabled:= false;
end;
end;
cbReadingsModeChange(Self);
end;
procedure TDetControlForm.RestoreScaleClick(Sender: TObject);
begin
tChart(pmChart.PopupComponent).ZoomFull(true);
end;
procedure TDetControlForm.BeforeStart(Sender: tLogModule);
var
i, j: integer;
begin
with Sender do
begin
//btStartPauseLog.Caption:= 'Приостановить'; //to an event onbeforestart
WriteProgramLog('Data collection start');
btClearClick(Self);
if AutoApply and (StepForm.Finished or not DetControlForm.ParamsApplied) then //skip if stepf is already going
begin
SetCursorAll(crHourGlass);
DetControlForm.btApplyClick(Self);
sleep(DetControlForm.eDelay.Value);
end;
SetCursorAll(crDefault);
ReadingMode:= eReadMode(cbReadingsMode.ItemIndex);
case ReadingMode of
rSimultaneous:
begin
if LogFreq and (not cgTransfer.Checked[ReferenceIndex]) and (not UseGenFreq) then //when logfreq set by mainform
begin
if cgTransfer.CheckEnabled[ReferenceIndex] then
cgTransfer.Checked[ReferenceIndex]:= true
else
begin
ShowMessage('Необходимо логирование опорной чатоты');
WriteProgramLog('Data collection could not start: not logging ref');
//btStartPauseLog.Caption:= 'Начать снятие';
exit;
end;
cgTransferItemClick(Self, -1);
end;
if not cgTransfer.Enabled then
begin
ShowMessage('Необходимо логирование опорной чатоты');
WriteProgramLog('Data collection could not start: not logging ref');
//btStartPauseLog.Caption:= 'Начать снятие';
exit;
end;
LogTime:= true;
if cgTransfer.Checked[ReferenceIndex] and (not LogFreq)
then LogFreq:= true;
j:= 0;
with cgTransfer do
begin
for i:= 0 to high(ReadPars) do
begin
ReadPars[i]:= false;
if Checked[i] then
begin
ReadPars[i]:= true;
ParToRead[j]:= i;
inc(j);
end;
end;
end;
for i:= j to high(ParToRead) do
ParToRead[i]:= -1;
setlength(CoordinateSources, cgTransfer.Items.Count);
for j:= 0 to high(ParToRead) do
begin
if ParToRead[j] < 0 then
break;
CoordinateSources[ParToRead[j]]:= TAxisSource.Create(128);
end;
if CH1Index >= 0 then
srcCH1:= CoordinateSources[CH1Index];
if CH2Index >= 0 then
srcCH2:= CoordinateSources[CH2Index];
end;
rBuffer:
begin
LogTime:= true; //???
if LogFreq then
cbUseGenFreq.Checked:= true;
cbUseGenFreqChange(Self);
setlength(CoordinateSources, 2);
CoordinateSources[0]:= TAxisSource.Create(128);
CoordinateSources[1]:= TAxisSource.Create(128);
srcCH1:= CoordinateSources[0];
srcCH2:= CoordinateSources[1];
end;
end;
if LogTime then
srcTime:= TAxisSource.Create(128);
if LogFreq and UseGenFreq then
srcFreq:= TAxisSource.Create(128);
if LogAmpl then
srcAmpl:= TAxisSource.Create(128);
if ReadingMode = rBuffer then
begin
cbChart1Show.ItemIndex:= cbChart1Show.Items.IndexOf(cbCH1.Text);
cbChart2Show.ItemIndex:= cbChart2Show.Items.IndexOf(cbCH2.Text);
end;
if SampleRate <> 0 then
TimeStep:= 1/SampleRate
else
TimeStep:= 1;
if not OnePointPerStep then
begin
UpdateTimer.Interval:= eUpdateInterval.Value;
UpdateTimer.Enabled:= true;
end;
t:= 0;
end;
end;
procedure TDetControlForm.Start(Sender: tLogModule);
begin
with Sender do
case ReadingMode of //onstart
rBuffer:
begin
EnterCriticalSection(CommCS);
AddCommand(dStartStorage);
PassCommands;
LeaveCriticalSection(CommCS);
ReadingsThread:= tDetBufferThread.Create(PointsInBuffer);
end;
rSimultaneous:
begin
if OnePointPerStep then
ReadingsThread:= nil //Assigned in stepform
else
ReadingsThread:= tDetSimultaneousThread.Create;
end;
end;
end;
procedure TDetControlForm.Pause(Sender: tLogModule);
begin
// btStartPauseLog.Caption:= 'Продолжить'; //event onpause
WriteProgramLog('Data collection pause');
UpdateTimer.Enabled:= false;
if ReadingMode = rBuffer then
begin
EnterCriticalSection(CommCS);
AddCommand(dPauseStorage);
PassCommands;
LeaveCriticalSection(CommCS);
end;
end;
procedure TDetControlForm.Continue(Sender: tLogModule);
begin
//btStartPauseLog.Caption:= 'Приостановить';
WriteProgramLog('Data collection resume');
UpdateTimer.Enabled:= true;
if ReadingMode = rBuffer then
begin
EnterCriticalSection(CommCS);
AddCommand(dStartStorage);
PassCommands;
LeaveCriticalSection(CommCS);
end;
with Sender do
case ReadingMode of
rBuffer:
ReadingsThread:= tDetBufferThread.Create(PointsInBuffer);
rSimultaneous:
begin
if OnePointPerStep then
ReadingsThread:= nil // Stepf
else
ReadingsThread:= tDetSimultaneousThread.Create;
end;
end;
end;
procedure TDetControlForm.Stop(Sender: tLogModule);
begin
UpdateTimer.Enabled:= false; //to event OnStop
if (ReadingMode = rBuffer) or (ForceStop and (Log.State = lInActive)) then
begin
EnterCriticalSection(CommCS);
AddCommand(dResetStorage);
PassCommands;
LeaveCriticalSection(CommCS);
ForceStop:= false;
end;
OnePointPerStep:= false;
if (Log.State <> lInActive) and AutoApply then
begin
if Config.AutoReport then { TODO 2 -cImprovement : a new texperiment class to keep track of conflicting shit like this }
MainForm.SaveReport(false, MainForm.ReportHeader);
inc(ExperimentNumber);
end;
end;
procedure TDetControlForm.CreateFile(Sender: tLogModule);
var
s1, s2: string;
i: integer;
begin
with Sender do
begin
FilePath:= DataFolder;
DateTimeToString(FileName, DefaultTimeFormat, Now);
Stub:= LogStub;
if LogExtension <> '' then
Extension:= LogExtension
else
Extension:= LogExtensions[integer(dDetector)];
if LogTime then
Header:= Header + cbXAxis.Items.Strings[0] + HT;
if LogFreq and UseGenFreq then
Header:= Header + 'Частота (генератор)' + HT;
if LogAmpl then
Header:= Header + 'Амплитуда (генератор)' + HT;
case ReadingMode of
rBuffer:
Header:= Header + cbCh1.Text + HT + cbCh2.Text;
rSimultaneous:
begin
for i:= 0 to high(ParToRead) do
begin
if ParToRead[i] = -1 then break;
if ParToRead[i] = CH1Index then
Header:= Header + 'Дисп.1 (' + cbCh1.Text + ')' + HT
else
if ParToRead[i] = CH2Index then
Header:= Header + 'Дисп.2 (' + cbCh2.Text + ')' + HT
else
Header:= Header + cbChart1Show.Items[ParToRead[i]];
Header:= Header + HT;
end;
end;
end;
Header:= Header + LineEnding;
end;
end;
function TDetControlForm.SaveLog(Sender: tLogModule): integer;
var
i, j: integer;
s: string;
Sources: array of tAxisSource;
begin
with Sender do
begin
if IsEmptyStr(FileName, [' ']) then
exit(-1);
if LogTime then
begin
setlength(Sources, length(Sources) + 1);
Sources[high(Sources)]:= SrcTime;
end;
if LogFreq and UseGenFreq then
begin
setlength(Sources, length(Sources) + 1);
Sources[high(Sources)]:= SrcFreq;
end;
if LogAmpl then
begin
setlength(Sources, length(Sources) + 1);
Sources[high(Sources)]:= SrcAmpl;
end;
case ReadingMode of
rBuffer:
begin
setlength(Sources, length(Sources) + 2);
Sources[high(Sources) - 1]:= CoordinateSources[0];
Sources[high(Sources)]:= CoordinateSources[1];
end;
rSimultaneous:
begin
for i:= 0 to cgTransfer.Items.Count - 1 do
if ReadPars[i] then
begin
setlength(Sources, length(Sources) + 1);
Sources[high(Sources)]:= CoordinateSources[i];
end;
end;
end;
Result:= length(Sources);
if assigned(ExperimentLog) then
for i:= 0 to ReadPoints - 1 do
begin
s:= '';
for j:= 0 to high(Sources) do
s+= strf(Sources[j].Values[i]) + HT;
s+= LineEnding;
ExperimentLog.Write(s[1], length(s))
end
else
exit(-2);
StatusBar.Panels[spStatus].Text:= 'Данные сохранены в ' + FileName;
end;
end;
procedure TDetControlForm.StateChange(Sender: tLogModule);
begin
with tLogModule(Sender) do
if State = lActive then
begin
btStartPauseLog.Caption:= PauseCaption;
btReset.Enabled:= false;
cbCh1.Enabled:= false;
cbCh2.Enabled:= false;
cbRatio1.Enabled:= false;
cbRatio2.Enabled:= false;
cbReadingsMode.Enabled:= false;
cbSampleRate.Enabled:= false;
cbTimeConstant.Enabled:= false;
cbSensitivity.Enabled:= false;
cbReserve1.Enabled:= false;
cbReserve2.Enabled:= false;