-
Notifications
You must be signed in to change notification settings - Fork 0
/
TempControlF.pas
1339 lines (1171 loc) · 34.4 KB
/
TempControlF.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 TempControlF;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, TASources, TATools, TAGraph, TASeries, Forms,
Controls, Graphics, Dialogs, ExtCtrls, Buttons, StdCtrls, Spin, Menus,
ComCtrls, EditBtn, Types, BaseConF, LogModule, TACustomSource, AxisSource;
type
{ TTempControlForm }
TTempControlForm = class(tConnectionForm)
btClear: TButton;
btStartPauseLog: TButton;
btStopLog: TButton;
cbChartShow: TComboBox;
cbReadingsMode: TComboBox;
cbSampleRate: TComboBox;
cbShowPoints: TCheckBox;
cbXAxis: TComboBox;
cgTransfer: TCheckGroup;
Chart: TChart;
ChartLineSeries: TLineSeries;
ChartToolset: TChartToolset;
DataPointHintTool: TDataPointHintTool;
Divider: TMenuItem;
eDelay: TSpinEdit;
eUpdateInterval: TSpinEdit;
deDataFileStub: TDirectoryEdit;
Label1: TLabel;
Label11: TLabel;
Label13: TLabel;
Label2: TLabel;
Label29: TLabel;
Label4: TLabel;
Label5: TLabel;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
PanDragTool: TPanDragTool;
pmChart: TPopupMenu;
pnConnection: TPanel;
pnGraphControl: TPanel;
RestoreScale: TMenuItem;
sbParamScroll: TScrollBox;
Source: TUserDefinedChartSource;
UpdateTimer: TTimer;
ZoomDragTool: TZoomDragTool;
ZoomIn: TMenuItem;
ZoomOut: TMenuItem;
procedure btApplyClick(Sender: TObject);
procedure btClearClick(Sender: TObject);
procedure btnConnectClick(Sender: TObject); override;
procedure btStartPauseLogClick(Sender: TObject);
procedure btStopLogClick(Sender: TObject);
procedure cbChartShowChange(Sender: TObject);
procedure cbReadingsModeChange(Sender: TObject);
procedure cbSampleRateChange(Sender: TObject);
procedure cbShowPointsChange(Sender: TObject);
procedure cgTransferItemClick(Sender: TObject; Index: integer);
procedure DataPointHintToolHint(ATool: TDataPointHintTool;
const APoint: TPoint; var AHint: String);
procedure deDataFileStubAcceptDirectory(Sender: TObject; var Value: String);
procedure deDataFileStubEditingDone(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btQueryClick(Sender: TObject); override;
procedure ChartMenuItemClick(Sender: TObject);
procedure pmChartPopup(Sender: TObject);
procedure RestoreScaleClick(Sender: TObject);
procedure SourceGetChartDataItem(ASource: TUserDefinedChartSource;
AIndex: Integer; var AItem: TChartDataItem);
procedure UpdateTimerTimer(Sender: TObject);
procedure ZoomInClick(Sender: TObject);
procedure ZoomOutClick(Sender: TObject);
private
{ private declarations }
srcFreq, srcAmpl: TAxisSource;
t: double;
ReadingMode: eReadMode;
MacroCrutch: string;
iPA, iBu: array of string;
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, OnePointPerStep, AutoApply: boolean;
//for logmodule
procedure CreateFile(Sender: tLogModule);
procedure EnableControls(Enable: boolean); override;
procedure GetDeviceParams; override;
procedure AfterConnect; override;
function RecvSnap(p: array of shortint): PBuffer; //not really a snap since not guaranteed simult
end;
var
TempControlForm: TTempControlForm;
implementation
uses
Dateutils, StrUtils, TAChartUtils, DeviceF, MainF, StepF, DetControlF,
ReadingThreads
{$IFOPT D+}
,tlntsend
{$ENDIF}
;
{$R *.lfm}
{ TTempControlForm }
procedure TTempControlForm.FormCreate(Sender: TObject);
var
i: integer;
begin
WriteProgramLog('Creating TempControl form');
Top:= MainForm.Top;
Left:= DetControlForm.Left + DetControlForm.Width + 8;
btQuery.Caption:= 'Запрос' + LineEnding + 'текущих' + LineEnding + 'значений';
btReset.Caption:= 'Сбросить' + LineEnding + 'настройки'+ LineEnding + 'прибора';
btCustomCommand.Caption:= 'Польз.' + LineEnding + 'команда';
btStatus.Caption:= 'Состояние' + LineEnding + ' прибора';
DisplayMessages:= true;
ParamsApplied:= false;
//MaxSimultPars:= -1;
DeviceKind:= dTempController;
DeviceIndex:= iDefaultDevice;
ConnectionKind:= cNone;
t:= 0;
DataFolder:= DefaultLogFolder;
LogStub:= '';
//DrawnBuffers:= 0;
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 TTempControlForm.FormDestroy(Sender: TObject);
begin
Log.Stop;
btClearClick(Self);
btnDisconnectClick(Self);
Log.Free;
DoneCriticalSection(CommCS);
end;
procedure TTempControlForm.FormShow(Sender: TObject);
begin
GetSupportedDevices(DeviceKind);
Chart.Height:= DetControlForm.Chart1.Height; //crutch to avoid misalignment in different OS's
end;
procedure TTempControlForm.btQueryClick(Sender: TObject);
var
s: string;
i: integer;
begin
EnterCriticalSection(CommCS);
Purge;
AddCommand(tSampleRate, true);
PassCommands;
s:= RecvString;
LeaveCriticalSection(CommCS);
if CurrentDevice^.Model = 'PTC10' then //FUCK PTC10 it returns strings different from those it takes
begin
for i:= 0 to high(iBu) do
if AnsiContainsText(iBu[i], s) then
cbSampleRate.ItemIndex:= i;
end
else
begin
i:= AnsiIndexText(s, iBu);
if i>= 0 then
cbSampleRate.ItemIndex:= i;
end;
end;
procedure TTempControlForm.ChartMenuItemClick(Sender: TObject);
var
cb: tComboBox;
i: integer;
begin
cb:= cbChartShow;
with cb do
begin
ItemIndex:= Items.IndexOf(tMenuItem(Sender).Caption);
if ItemIndex >= 0 then
begin
for i:= 0 to pmChart.Items.Count - 1 do
pmChart.Items[i].Checked:= false;
tMenuItem(Sender).Checked:= true;
end;
OnChange(Self);
end;
end;
procedure TTempControlForm.pmChartPopup(Sender: TObject);
var
i: integer;
begin
with cbChartShow 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 TTempControlForm.SourceGetChartDataItem(
ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
var
Src: TAxisSource;
begin
case cbXAxis.ItemIndex of
0: if LogTime then
AItem.X:= Log.srcTime.Values[Aindex];
1: if LogFreq then
AItem.X:= srcFreq.Values[Aindex];
2: if LogAmpl then
AItem.X:= srcAmpl.Values[Aindex];
end;
{ TODO 3 -cFeature : show gen freq? }
{if (ReadingMode = rBuffer) then
i:= 0
else
i:= cbChartShow.ItemIndex;}
Src:= Log.CoordinateSources[cbChartShow.ItemIndex];
//try
if Src <> nil then
AItem.Y:= Src.Values[Aindex]
else ASource.PointsNumber:= 0;
{except
on e:exception do writeprogramlog(e.message +' '+ strf(aindex)+' ' + strf(ASource.PointsNumber) +' '+ strf(src.count))
end;}
end;
procedure TTempControlForm.UpdateTimerTimer(Sender: TObject);
begin
Log.ProcessBuffers;
end;
procedure TTempControlForm.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 TTempControlForm.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 TTempControlForm.CheckTransferCount;
var
i, ParNum: integer;
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
for i:= 0 to Items.Count - 1 do
CheckEnabled[i]:= true; }
case ParNum of
0:
begin
ShowMessage('Ошибка: не выбрано ни одного параметра');
Checked[0]:= true;
end;
1:
begin
for i:= 0 to Items.Count - 1 do
if Checked[i] then
CheckEnabled[i]:= false
else
CheckEnabled[i]:= true;
end;
else
for i:= 0 to Items.Count - 1 do
CheckEnabled[i]:= true;
end;
if ParNum < 1 then
begin
end;
end;
end;
procedure TTempControlForm.RestoreScaleClick(Sender: TObject);
begin
tChart(pmChart.PopupComponent).ZoomFull(true);
end;
procedure TTempControlForm.BeforeStart(Sender: tLogModule);
var
i, j: integer;
//s: string;
begin
with Sender do
begin
//btStartPauseLog.Caption:= 'Приостановить'; //to an event onbeforestart
WriteProgramLog('Data collection start');
btClearClick(Self);
if AutoApply and (StepForm.Finished or not TempControlForm.ParamsApplied) then //skip if stepf is already going
begin
SetCursorAll(crHourGlass);
TempControlForm.btApplyClick(Self);
sleep(TempControlForm.eDelay.Value);
end;
SetCursorAll(crDefault);
ReadingMode:= eReadMode(cbReadingsMode.ItemIndex);
case ReadingMode of
rBuffer:
exit;
rSimultaneous:
begin
LogTime:= true;
j:= 0;
with cgTransfer do
begin
for i:= 0 to Items.Count - 1 do //count checked
if Checked[i] then
inc(j);
setlength(ParToRead, j);
j:= 0;
for i:= 0 to Items.Count - 1 do //set partoread
if Checked[i] then
begin
ParToRead[j]:= i;
inc(j);
end;
end;
setlength(CoordinateSources, cgTransfer.Items.Count);
for j:= 0 to high(ParToRead) do
CoordinateSources[ParToRead[j]]:= TAxisSource.Create(128);
end;
rRealTime:
begin
LogTime:= true;
j:= 0;
with cgTransfer do
begin
for i:= 0 to Items.Count - 1 do //count checked
if Checked[i] then
inc(j);
setlength(ParToRead, j);
j:= 0;
for i:= 0 to Items.Count - 1 do //set partoread
if Checked[i] then
begin
ParToRead[j]:= i;
inc(j);
end;
end;
setlength(CoordinateSources, cgTransfer.Items.Count);
for j:= 0 to high(ParToRead) do
CoordinateSources[ParToRead[j]]:= TAxisSource.Create(128);
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 then
srcFreq:= TAxisSource.Create(128);
if LogAmpl then
srcAmpl:= TAxisSource.Create(128);
if not OnePointPerStep then
begin
UpdateTimer.Interval:= eUpdateInterval.Value;
UpdateTimer.Enabled:= true;
end;
t:= 0;
end;
{EnterCriticalSection(CommCS); //dont even need it
AddCommand(tGetChannelNames);
PassCommands;
s:= RecvString;
LeaveCriticalSection(CommCS);}
end;
procedure TTempControlForm.Start(Sender: tLogModule);
var
s: string;
i: integer;
begin
with Sender do
case ReadingMode of //onstart
rBuffer:
begin
AddCommand(tResetStorage);
AddCommand(tStartStorage);
PassCommands;
ReadingsThread:= nil;//tDetBufferThread.Create(PointsInBuffer);
end;
rSimultaneous:
begin
if OnePointPerStep then
ReadingsThread:= nil //Assigned in stepform
else
ReadingsThread:= tTempSimultaneousThread.Create;
end;
rRealTime:
begin
if CurrentDevice^.Model = 'PTC10' then //srsly, fuck ptc10. who coded this? can't transfer buffer other than 1 point at a time? also macros are shit. cant even form custom strings. i am not writing another command architecture to accomodate this bullshit.
begin
s:= '';
for i:= 0 to high(ParToRead) do
s+= 'getlog ' + cgTransfer.Items[ParToRead[i]] + ', next; ';
s+= ' }';
EnterCriticalSection(CommCS);
AddCommand(tResetStorage);
//AddCommand(tStartRealTime);
commandstring+= '; name RTAMacro; while (1) { ' + s;
MacroCrutch:= CommandString; //needed to continue
PassCommands;
LeaveCriticalSection(CommCS);
end
else
begin
EnterCriticalSection(CommCS);
AddCommand(tResetStorage);
AddCommand(tStartRealTime);
PassCommands;
LeaveCriticalSection(CommCS);
end;
ReadingsThread:= tTempRealTimeThread.Create;
end;
end;
end;
procedure TTempControlForm.Pause(Sender: tLogModule);
begin
WriteProgramLog('Data collection pause');
UpdateTimer.Enabled:= false;
case ReadingMode of
rBuffer:
begin
EnterCriticalSection(CommCS);
AddCommand(tPauseStorage);
PassCommands;
LeaveCriticalSection(CommCS);
end;
//rSimultaneous: ;
rRealTime:
begin
if CurrentDevice^.Model = 'PTC10' then
begin
EnterCriticalSection(CommCS);
CommandString:= 'kill RTAMacro';
PassCommands;
LeaveCriticalSection(CommCS);
end
else
begin
EnterCriticalSection(CommCS);
AddCommand(tPauseRealTime);
PassCommands;
LeaveCriticalSection(CommCS);
end;
end;
end;
{if ReadingMode = rBuffer then
begin
EnterCriticalSection(CommCS);
AddCommand(dPauseStorage);
PassCommands;
LeaveCriticalSection(CommCS);
end; }
end;
procedure TTempControlForm.Continue(Sender: tLogModule);
begin
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:
begin
EnterCriticalSection(CommCS);
AddCommand(tStartStorage);
PassCommands;
LeaveCriticalSection(CommCS);
ReadingsThread:= tDetBufferThread.Create(0{PointsInBuffer});
end;
rSimultaneous:
begin
if OnePointPerStep then
ReadingsThread:= nil // Stepf
else
ReadingsThread:= tTempSimultaneousThread.Create;
end;
rRealTime:
begin
if CurrentDevice^.Model = 'PTC10' then
begin
EnterCriticalSection(CommCS);
CommandString:= MacroCrutch;
PassCommands;
LeaveCriticalSection(CommCS);
end
else
begin
EnterCriticalSection(CommCS);
AddCommand(tStartRealTime);
PassCommands;
LeaveCriticalSection(CommCS);
end;
ReadingsThread:= tTempRealTimeThread.Create;
end;
end;
end;
procedure TTempControlForm.Stop(Sender: tLogModule);
begin
UpdateTimer.Enabled:= false; //to event OnStop
case ReadingMode of
rBuffer:
begin
EnterCriticalSection(CommCS);
AddCommand(dResetStorage);
PassCommands;
LeaveCriticalSection(CommCS);
end;
// rSimultaneous: ;
rRealTime:
begin
if CurrentDevice^.Model = 'PTC10' then
begin
EnterCriticalSection(CommCS);
CommandString:= 'kill RTAMacro';
PassCommands;
LeaveCriticalSection(CommCS);
end
else
begin
EnterCriticalSection(CommCS);
AddCommand(tStopRealTime);
PassCommands;
LeaveCriticalSection(CommCS);
end;
end;
end;
{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
MainForm.SaveReport(false, MainForm.ReportHeader);
//to avoid increasing two times
inc(ExperimentNumber);
end;
end;
procedure TTempControlForm.CreateFile(Sender: tLogModule);
var
i: integer;
begin
with Sender do
begin
FilePath:= DataFolder;
DateTimeToString(FileName, DefaultTimeFormat, Now);
Stub:= LogStub;
if LogExtension <> '' then
Extension:= LogExtension
else
Extension:= LogExtensions[integer(dTempController)];
if LogTime then
Header:= Header + cbXAxis.Items.Strings[0] + HT;
if LogFreq then
Header:= Header + 'Частота (генератор)' + HT;
if LogAmpl then
Header:= Header + 'Амплитуда (генератор)' + HT;
for i:= 0 to high(ParToRead) do
Header:= Header + cbChartShow.Items[ParToRead[i]] + HT;
Header:= Header + LineEnding;
end;
end;
function TTempControlForm.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 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 }
j:= length(Sources);
setlength(Sources, length(Sources) + length(ParToRead));
for i:= 0 to length(ParToRead) - 1 do
Sources[j + i]:= CoordinateSources[ParToRead[i]];
{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 TTempControlForm.StateChange(Sender: tLogModule);
begin
with tLogModule(Sender) do
if State = lActive then
begin
btStartPauseLog.Caption:= PauseCaption;
btReset.Enabled:= false;
cbReadingsMode.Enabled:= false;
cbSampleRate.Enabled:= false;
cgTransfer.Enabled:= false;
btClear.Enabled:= false;
btApply.Enabled:= false;
pnConnection.Enabled:= false;
cbSampleRate.Enabled:= false;
end
else
begin
btReset.Enabled:= true;
cbReadingsMode.Enabled:= true;
cbSampleRate.Enabled:= true;
cgTransfer.Enabled:= true;
btApply.Enabled:= true;
cbSampleRate.Enabled:= true;
if State = lInActive then
begin
pnConnection.Enabled:= true;
btClear.Enabled:= true;
btStartPauseLog.Caption:= StartCaption;
end
else
btStartPauseLog.Caption:= ContinueCaption;
end;
end;
procedure TTempControlForm.ProcessBuffers(Sender: tLogModule);
var
i, j: longint;
v, f, a: double;
begin
with Sender do
begin
if LogFreq then
f:= StepF.F;
if LogAmpl then
a:= StepF.A;
if DataList.Count > 0 then
case ReadingMode of {
rBuffer:
begin
for i:= 0 to (DataList.Count div 2) - 1 do
begin
l:= length(Buffer(DataList.Items[i * 2]^));
ProcessedPoints+= l;
c:= srcCh1.Count;
srcCH1.Add(Buffer(DataList.Items[i * 2]^));
srcCH2.Add(Buffer(DataList.Items[i * 2 + 1]^));
if LogFreq and UseGenFreq then
begin
srcFreq.Capacity:= srcFreq.Capacity + l;
srcFreq.Count:= srcFreq.Count + l;
end;
if LogAmpl then
begin
srcAmpl.Capacity:= srcAmpl.Capacity + l;
srcAmpl.Count:= srcAmpl.Count + l;
end;
if LogTime then
begin
srcTime.Capacity:= srcTime.Capacity + l;
srcTime.Count:= srcTime.Count + l;
end;
l:= c + l - 1;
for j:= c to l do
begin
if LogFreq and UseGenFreq then
srcFreq.Values[j]:= f;
if LogAmpl then
srcAmpl.Values[j]:= a;
srcTime.Values[j]:= t;
t+= TimeStep;
end;
dispose(PBuffer(DataList.Items[i * 2]));
dispose(PBuffer(DataList.Items[i * 2 + 1]));
end;
DataList.Clear;
end; }
rSimultaneous:
begin
for i:= 0 to (DataList.Count div 2) - 1 do
begin
if LogFreq then
srcFreq.Add(f);
if LogAmpl then
srcAmpl.Add(a);
t:= SecondSpan(TDateTime(DataList.Items[i * 2]^), 0);
dispose(PDateTime(DataList.Items[i * 2]));
if LogTime then
srcTime.Add(t);
for j:= 0 to high(Buffer(DataList.Items[i * 2 + 1]^)) do
begin
v:= Buffer(DataList.Items[i * 2 + 1]^)[j];
//WriteProgramLog('');
//WriteProgramLog('i ' + strf(i) + ' j ' + strf(j));
CoordinateSources[ParToRead[j]].Add(v);
{for k:= (lk + 1) to high(ReadPars) do
begin
//WriteProgramLog('lk ' + strf(lk)+' k '+strf(k));
if ReadPars[k] then
begin
//writeprogramlog('k' + strf(k));
CoordinateSources[k].Add(v);
lk:= k;
break;
end;
end;}
end;
dispose(PBuffer(DataList.Items[i * 2 + 1]));
end;
DataList.Clear;
if LogTime then
ProcessedPoints:= srcTime.Count
else
if LogFreq then
ProcessedPoints:= srcFreq.Count
else
ProcessedPoints:= srcAmpl.Count;
end;
rRealTime:
begin
for i:= 0 to DataList.Count - 1 do
begin
if LogFreq then
srcFreq.Add(f);
if LogAmpl then
srcAmpl.Add(a);
if LogTime then
srcTime.Add(t);
for j:= 0 to high(Buffer(DataList.Items[i]^)) do
begin
v:= Buffer(DataList.Items[i]^)[j];
//WriteProgramLog('');
//WriteProgramLog('i ' + strf(i) + ' j ' + strf(j));
CoordinateSources[ParToRead[j]].Add(v);
{for k:= (lk + 1) to high(ReadPars) do
begin
//WriteProgramLog('lk ' + strf(lk)+' k '+strf(k));
if ReadPars[k] then
begin
//writeprogramlog('k' + strf(k));
CoordinateSources[k].Add(v);
lk:= k;
break;
end;
end;}
end;
dispose(PBuffer(DataList.Items[i]));
t+= 1;
end;
DataList.Clear;
if LogTime then
ProcessedPoints:= srcTime.Count
else
if LogFreq then
ProcessedPoints:= srcFreq.Count
else
ProcessedPoints:= srcAmpl.Count;
end;
end;
Source.PointsNumber:= ProcessedPoints;
//writeprogramlog('c ' + strf(srctime.count) + ' ' + strf(srctime.capacity));
//writeprogramlog('c ' + strf(srcref.count) + ' ' + strf(srcref.capacity));
//writeprogramlog('c ' + strf(srcdisp1.count) + ' ' + strf(srcdisp1.capacity));
//writeprogramlog('c ' + strf(srcdisp2.count) + ' ' + strf(srcdisp2.capacity));