forked from VE3NEA/OmniRig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRigSett.pas
227 lines (181 loc) · 6.89 KB
/
RigSett.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
//------------------------------------------------------------------------------
//This Source Code Form is subject to the terms of the Mozilla Public
//License, v. 2.0. If a copy of the MPL was not distributed with this
//file, You can obtain one at http://mozilla.org/MPL/2.0/.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Omni-Rig
//
// Copyright (c) 2003 Alex Shovkoplyas, VE3NEA
//
//------------------------------------------------------------------------------
unit RigSett;
interface
uses
SysUtils, Classes, RigObj, IniFiles, Math;
type
TRigSettings = class
public
RigType,
Port,
BaudRate,
DataBits,
Parity,
StopBits,
RtsMode, DtrMode,
PollMs,
TimeoutMs: integer;
procedure FromIni(AIni: TIniFile; ASection: string);
procedure ToIni(AIni: TIniFile; ASection: string);
function Text: string;
procedure FromControls;
procedure ToControls;
procedure FromRig(ARig: TRig);
procedure ToRig(ARig: TRig);
end;
implementation
uses
Main, RigCmds, AlComPrt;
//------------------------------------------------------------------------------
// helper funs
//------------------------------------------------------------------------------
function BaudRateToIndex(Rate: integer): integer;
begin
Result := Max(0, MainForm.BaudRateComboBox.Items.IndexOf(IntToStr(Rate)));
end;
function IndexToBaudRate(Idx: integer): integer;
begin
Result := StrToIntDef(MainForm.BaudRateComboBox.Items[Idx], 9600);
end;
//------------------------------------------------------------------------------
// TRigSettings
//------------------------------------------------------------------------------
{ TRigSettings }
procedure TRigSettings.FromIni(AIni: TIniFile; ASection: string);
var
RigName: string;
begin
RigName := AIni.ReadString(ASection, 'RigType', 'NONE');
RigType := Max(0, MainForm.RigTypes.IndexOf(RigName));
Port := AIni.ReadInteger(ASection, 'Port', Port);
BaudRate := AIni.ReadInteger(ASection, 'BaudRate', 6);
DataBits := AIni.ReadInteger(ASection, 'DataBits', 3);
Parity := AIni.ReadInteger(ASection, 'Parity', 0);
StopBits := AIni.ReadInteger(ASection, 'StopBits', 0);
RtsMode := AIni.ReadInteger(ASection, 'RtsMode', 1);
DtrMode := AIni.ReadInteger(ASection, 'DtrMode', 1);
//backward compatibility
//if AIni.ReadString(ASection, 'Flow', '') = '0' then RtsMode := 2;
PollMs := AIni.ReadInteger(ASection, 'PollMs', 500);
TimeoutMs := AIni.ReadInteger(ASection, 'TimeoutMs', 4000);
end;
procedure TRigSettings.ToIni(AIni: TIniFile; ASection: string);
begin
//erase the obsolete Flow entry
AIni.EraseSection(ASection);
AIni.WriteString(ASection, 'RigType', MainForm.RigTypes[RigType]);
AIni.WriteInteger(ASection, 'Port', Port);
AIni.WriteInteger(ASection, 'BaudRate', BaudRate);
AIni.WriteInteger(ASection, 'DataBits', DataBits);
AIni.WriteInteger(ASection, 'Parity', Parity);
AIni.WriteInteger(ASection, 'StopBits', StopBits);
AIni.WriteInteger(ASection, 'RtsMode', RtsMode);
AIni.WriteInteger(ASection, 'DtrMode', DtrMode);
AIni.WriteInteger(ASection, 'PollMs', PollMs);
AIni.WriteInteger(ASection, 'TimeoutMs', TimeoutMs);
end;
procedure TRigSettings.FromControls;
begin
RigType := MainForm.RigComboBox.ItemIndex;
Port := StrToIntDef(Copy(MainForm.PortComboBox.Text, 5, MAXINT), 1);
BaudRate := MainForm.BaudRateComboBox.ItemIndex;
DataBits := MainForm.DataBitsComboBox.ItemIndex;
Parity := MainForm.ParityComboBox.ItemIndex;
StopBits := MainForm.StopBitsComboBox.ItemIndex;
RtsMode := MainForm.RtsComboBox.ItemIndex;
DtrMode := MainForm.DtrComboBox.ItemIndex;
PollMs := MainForm.PollSpinEdit.Value;
TimeoutMs := MainForm.TimeoutSpinEdit.Value;
end;
procedure TRigSettings.ToControls;
begin
MainForm.RigComboBox.ItemIndex := RigType;
MainForm.PortComboBox.ItemIndex :=
Max(0, MainForm.PortComboBox.Items.IndexOf('COM ' + IntToStr(Port)));
MainForm.BaudRateComboBox.ItemIndex := BaudRate;
MainForm.DataBitsComboBox.ItemIndex := DataBits;
MainForm.ParityComboBox.ItemIndex := Parity;
MainForm.StopBitsComboBox.ItemIndex := StopBits;
MainForm.RtsComboBox.ItemIndex := RtsMode;
MainForm.DtrComboBox.ItemIndex := DtrMode;
MainForm.PollSpinEdit.Value := PollMs;
MainForm.TimeoutSpinEdit.Value := TimeoutMs;
end;
procedure TRigSettings.FromRig(ARig: TRig);
begin
RigType := MainForm.RigTypes.IndexOfObject(ARig.RigCommands);
Port := ARig.ComPort.Port;
BaudRate := BaudRateToIndex(ARig.ComPort.BaudRate);
DataBits := ARig.ComPort.DataBits - 5;
Parity := Ord(ARig.ComPort.Parity);
StopBits := Ord(ARig.ComPort.StopBits);
RtsMode := Ord(ARig.ComPort.RtsMode);
DtrMode := Ord(ARig.ComPort.DtrMode);
PollMs := ARig.PollMs;
TimeoutMs := ARig.TimeoutMs;
end;
procedure TRigSettings.ToRig(ARig: TRig);
begin
ARig.Enabled := false;
try
ARig.RigCommands := MainForm.RigTypes.Objects[RigType] as TRigCommands;
ARig.ComPort.Port := Port;
ARig.ComPort.BaudRate := IndexToBaudRate(BaudRate);
ARig.ComPort.DataBits := DataBits + 5;
ARig.ComPort.Parity := TParity(Parity);
ARig.ComPort.StopBits := TStopBits(StopBits);
ARig.ComPort.DtrMode := TFlowControl(DtrMode);
ARig.ComPort.RtsMode := TFlowControl(RtsMode);
ARig.PollMs := PollMs;
ARig.TimeoutMs := TimeoutMs;
finally
ARig.Enabled := true;
end;
end;
{
COM port settings
setting HW SW NO
---------------------------------------------
RxDsrSensitivity FALSE FALSE FALSE
RxDtrControl ENABLED ENABLED ENABLED
RxRtsControl HANDSHAKE ENABLED ENABLED
TxContinueXoff FALSE FALSE FALSE
TxCtsFlow TRUE FALSE FALSE
TxDsrFlow FALSE FALSE FALSE
XonXoff FALSE TRUE FALSE
Sig from TS-570 meaning
-------------------------------------
DTR COMP Comp is On
DSR XCVR Rig is On
RTS COMP + Comp can receive
CTS XCVR + Rig can receive
}
function TRigSettings.Text: string;
begin
Result := Format(
'Rig=%s|Port=COM%d|Baud=%s|Data=%s|Parity=%s|Stop=%s|RTS=%s|Dtr=%s|Poll=%d|Timeout=%d',
[
MainForm.RigComboBox.Items[RigType],
Port,
MainForm.BaudRateComboBox.Items[BaudRate],
MainForm.DataBitsComboBox.Items[DataBits],
MainForm.ParityComboBox.Items[Parity],
MainForm.StopBitsComboBox.Items[StopBits],
MainForm.RtsComboBox.Items[RtsMode],
MainForm.DtrComboBox.Items[DtrMode],
PollMs,
TimeoutMs
]);
end;
end.