source: PinConnection/CommTelnetComPortOption.pas

Last change on this file was 575, checked in by chronos, 5 months ago
  • Modified: Remove U prefix from unit names of PinConnection package.
File size: 5.9 KB
Line 
1unit CommTelnetComPortOption;
2
3interface
4
5uses
6 Classes, SysUtils, CommTelnet, SerialPort, SpecializedList, UBinarySerializer;
7
8type
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
51implementation
52
53{ TTelnetOptionComPort }
54
55function TTelnetOptionComPort.GetDataBits: TDataBits;
56begin
57end;
58
59function TTelnetOptionComPort.GetDTR: Boolean;
60begin
61end;
62
63function TTelnetOptionComPort.GetFlowControl: TFlowControl;
64begin
65end;
66
67function TTelnetOptionComPort.GetParity: TParity;
68begin
69end;
70
71function TTelnetOptionComPort.GetRTS: Boolean;
72begin
73end;
74
75function TTelnetOptionComPort.GetStopBits: TStopBits;
76begin
77end;
78
79procedure TTelnetOptionComPort.SetActive(AValue: Boolean);
80begin
81 inherited;
82 if AValue then begin
83 SetBaudRate(FBaudRate);
84 SetDTR(FDTR);
85 SetRTS(FRTS);
86 SetFlowControl(fcNone);
87 end;
88end;
89
90procedure TTelnetOptionComPort.SetBaudRate(Value: Cardinal);
91var
92 Request: TBinarySerializer;
93begin
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;
107end;
108
109function TTelnetOptionComPort.GetBaudRate: Cardinal;
110var
111 Request: TBinarySerializer;
112 Response: TBinarySerializer;
113begin
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;
133end;
134
135procedure TTelnetOptionComPort.SetDataBits(AValue: TDataBits);
136begin
137end;
138
139procedure TTelnetOptionComPort.SetDTR(AValue: Boolean);
140var
141 Request: TBinarySerializer;
142begin
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;
156end;
157
158procedure TTelnetOptionComPort.SetFlowControl(AValue: TFlowControl);
159var
160 Request: TBinarySerializer;
161begin
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;
177end;
178
179procedure TTelnetOptionComPort.SetParity(AValue: TParity);
180begin
181end;
182
183procedure TTelnetOptionComPort.SetRTS(AValue: Boolean);
184var
185 Request: TBinarySerializer;
186begin
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;
200end;
201
202procedure TTelnetOptionComPort.SetStopBits(AValue: TStopBits);
203begin
204end;
205
206constructor TTelnetOptionComPort.Create;
207begin
208 Code := tmComPortControlOption;
209end;
210
211destructor TTelnetOptionComPort.Destroy;
212begin
213 inherited;
214end;
215
216procedure TTelnetOptionComPort.Assign(Source: TTelnetOption);
217begin
218 FBaudRate := TTelnetOptionComPort(Source).FBaudRate;
219 FDTR := TTelnetOptionComPort(Source).FDTR;
220 FRTS := TTelnetOptionComPort(Source).FRTS;
221 inherited Assign(Source);
222end;
223
224end.
225
Note: See TracBrowser for help on using the repository browser.