source: PinConnection/UCommTelnetComPortOption.pas

Last change on this file was 440, checked in by chronos, 12 years ago
  • Fixed: Thread safe access to serial port pin interface using lock.
File size: 5.9 KB
Line 
1unit UCommTelnetComPortOption;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, UCommTelnet, USerialPort,
9 SpecializedList, UBinarySerializer;
10
11type
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
54implementation
55
56{ TTelnetOptionComPort }
57
58function TTelnetOptionComPort.GetDataBits: TDataBits;
59begin
60
61end;
62
63function TTelnetOptionComPort.GetDTR: Boolean;
64begin
65
66end;
67
68function TTelnetOptionComPort.GetFlowControl: TFlowControl;
69begin
70
71end;
72
73function TTelnetOptionComPort.GetParity: TParity;
74begin
75
76end;
77
78function TTelnetOptionComPort.GetRTS: Boolean;
79begin
80
81end;
82
83function TTelnetOptionComPort.GetStopBits: TStopBits;
84begin
85
86end;
87
88procedure TTelnetOptionComPort.SetActive(AValue: Boolean);
89begin
90 inherited;
91 if AValue then begin
92 SetBaudRate(FBaudRate);
93 SetDTR(FDTR);
94 SetRTS(FRTS);
95 SetFlowControl(fcNone);
96 end;
97end;
98
99procedure TTelnetOptionComPort.SetBaudRate(Value: Cardinal);
100var
101 Request: TBinarySerializer;
102begin
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;
116end;
117
118function TTelnetOptionComPort.GetBaudRate: Cardinal;
119var
120 Request: TBinarySerializer;
121 Response: TBinarySerializer;
122begin
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;
142end;
143
144procedure TTelnetOptionComPort.SetDataBits(AValue: TDataBits);
145begin
146
147end;
148
149procedure TTelnetOptionComPort.SetDTR(AValue: Boolean);
150var
151 Request: TBinarySerializer;
152begin
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;
166end;
167
168procedure TTelnetOptionComPort.SetFlowControl(AValue: TFlowControl);
169var
170 Request: TBinarySerializer;
171begin
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;
187end;
188
189procedure TTelnetOptionComPort.SetParity(AValue: TParity);
190begin
191
192end;
193
194procedure TTelnetOptionComPort.SetRTS(AValue: Boolean);
195var
196 Request: TBinarySerializer;
197begin
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;
211end;
212
213procedure TTelnetOptionComPort.SetStopBits(AValue: TStopBits);
214begin
215
216end;
217
218constructor TTelnetOptionComPort.Create;
219begin
220 Code := tmComPortControlOption;
221end;
222
223destructor TTelnetOptionComPort.Destroy;
224begin
225 inherited Destroy;
226end;
227
228procedure TTelnetOptionComPort.Assign(Source: TTelnetOption);
229begin
230 FBaudRate := TTelnetOptionComPort(Source).FBaudRate;
231 FDTR := TTelnetOptionComPort(Source).FDTR;
232 FRTS := TTelnetOptionComPort(Source).FRTS;
233 inherited Assign(Source);
234end;
235
236end.
237
Note: See TracBrowser for help on using the repository browser.