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