-
Notifications
You must be signed in to change notification settings - Fork 0
/
devicef.pas
1336 lines (1235 loc) · 39.3 KB
/
devicef.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 DeviceF;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, DividerBevel, Forms, Controls, Graphics, Dialogs,
Grids, Buttons, StdCtrls, ComCtrls, ExtCtrls, Types;
type
eHeaderRow = (
hModel, hManufacturer, hInterface, hBaudRate, hDataBits, hStopBits, hParity,
hHandShake, hIPAdress, hPort, hInitString, hTimeOut, hMinDelay,
hParSeparator, hCommSeparator, hTerminator,
hTimeConstOptions, hSensitivityOptions, hTransferParams, hIndices,
hMaxSimultPars, hPointsInBuffer, hCH1Options, hCH2Options, hRatio1Options,
hRatio2Options, hBufferRateOptions, hCloseReserveOptions,
hWideReserveOptions, hRangeOptions, hOffsetParams,
hResistanceOptions = integer(hTimeConstOptions), hFunctionOptions,
hSweepTypeOptions, hSweepDirectionOptions, hModulationOptions,
hAmplitudeUnits, hMaxFrequencies, hMinMaxAmplitudes,
hChannelList = integer(hTimeConstOptions), htSampleRateOptions, { TODO 2 -cImprovement : split? }
hBufferPointOptions
);
eCommonCommand = (
cReset, cReboot, cIdentify, cRecall, cSave, cTest, cCalibrate, cClearStatus,
cSerialPoll, cSerialPollEnable, cStdEvent, cStdEventEnable, cPowerClear,
cTrigger
);
eGenCommand = (
gDDS = integer(cTrigger) + 1, gDDSEnable, gResistance, gFunction,
gAmplitude, gOffset, gFrequency, gSweepSource, gSweepEnable,
gSweepRate, gSweepStartFrequency, gSweepStopFrequency, gSweepType,
gSweepDirection, gModulationWaveform
);
eDetCommand = (
dError = integer(cTrigger) + 1, dErrorEnable, dLIA, dLIAEnable,
dInputRange, dSensitivity, dTimeConstant, dCloseReserve, dWideReserve,
dOffset, dExpand, dAutoRange, dAutoSensitivity, dAutoCloseReserve,
dAutoWideReserve, dAutoPhase, dAutoOffset, dReferenceSource, dSampleRate,
dStartStorage, dPauseStorage, dResetStorage, dStoredPoints, //dReadPonts in text
dReadPointsNative, dStorageMode, dReadSimultaneous, dDisplaySelect
);
eTempCommand = (
tError = integer(cTrigger) + 1, tPrint, tGetChannelNames,
tSampleRate, tStartStorage, tPauseStorage, tResetStorage, tStoredPoints,
tReadPoints, tReadSimultaneous, tStartRealTime, tPauseRealTime, tStopRealTime
);
{type
TSR844Command = (
PRST = longint(TRG) + 1, LOCL, OVRM,
FMOD, HARM, FREQ, FRAQ, FRIQ, PHAS, APHS, REFZ, WRSV, AWRS, INPZ,
SENS, AGAN, CRSV, ACRS, OFLT, OFSL, SETL,
DDEF, DRAT, FPOP, DOFF, AOFF, DEXP,
AUXI, AUXO,
OUTX, KCLK, ALRM, SSET, RSET, KNOB, KEYP,
SSTR, SFIN, SSTP, SMOD, RSTO, RRDY, RCLR, RMOD,
SRAT, SEND, TSTR, STRT, PAUS, REST,
OUTP, OUTR, SNAP, SPTS, TRCA, TRCB, TRCL, FAST, STRD,
ERRS, ERRE, LIAS, LIAE
);
TSR830Command = (
RST, IDN, LOCL = 3, OVRM,
FMOD, HARM, FREQ, PHAS = 10, APHS,
SENS = 16, AGAN, OFLT = 20, OFSL,
DDEF = 23, FPOP = 25, AOFF = 27,
OAUX = 29, AUXV,
OUTX, KCLK, ALRM, SSET, RSET,
RMOD = 45,
SRAT, SEND, TRIG, TSTR, STRT, PAUS, REST,
OUTP, OUTR, SNAP, SPTS, TRCA, TRCB, TRCL, FAST, STRD,
CLS, STB, SRE, ESR, ESE, PSC, ERRS, ERRE, LIAS, LIAE,
RSLP = longint(LIAE) + 1, SLVL, ISRC, IGND, ICPL, ILIN, SYNC, OEXP, ARSV
); }
{ SR844Command: array[longint(RST)..longint(LIAE)] of ansistring = (
'*RST', '*IDN', '', '', '', '', '*CLS', '*STB', '*SRE', '*ESR', '*ESE', '*PSC' , 'TRIG',
'PRST', 'LOCL', 'OVRM',
'FMOD', 'HARM', 'FREQ', 'FRAQ', 'FRIQ', 'PHAS', 'APHS', 'REFZ', 'WRSV', 'AWRS', 'INPZ',
'SENS', 'AGAN', 'CRSV', 'ACRS', 'OFLT', 'OFSL', 'SETL',
'DDEF', 'DRAT', 'FPOP', 'DOFF', 'AOFF', 'DEXP',
'AUXI', 'AUXO',
'OUTX', 'KCLK', 'ALRM', 'SSET', 'RSET', 'KNOB', 'KEYP',
'SSTR', 'SFIN', 'SSTP', 'SMOD', 'RSTO', 'RRDY', 'RCLR', 'RMOD',
'SRAT', 'SEND', 'TSTR', 'STRT', 'PAUS', 'REST',
'OUTP', 'OUTR', 'SNAP', 'SPTS', 'TRCA', 'TRCB', 'TRCL', 'FAST', 'STRD',
'ERRS', 'ERRE', 'LIAS', 'LIAE'
);
SR830Command: array[longint(RST)..longint(ARSV)] of ansistring = (
'*RST', '*IDN', '', '', '', '', '*CLS', '*STB', '*SRE', '*ESR', '*ESE', '*PSC' , 'TRIG',
'', 'LOCL', 'OVRM',
'FMOD', 'HARM', 'FREQ', '', '', 'PHAS', 'APHS', '', '', '', '',
'SENS', 'AGAN', '', '', 'OFLT', 'OFSL', '',
'DDEF', '', 'FPOP', '', 'AOFF', '',
'OAUX', 'AUXV',
'OUTX', 'KCLK', 'ALRM', 'SSET', 'RSET', '', '',
'', '', '', '', '', '', '', 'RMOD',
'SRAT', 'SEND', 'TSTR', 'STRT', 'PAUS', 'REST',
'OUTP', 'OUTR', 'SNAP', 'SPTS', 'TRCA', 'TRCB', 'TRCL', 'FAST', 'STRD',
'ERRS', 'ERRE', 'LIAS', 'LIAE',
'RSLP', 'SLVL', 'ISRC', 'IGND', 'ICPL', 'ILIN', 'SYNC', 'OEXP', 'ARSV'
); }
{tDS345Command = (
AECL = longint(TRG) + 1, AMPL, ATTL, FREQ, FSMP, FUNC, INVT, OFFS, PCLR, PHSE,
BCNT, DPTH, FDEV, MDWF, MENA, MKSP, MRKF, MTYP, PDEV, RATE, SPAN, SPCF, SPFR, SPMK, STFR, TRAT, TSRC,
AMRT, AMOD, LDWF,
DENA, STAT
);
tDS335Command = (
KEYS = longint(STAT) + 1, SYNC, TERM,
FSEN, SDIR, SWEN
);
const
DS345Command: array [longint(RST)..longint(STAT)] of ansistring = (
'*RST', '*IDN', '*RCL', '*SAV', '*TST', '*CAL', '*CLS', '*STB', '*SRE', '*ESR', '*ESE', '*PSC' , '*TRG',
'AECL', 'AMPL', 'ATTL', 'FREQ', 'FSMP', 'FUNC', 'INVT', 'OFFS', 'PCLR', 'PHSE',
'BCNT', 'DPTH', 'FDEV', 'MDWF', 'MENA', 'MKSP', 'MRKF', 'MTYP', 'PDEV', 'RATE', 'SPAN', 'SPCF', 'SPFR', 'SPMK', 'STFR', 'TRAT', 'TSRC',
'AMRT', 'AMOD', 'LDWF',
'DENA', 'STAT'
);
DS335Command: array [longint(RST)..longint(SWEN)] of ansistring = (
'*RST', '*IDN', '*RCL', '*SAV', '*TST', '', '*CLS', '*STB', '*SRE', '*ESR', '*ESE', '*PSC' , '*TRG',
'AECL', 'AMPL', 'ATTL', 'FREQ', '', 'FUNC', 'INVT', 'OFFS', '', '',
'', '', '', '', '', '', '', 'STYP', '', '', '', '', 'SPFR', '', 'STFR', 'SRAT', 'TSRC',
'', '', '',
'DENA', 'STAT',
'KEYS', 'SYNC', 'TERM',
'FSEN', 'SDIR', 'SWEN'
); }
{ tDeviceForm }
tDeviceForm = class(TForm)
btAddDevice: TButton;
btDeleteDevice: TButton;
btApply: TButton;
btSaveToFile: TButton;
btLoadFromFile: TButton;
btSetDefaultFile: TButton;
btDone: TButton;
btResetDefaultFile: TButton;
cbHandshake: TComboBox;
cbParity: TComboBox;
cbStopBits: TComboBox;
cbTerminator: TComboBox;
cbInterface: TComboBox;
DividerBevel1: TDividerBevel;
DividerBevel2: TDividerBevel;
sgTempCommands: TStringGrid;
stInstruction: TStaticText;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
OpenDialog: TOpenDialog;
pcDevice: TPageControl;
SaveDialog: TSaveDialog;
sgGenCommands: TStringGrid;
sgDetCommands: TStringGrid;
tsTempControllers: TTabSheet;
tsGenerators: TTabSheet;
tsDetectors: TTabSheet;
procedure btAddDeviceClick(Sender: TObject);
procedure btApplyClick(Sender: TObject);
procedure btDeleteDeviceClick(Sender: TObject);
procedure btDoneClick(Sender: TObject);
procedure btLoadFromFileClick(Sender: TObject);
procedure btResetDefaultFileClick(Sender: TObject);
procedure btSaveToFileClick(Sender: TObject);
procedure btSetDefaultFileClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure pcDeviceChange(Sender: TObject);
procedure sgDetCommandsClick(Sender: TObject);
procedure sgDetCommandsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure sgGenCommandsClick(Sender: TObject);
procedure sgGenCommandsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure sgGenCommandsSelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure sgDetCommandsSelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure sgGenCommandsSelection(Sender: TObject; aCol, aRow: Integer);
procedure EditOptionString(c, r: integer);
function CheckConformance: integer;
procedure sgTempCommandsClick(Sender: TObject);
procedure sgTempCommandsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure sgTempCommandsSelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
procedure sgTempCommandsSelection(Sender: TObject; aCol, aRow: Integer);
procedure sgTempCommandsValidateEntry(sender: TObject; aCol, aRow: Integer;
const OldValue: string; var NewValue: String);
private
{ private declarations }
CurrColumn: integer; //stringgrid.row
CurrGenFileName, CurrDetFileName, CurrTempFileName: string;
sg: tStringGrid;
public
{ public declarations }
end;
const
SGHeaderLength = integer(high(eHeaderRow)) + 4; //кол-во строк в tStringGrid, не относящ. к командам
DefaultGen = 'DefaultGenCommands.xml';
DefaultDet = 'DefaultDetCommands.xml';
DefaultTemp = 'DefaultTempCommands.xml';
TelnetString = 'Ethernet - Telnet';
VXIString = 'Ethernet - VXI';
USBString = 'USB';
SerialString = 'RS232';
var
DeviceForm: TDeviceForm;
implementation
{$R *.lfm}
uses
LCLType, Math, StrUtils, SynaIP, MainF, DetControlF, TempControlF, OptionF, BaseConF, MemoF, ButtonPanel;
const
InputQueryWidth = 300;
function InputQueryActiveMonitor: TMonitor;
begin
if Screen.ActiveCustomForm <> nil then
Result := Screen.ActiveCustomForm.Monitor
else
if Application.MainForm <> nil then
Result := Application.MainForm.Monitor
else
Result := Screen.PrimaryMonitor;
end;
function CustomInputDialog(const InputCaption, InputPrompt : String;
MaskInput : Boolean; var Value : String) : Boolean;
var
Form: TForm;
Prompt: TLabel;
Edit: TEdit;
MinEditWidth: integer;
AMonitor: TMonitor;
begin
Result := False;
Form := TForm(TForm.NewInstance);
Form.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('ShowInputDialog'){$ENDIF};
Form.CreateNew(nil, 0);
with Form do
begin
PopupMode := pmAuto;
BorderStyle := bsDialog;
Caption := InputCaption;
Position := poScreenCenter;
Width := InputQueryWidth;
Prompt := TLabel.Create(Form);
with Prompt do
begin
Parent := Form;
Caption := InputPrompt;
Align := alTop;
AutoSize := True;
end;
Edit := TEdit.Create(Form);
with Edit do
begin
Parent := Form;
Top := Prompt.Height;
Align := alTop;
BorderSpacing.Top := 3;
AMonitor := InputQueryActiveMonitor;
// check that edit is smaller than our monitor, it must be smaller at least
// by 6 * 2 pixels (spacing from window borders) + window border
MinEditWidth := Min(AMonitor.Width - 20, InputQueryWidth - 16);
Constraints.MinWidth := MinEditWidth;
Text := Value;
TabStop := True;
if MaskInput then
begin
EchoMode := emPassword;
PasswordChar := '*';
end else
begin
EchoMode := emNormal;
PasswordChar := #0;
end;
TabOrder := 0;
end;
with TButtonPanel.Create(Form) do
begin
Top := Edit.Top + Edit.Height;
Parent := Form;
ShowBevel := False;
ShowButtons := [pbOK, pbCancel];
OKButton.Caption:= 'ОК';
OKButton.Glyph:= nil;
CancelButton.Caption:= 'Отмена';
CancelButton.Glyph:= nil;
Align := alTop;
end;
ChildSizing.TopBottomSpacing := 6;
ChildSizing.LeftRightSpacing := 6;
AutoSize := True;
// upon show, the edit control will be focused for editing, because it's
// the first in the tab order
Form.EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('ShowInputDialog'){$ENDIF};
if (ShowModal = mrOk) and (Edit.Text <> '') then
begin
Value := Edit.Text;
Result := True;
end;
Form.Free;
end;
end;
{ TDeviceForm }
procedure tDeviceForm.btAddDeviceClick(Sender: TObject);
var
Model: string;
begin
if CustomInputDialog(
'Новое устройство', 'Введите название модели',
false, Model
) then
with sg do
begin
Columns.Add;
Cells[ColCount - 1, 0]:= Model;
//Cols[].Add(Model);
end;
end;
procedure tDeviceForm.btApplyClick(Sender: TObject);
begin
if CurrColumn < 0 then exit;
with sg do
begin
Cells[CurrColumn, integer(hInterface) ]:= cbInterface.Text;
Cells[CurrColumn, integer(hStopBits) ]:= cbStopBits.Text;
Cells[CurrColumn, integer(hParity) ]:= cbParity.Text;
Cells[CurrColumn, integer(hHandShake) ]:= cbHandShake.Text;
Cells[CurrColumn, integer(hTerminator)]:= cbTerminator.Text;
end;
end;
procedure tDeviceForm.btDeleteDeviceClick(Sender: TObject);
begin
if CurrColumn < 0 then exit;
with sg do
begin
if QuestionDlg(
'Удаление устройства', 'Будет удалено устройство ' +
Cells[CurrColumn, 0] + '. Продолжить?',
mtCustom,[mrYes,'Да', mrNo, 'Нет'], ''
) = mrYes then
if CurrColumn > 0 then
DeleteCol(CurrColumn);
if CurrColumn > ColCount - 1 then
CurrColumn:= ColCount - 1;
end;
end;
procedure tDeviceForm.btDoneClick(Sender: TObject);
begin
Close; //onclosequery checks
end;
procedure tDeviceForm.btLoadFromFileClick(Sender: TObject);
begin
with OpenDialog do
begin
case pcDevice.TabIndex of
0: FileName:= DefaultGen;
1: FileName:= DefaultDet;
2: FileName:= DefaultTemp;
end;
InitialDir:= MainForm.FullCfgDir;
DefaultExt:= '.xml';
Title:= 'Загрузить файл устройств';
Filter:= 'Файлы устройств|*.xml|Все файлы|*.*';
if Execute then
begin
case pcDevice.TabIndex of
0: begin
CurrGenFileName:= UTF8toANSI(FileName); // проверить на доп символы
if FileExists(CurrGenFileName) then
with sg do
begin
sg.Clean;
LoadFromFile(CurrGenFileName);
end;
end;
1: begin
CurrDetFileName:= UTF8toANSI(FileName);
if FileExists(CurrDetFileName) then
with sg do
begin
sg.Clean;
LoadFromFile(CurrDetFileName);
end;
end;
2: begin
CurrTempFileName:= UTF8toANSI(FileName);
if FileExists(CurrTempFileName) then
with sg do
begin
sg.Clean;
LoadFromFile(CurrTempFileName);
end;
end;
end;
end;
end;
end;
procedure tDeviceForm.btResetDefaultFileClick(Sender: TObject);
begin
case pcDevice.TabIndex of
0: Config.DefaultGens:= '';
1: Config.DefaultDets:= '';
2: Config.DefaultTemps:= '';
end;
end;
procedure tDeviceForm.btSaveToFileClick(Sender: TObject);
begin
with SaveDialog do
begin
case pcDevice.TabIndex of
0: FileName:= DefaultGen;
1: FileName:= DefaultDet;
2: FileName:= DefaultTemp;
end;
InitialDir:= MainForm.FullCfgDir;
DefaultExt:= '.xml';
Title:= 'Сохранить файл устройств как';
Filter:= 'Файлы устройств|*.xml|Все файлы|*.*';
if Execute then
begin
case pcDevice.TabIndex of
0: begin
CurrGenFileName:= UTF8toANSI(FileName);
sg.SaveToFile(CurrGenFileName);
end;
1: begin
CurrDetFileName:= UTF8toANSI(FileName);
sg.SaveToFile(CurrDetFileName);
end;
2: begin
CurrTempFileName:= UTF8toANSI(FileName);
sg.SaveToFile(CurrTempFileName);
end;
end;
end;
end;
end;
procedure tDeviceForm.btSetDefaultFileClick(Sender: TObject);
begin
case pcDevice.TabIndex of
0: if CurrGenFileName <> '' then
Config.DefaultGens:= CurrGenFileName;
1: if CurrDetFileName <> '' then
Config.DefaultDets:= CurrDetFileName;
2: if CurrTempFileName <> '' then
Config.DefaultTemps:= CurrTempFileName;
end;
end;
procedure tDeviceForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
var
o: integer;
begin
o:= CheckConformance;
if o = 0 then
begin
MainForm.GetSupportedDevices(dGenerator);
DetControlForm.GetSupportedDevices(dDetector);
TempControlForm.GetSupportedDevices(dTempController);
OptionForm.ReloadDeviceList;
CanClose:= true;
end
else
CanClose:= false;
end;
procedure tDeviceForm.FormCreate(Sender: TObject);
begin //this is regulated by mainform.loadconfig NOT ANYMORE THAT WAS STUPID
if Config.DefaultGens <> '' then
if FileExists(Config.DefaultGens) then
sgGenCommands.LoadFromFile(Config.DefaultGens)
else
ShowMessage('Не найден файл ' + Config.DefaultGens);
if Config.DefaultDets <> '' then
if FileExists(Config.DefaultDets) then
sgDetCommands.LoadFromFile(Config.DefaultDets)
else
ShowMessage('Не найден файл ' + Config.DefaultDets);
if Config.DefaultTemps <> '' then
if FileExists(Config.DefaultTemps) then
sgTempCommands.LoadFromFile(Config.DefaultTemps)
else
ShowMessage('Не найден файл ' + Config.DefaultTemps);
end;
procedure tDeviceForm.FormShow(Sender: TObject);
begin
CurrGenFileName:= '';
CurrDetFileName:= '';
CurrTempFileName:= '';
CurrColumn:= -1;
pcDeviceChange(Self);
end;
procedure tDeviceForm.pcDeviceChange(Sender: TObject);
begin
CurrColumn:= -1;
case pcDevice.TabIndex of
0: sg:= sgGenCommands;
1: sg:= sgDetCommands;
2: sg:= sgTempCommands;
end;
end;
procedure tDeviceForm.sgDetCommandsClick(Sender: TObject);
begin
with sgDetCommands do
case Row of
integer(hTimeConstOptions),
integer(hSensitivityOptions),
integer(hTransferParams),
integer(hCH1Options),
integer(hCH2Options),
integer(hRatio1Options),
integer(hRatio2Options),
integer(hBufferRateOptions),
integer(hCloseReserveOptions),
integer(hWideReserveOptions),
integer(hRangeOptions),
integer(hOffsetParams):
EditOptionString(Col, Row);
end;
end;
procedure tDeviceForm.sgDetCommandsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
with sgDetCommands do
case Row of
integer(hTimeConstOptions),
integer(hSensitivityOptions),
integer(hTransferParams),
integer(hCH1Options),
integer(hCH2Options),
integer(hRatio1Options),
integer(hRatio2Options),
integer(hBufferRateOptions),
integer(hCloseReserveOptions),
integer(hWideReserveOptions),
integer(hRangeOptions),
integer(hOffsetParams):
begin
key:= 0;
EditOptionString(Col, Row);
end;
end;
end;
procedure tDeviceForm.sgGenCommandsClick(Sender: TObject);
begin
with sgGenCommands do
case Row of
integer(hResistanceOptions),
integer(hFunctionOptions),
integer(hSweepTypeOptions),
integer(hsWeepDirectionOptions),
integer(hModulationOptions),
integer(hAmplitudeUnits),
integer(hMaxFrequencies),
integer(hMinMaxAmplitudes):
EditOptionString(Col, Row);
end;
end;
procedure tDeviceForm.sgGenCommandsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
with sgGenCommands do
case Row of
integer(hResistanceOptions),
integer(hFunctionOptions),
integer(hSweepTypeOptions),
integer(hsWeepDirectionOptions),
integer(hModulationOptions),
integer(hAmplitudeUnits),
integer(hMaxFrequencies),
integer(hMinMaxAmplitudes):
begin
key:= 0;
EditOptionString(Col, Row);
end;
end;
end;
procedure tDeviceForm.sgGenCommandsSelectCell(Sender: TObject; aCol,
aRow: Integer; var CanSelect: Boolean);
begin
with sgGenCommands do
begin
AutoEdit:= true;
if aCol > 0 then
with Columns.Items[aCol - 1] do
case aRow of
integer(hInterface):
begin
ButtonStyle:= cbsPickList;
PickList:= cbInterface.Items;
end;
integer(hStopBits):
begin
ButtonStyle:= cbsPickList;
PickList:= cbStopBits.Items;
end;
integer(hParity):
begin
ButtonStyle:= cbsPickList;
PickList:= cbParity.Items;
end;
integer(hHandshake):
begin
ButtonStyle:= cbsPickList;
PickList:= cbHandshake.Items;
end;
integer(hTerminator):
begin
ButtonStyle:= cbsPickList;
PickList:= cbTerminator.Items;
end;
integer(hResistanceOptions),
integer(hFunctionOptions),
integer(hSweepTypeOptions),
integer(hSweepDirectionOptions),
integer(hModulationOptions),
integer(hAmplitudeUnits),
integer(hMaxFrequencies),
integer(hMinMaxAmplitudes):
AutoEdit:= false;
else
begin
ButtonStyle:= cbsAuto;
if PickList <> nil then
PickList:= nil;
end;
end;
end;
end;
procedure tDeviceForm.sgDetCommandsSelectCell(Sender: TObject; aCol,
aRow: Integer; var CanSelect: Boolean);
begin
with sgDetCommands do
begin
AutoEdit:= true;
if aCol > 0 then
with Columns.Items[aCol - 1] do
case aRow of
integer(hInterface):
begin
ButtonStyle:= cbsPickList;
PickList:= cbInterface.Items;
end;
integer(hStopBits):
begin
ButtonStyle:= cbsPickList;
PickList:= cbStopBits.Items;
end;
integer(hParity):
begin
ButtonStyle:= cbsPickList;
PickList:= cbParity.Items;
end;
integer(hHandshake):
begin
ButtonStyle:= cbsPickList;
PickList:= cbHandshake.Items;
end;
integer(hTerminator):
begin
ButtonStyle:= cbsPickList;
PickList:= cbTerminator.Items;
end;
integer(hTimeConstOptions),
integer(hSensitivityOptions),
integer(hTransferParams),
integer(hCH1Options),
integer(hCH2Options),
integer(hRatio1Options),
integer(hRatio2Options),
integer(hBufferRateOptions),
integer(hCloseReserveOptions),
integer(hWideReserveOptions),
integer(hRangeOptions),
integer(hOffsetParams):
AutoEdit:= false;
else
begin
ButtonStyle:= cbsAuto;
if PickList <> nil then
PickList:= nil;
end;
end;
end;
end;
procedure tDeviceForm.sgGenCommandsSelection(Sender: TObject; aCol,
aRow: Integer);
begin
CurrColumn:= aCol;
end;
procedure tDeviceForm.EditOptionString(c, r: integer);
begin
with sg, MemoForm do
begin
mComment.Text:= Cells[Col, Row];
Caption:= Cells[0, Row];
ShowModal;
Caption:= 'Комментарий';
if (not IsEmptyStr(mComment.Text, [' '])) or
(not IsEmptyStr(Cells[Col, Row], [' '])) then
begin
Cells[Col, Row]:= mComment.Text;
end;
mComment.Lines.Clear;
end;
end;
function tDeviceForm.CheckConformance: integer;
var
s: string;
i, j, n, o, e: integer;
m: double;
{Exitcodes:
0 - Success
in gen
-1 - Interface
-2 - Baud rate
-3 - Databits
-4 - Stop bits
-5 - Parity
-6 - Handshake
-7 - ip
-8 - port
-9 - terminator
-10 - timeout
in det
-$11 - Interface
-$12 - Baud rate
-$13 - Databits
-$14 - Stop bits
-$15 - Parity
-$16 - Handshake
-$17 - ip
-$18 - port
-$19 - terminator
-$20 - timeout
-$30 temp usb wip
}
begin
Result:= 0;
with sgGenCommands do
for i:= 1 to ColCount - 1 do
begin
for j:= 0 to RowCount - 1 do
begin
if IsEmptyStr(Cells[i, j], [' ']) then Cells[i, j]:= '';
end;
s:= Cells[i, integer(hInterface)];
o:= DeviceForm.cbInterface.Items.IndexOf(s);
case o of
integer(cSerial):
begin
o:= valf(Cells[i, integer(hBaudRate)]);
if o < 50 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hBaudRate);
Col:= i;
ShowMessage('Ошибка в поле "Бод-частота"');
exit(-2);
end;
o:= valf(Cells[i, integer(hDataBits)]);
if o < 1 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hDataBits);
Col:= i;
ShowMessage('Ошибка в поле "Биты данных"');
exit(-3);
end;
s:= Cells[i, integer(hStopBits)];
o:= DeviceForm.cbStopBits.Items.IndexOf(s);
if o < 0 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hStopBits);
Col:= i;
ShowMessage('Ошибка в поле "Стоп-биты"');
exit(-4);
end;
s:= Cells[i, integer(hParity)];
o:= DeviceForm.cbParity.Items.IndexOf(s);
if o < 0 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hParity);
Col:= i;
ShowMessage('Ошибка в поле "Парность"');
exit(-5);
end;
s:= Cells[i, integer(hHandshake)];
o:= DeviceForm.cbHandshake.Items.IndexOf(s);
if o < 0 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hHandShake);
Col:= i;
ShowMessage('Ошибка в поле "Handshake"');
exit(-6);
end;
end;
integer(cUSB):
begin
pcDevice.TabIndex:= 0;
ShowMessage('USB не поддерживается');
exit(-30);
end;
integer(cTelnet), integer(cVXI):
begin
s:= Cells[i, integer(hIPAdress)];
if not IsIP(s) then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hIPAdress);
Col:= i;
ShowMessage('Ошибка в поле "IP-адрес"');
exit(-7);
end;
val(Cells[i, integer(hPort)], o, e);
if (e <> 0) or (o < 0) then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hPort);
Col:= i;
ShowMessage('Ошибка в поле "Порт"');
exit(-8);
end;
end;
else
begin
pcDevice.TabIndex:= 0;
Row:= integer(hInterface);
Col:= i;
ShowMessage('Ошибка в поле "Интерфейс"');
exit(-1);
end;
end;
s:= Cells[i, integer(hTerminator)];
o:= DeviceForm.cbTerminator.Items.IndexOf(s);
if o < 0 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hTerminator);
Col:= i;
ShowMessage('Ошибка в поле "Терминатор"');
exit(-9);
end;
val(Cells[i, integer(hTimeOut)], o, e);
if (e <> 0) or (o < 0) then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hTimeOut);
Col:= i;
ShowMessage('Ошибка в поле "Таймаут"');
exit(-$a);
end;
s:= sgGenCommands.Cells[i, integer(hMaxFrequencies)];
if not IsEmptyStr(s, [' ']) then
with MemoForm do
begin
mComment.Text:= sgGenCommands.Cells[i, integer(hFunctionOptions)];
o:= mComment.Lines.Count;
mComment.Text:= s;
n:= mComment.Lines.Count;
if o <> n then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hMaxFrequencies);
Col:= i;
ShowMessage('Ошибка в поле "Максимальные частоты соотв. функциям:"' + LineEnding +
'число параметров не соответствует числу функций');
exit(-$b);
end;
for j:= 0 to n - 1 do
begin
val(mComment.Lines[j], o, e);
if e <> 0 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hMaxFrequencies);
Col:= i;
ShowMessage('Ошибка в поле "Максимальные частоты соотв. функциям"');
exit(-$b);
end;
end;
mComment.Lines.Clear;
end;
s:= sgGenCommands.Cells[i, integer(hMinMaxAmplitudes)];
if not IsEmptyStr(s, [' ']) then
with MemoForm do
begin
mComment.Text:= sgGenCommands.Cells[i, integer(hResistanceOptions)];
o:= mComment.Lines.Count;
mComment.Text:= s;
n:= mComment.Lines.Count;
if ((o > 0) and (o <> n)) or ((o = 0) and (n > 1)) then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hMinMaxAmplitudes);
Col:= i;
ShowMessage('Ошибка в поле "Мин.-макс. амплитуды соотв. импедансу"' + LineEnding +
'число параметров не соответствует числу вариантов импеданса');
exit(-$b);
end;
for j:= 0 to n - 1 do
begin
s:= mComment.Lines[j];
val(Copy2SymbDel(s, '-'), m, e); //удаляем включая "-"
if e <> 0 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hMinMaxAmplitudes);
Col:= i;
ShowMessage('Ошибка в поле "Мин.-макс. амплитуды соотв. импедансу"');
exit(-$b);
end;
val(s, m, e);
if e <> 0 then
begin
pcDevice.TabIndex:= 0;
Row:= integer(hMinMaxAmplitudes);
Col:= i;
ShowMessage('Ошибка в поле "Мин.-макс. амплитуды соотв. импедансу"');
exit(-$b);