-
Notifications
You must be signed in to change notification settings - Fork 0
/
customcommandf.pas
183 lines (151 loc) · 3.96 KB
/
customcommandf.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
unit CustomCommandF;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ActnList, Spin, synaser;
type
{ TCustomCommandForm }
TCustomCommandForm = class(TForm)
btSend: TButton;
btAdd: TButton;
btClear: TButton;
cbCommands: TComboBox;
cbQuery: TCheckBox;
cbInt1: TCheckBox;
cbInt2: TCheckBox;
cbFloat: TCheckBox;
cbTerminator: TComboBox;
cbAwaitResponse: TCheckBox;
eInt2: TSpinEdit;
eFloat: TFloatSpinEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
mCustomCommand: TMemo;
eInt1: TSpinEdit;
eTimeout: TSpinEdit;
procedure btAddClick(Sender: TObject);
procedure btClearClick(Sender: TObject);
procedure btSendClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure GetCommands;
{ private declarations }
public
Form: pointer;
{ public declarations }
end;
var
CustomCommandForm: TCustomCommandForm;
Command: shortstring;
implementation
uses MainF, BaseConF;
{$R *.lfm}
{ TCustomCommandForm }
procedure TCustomCommandForm.btSendClick(Sender: TObject);
var
i, t: longint;
s: ansistring;
begin
with tConnectionForm(Form) do
begin
for i:= 0 to mCustomCommand.Lines.Count - 1 do
Command+= mCustomCommand.Lines[i];
case cbTerminator.ItemIndex of
0: Command+= CR;
1: Command+= LF;
2: Command+= CRLF;
end;
case ConnectionKind of
//cNone: ;
cSerial:
if SerPort.InstanceActive then
begin
EnterCriticalSection(CommCS);
SerPort.RaiseExcept:= false;
SerPort.SendString(Command);
if cbAwaitResponse.Checked then
begin
s:= SerPort.Recvstring(eTimeOut.Value);
ShowMessage(s);
end;
SerPort.RaiseExcept:= true;
LeaveCriticalSection(CommCS);
end;
cUSB: ;
cTelNet:
begin
EnterCriticalSection(CommCS);
TelNetClient.Send(Command);
if cbAwaitResponse.Checked then
begin
t:= TelNetClient.Timeout;
TelNetClient.Timeout:= eTimeOut.Value;
s:= TelNetClient.RecvTerminated(CurrentDevice^.Terminator);
ShowMessage(s);
TelNetClient.Timeout:= t;
end;
LeaveCriticalSection(CommCS);
end;
cVXI: ;
end;
Command:= '';
end;
end;
procedure TCustomCommandForm.btAddClick(Sender: TObject);
var
Params, s: string;
begin
Params:= '';
if cbQuery.Checked then
Params:= '?';
str(eInt1.Value, s);
if cbInt1.Checked then
Params+= ' ' + s; //;!!
str(eInt2.Value, s);
if cbInt2.Checked then
Params+= ' ' + s;
str(eFloat.Value, s);
if cbFloat.Checked then
Params+= ' ' + s;
if mCustomCommand.Lines.Count > 0 then
mCustomCommand.Lines.Append(';');
mCustomCommand.Lines.AddText(cbCommands.Text + Params);
end;
procedure TCustomCommandForm.btClearClick(Sender: TObject);
begin
mCustomCommand.Clear;
end;
procedure TCustomCommandForm.FormShow(Sender: TObject);
begin
with tConnectionForm(Form) do
begin
Self.Top:= Top;
Self.Left:= Left;
Label2.Caption:= CurrentDevice^.Manufacturer + ' ' + CurrentDevice^.Model;
end;
if Label2.Caption = '' then
Label2.Caption:= 'Устройство не опознано';
GetCommands;
end;
procedure TCustomCommandForm.GetCommands;
begin
cbCommands.Clear;
with tConnectionForm(Form).CurrentDevice^ do
begin
cbCommands.Items.AddStrings(Commands);
case Terminator of
CR: cbTerminator.ItemIndex:= cbTerminator.Items.IndexOf('CR');
LF: cbTerminator.ItemIndex:= cbTerminator.Items.IndexOf('LF');
CRLF: cbTerminator.ItemIndex:= cbTerminator.Items.IndexOf('CRLF');
end;
eTimeOut.Value:= TimeOut;
end;
if cbCommands.Items.Count > 0 then
while cbCommands.Items[0] = '' do
cbCommands.Items.Delete(0);
end;
end.