1 | unit UCommTelnetComPortOption;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UCommTelnet, USerialPort,
|
---|
9 | SpecializedList, UBinarySerializer;
|
---|
10 |
|
---|
11 | type
|
---|
12 | TComPortOptionCommand = (cpcSetBaudRate = 1, cpcSetDataSize = 2,
|
---|
13 | cpcSetParity = 3, cpcSetStopSize = 4, cpcSetControl = 5, cpcNotifyLineState = 6,
|
---|
14 | cpcNotifyModeState = 7, cpcFlowControlSuspend = 8, cpcFlowControlResume = 9,
|
---|
15 | cpcLineStateMask = 10, cpcModemStateMask = 11, cpcPurgeData = 12);
|
---|
16 |
|
---|
17 | { TTelnetOptionComPort }
|
---|
18 |
|
---|
19 | TTelnetOptionComPort = class(TTelnetOption)
|
---|
20 | private
|
---|
21 | FBaudRate: Cardinal;
|
---|
22 | FDTR: Boolean;
|
---|
23 | FRTS: Boolean;
|
---|
24 | function GetDataBits: TDataBits;
|
---|
25 | function GetDTR: Boolean;
|
---|
26 | function GetFlowControl: TFlowControl;
|
---|
27 | function GetParity: TParity;
|
---|
28 | function GetRTS: Boolean;
|
---|
29 | function GetStopBits: TStopBits;
|
---|
30 | function GetBaudRate: Cardinal;
|
---|
31 | procedure SetBaudRate(Value: Cardinal);
|
---|
32 | procedure SetDataBits(AValue: TDataBits);
|
---|
33 | procedure SetDTR(AValue: Boolean);
|
---|
34 | procedure SetFlowControl(AValue: TFlowControl);
|
---|
35 | procedure SetParity(AValue: TParity);
|
---|
36 | procedure SetRTS(AValue: Boolean);
|
---|
37 | procedure SetStopBits(AValue: TStopBits);
|
---|
38 | protected
|
---|
39 | procedure SetActive(AValue: Boolean); override;
|
---|
40 | public
|
---|
41 | constructor Create;
|
---|
42 | destructor Destroy; override;
|
---|
43 | procedure Assign(Source: TTelnetOption); override;
|
---|
44 | property FlowControl: TFlowControl read GetFlowControl write SetFlowControl;
|
---|
45 | property DataBits: TDataBits read GetDataBits write SetDataBits;
|
---|
46 | property StopBits: TStopBits read GetStopBits write SetStopBits;
|
---|
47 | property Parity: TParity read GetParity write SetParity;
|
---|
48 | property BaudRate: Cardinal read GetBaudRate write SetBaudRate;
|
---|
49 | property RTS: Boolean read GetRTS write SetRTS;
|
---|
50 | property DTR: Boolean read GetDTR write SetDTR;
|
---|
51 | end;
|
---|
52 |
|
---|
53 |
|
---|
54 | implementation
|
---|
55 |
|
---|
56 | { TTelnetOptionComPort }
|
---|
57 |
|
---|
58 | function TTelnetOptionComPort.GetDataBits: TDataBits;
|
---|
59 | begin
|
---|
60 |
|
---|
61 | end;
|
---|
62 |
|
---|
63 | function TTelnetOptionComPort.GetDTR: Boolean;
|
---|
64 | begin
|
---|
65 |
|
---|
66 | end;
|
---|
67 |
|
---|
68 | function TTelnetOptionComPort.GetFlowControl: TFlowControl;
|
---|
69 | begin
|
---|
70 |
|
---|
71 | end;
|
---|
72 |
|
---|
73 | function TTelnetOptionComPort.GetParity: TParity;
|
---|
74 | begin
|
---|
75 |
|
---|
76 | end;
|
---|
77 |
|
---|
78 | function TTelnetOptionComPort.GetRTS: Boolean;
|
---|
79 | begin
|
---|
80 |
|
---|
81 | end;
|
---|
82 |
|
---|
83 | function TTelnetOptionComPort.GetStopBits: TStopBits;
|
---|
84 | begin
|
---|
85 |
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TTelnetOptionComPort.SetActive(AValue: Boolean);
|
---|
89 | begin
|
---|
90 | inherited;
|
---|
91 | if AValue then begin
|
---|
92 | SetBaudRate(FBaudRate);
|
---|
93 | SetDTR(FDTR);
|
---|
94 | SetRTS(FRTS);
|
---|
95 | SetFlowControl(fcNone);
|
---|
96 | end;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TTelnetOptionComPort.SetBaudRate(Value: Cardinal);
|
---|
100 | var
|
---|
101 | Request: TBinarySerializer;
|
---|
102 | begin
|
---|
103 | FBaudRate := Value;
|
---|
104 | if Telnet.Active then
|
---|
105 | try
|
---|
106 | Request := TBinarySerializer.Create;
|
---|
107 | Request.Endianness := enBig;
|
---|
108 | Request.List := TListByte.Create;
|
---|
109 | Request.OwnsList := True;
|
---|
110 | Request.WriteByte(Byte(cpcSetBaudRate));
|
---|
111 | Request.WriteCardinal(Value);
|
---|
112 | Telnet.SendSubCommand(tmComPortControlOption, Request.List, nil);
|
---|
113 | finally
|
---|
114 | Request.Free;
|
---|
115 | end;
|
---|
116 | end;
|
---|
117 |
|
---|
118 | function TTelnetOptionComPort.GetBaudRate: Cardinal;
|
---|
119 | var
|
---|
120 | Request: TBinarySerializer;
|
---|
121 | Response: TBinarySerializer;
|
---|
122 | begin
|
---|
123 | if Telnet.Active then
|
---|
124 | try
|
---|
125 | Request := TBinarySerializer.Create;
|
---|
126 | Request.List := TListByte.Create;
|
---|
127 | Request.OwnsList := True;
|
---|
128 | Request.Endianness := enBig;
|
---|
129 | Response := TBinarySerializer.Create;
|
---|
130 | Response.List := TListByte.Create;
|
---|
131 | Response.OwnsList := True;
|
---|
132 | Response.Endianness := enBig;
|
---|
133 | Request.WriteByte(Byte(cpcSetBaudRate));
|
---|
134 | Request.WriteCardinal(0);
|
---|
135 | Telnet.SendSubCommand(tmComPortControlOption, Request.List, Response.List);
|
---|
136 | Response.Position := 0;
|
---|
137 | Result := Response.ReadCardinal;
|
---|
138 | finally
|
---|
139 | Response.Free;
|
---|
140 | Request.Free;
|
---|
141 | end else Result := 0;
|
---|
142 | end;
|
---|
143 |
|
---|
144 | procedure TTelnetOptionComPort.SetDataBits(AValue: TDataBits);
|
---|
145 | begin
|
---|
146 |
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TTelnetOptionComPort.SetDTR(AValue: Boolean);
|
---|
150 | var
|
---|
151 | Request: TBinarySerializer;
|
---|
152 | begin
|
---|
153 | FDTR := AValue;
|
---|
154 | if Telnet.Active then
|
---|
155 | try
|
---|
156 | Request := TBinarySerializer.Create;
|
---|
157 | Request.List := TListByte.Create;
|
---|
158 | Request.OwnsList := True;
|
---|
159 | Request.WriteByte(Byte(cpcSetControl));
|
---|
160 | if AValue then Request.WriteByte(8)
|
---|
161 | else Request.WriteByte(9);
|
---|
162 | Telnet.SendSubCommand(tmComPortControlOption, Request.List, nil);
|
---|
163 | finally
|
---|
164 | Request.Free;
|
---|
165 | end;
|
---|
166 | end;
|
---|
167 |
|
---|
168 | procedure TTelnetOptionComPort.SetFlowControl(AValue: TFlowControl);
|
---|
169 | var
|
---|
170 | Request: TBinarySerializer;
|
---|
171 | begin
|
---|
172 | if Telnet.Active then
|
---|
173 | try
|
---|
174 | Request := TBinarySerializer.Create;
|
---|
175 | Request.List := TListByte.Create;
|
---|
176 | Request.OwnsList := True;
|
---|
177 | Request.WriteByte(Byte(cpcSetControl));
|
---|
178 | case AValue of
|
---|
179 | fcNone: Request.WriteByte(1);
|
---|
180 | fcSoftware: Request.WriteByte(2);
|
---|
181 | fcHardware: Request.WriteByte(3);
|
---|
182 | end;
|
---|
183 | Telnet.SendSubCommand(tmComPortControlOption, Request.List, nil);
|
---|
184 | finally
|
---|
185 | Request.Free;
|
---|
186 | end;
|
---|
187 | end;
|
---|
188 |
|
---|
189 | procedure TTelnetOptionComPort.SetParity(AValue: TParity);
|
---|
190 | begin
|
---|
191 |
|
---|
192 | end;
|
---|
193 |
|
---|
194 | procedure TTelnetOptionComPort.SetRTS(AValue: Boolean);
|
---|
195 | var
|
---|
196 | Request: TBinarySerializer;
|
---|
197 | begin
|
---|
198 | FRTS := AValue;
|
---|
199 | if Telnet.Active then
|
---|
200 | try
|
---|
201 | Request := TBinarySerializer.Create;
|
---|
202 | Request.List := TListByte.Create;
|
---|
203 | Request.OwnsList := True;
|
---|
204 | Request.WriteByte(Byte(cpcSetControl));
|
---|
205 | if AValue then Request.WriteByte(11)
|
---|
206 | else Request.WriteByte(12);
|
---|
207 | Telnet.SendSubCommand(tmComPortControlOption, Request.List, nil);
|
---|
208 | finally
|
---|
209 | Request.Free;
|
---|
210 | end;
|
---|
211 | end;
|
---|
212 |
|
---|
213 | procedure TTelnetOptionComPort.SetStopBits(AValue: TStopBits);
|
---|
214 | begin
|
---|
215 |
|
---|
216 | end;
|
---|
217 |
|
---|
218 | constructor TTelnetOptionComPort.Create;
|
---|
219 | begin
|
---|
220 | Code := tmComPortControlOption;
|
---|
221 | end;
|
---|
222 |
|
---|
223 | destructor TTelnetOptionComPort.Destroy;
|
---|
224 | begin
|
---|
225 | inherited Destroy;
|
---|
226 | end;
|
---|
227 |
|
---|
228 | procedure TTelnetOptionComPort.Assign(Source: TTelnetOption);
|
---|
229 | begin
|
---|
230 | FBaudRate := TTelnetOptionComPort(Source).FBaudRate;
|
---|
231 | FDTR := TTelnetOptionComPort(Source).FDTR;
|
---|
232 | FRTS := TTelnetOptionComPort(Source).FRTS;
|
---|
233 | inherited Assign(Source);
|
---|
234 | end;
|
---|
235 |
|
---|
236 | end.
|
---|
237 |
|
---|