Produced by Araxis Merge on 3/31/2017 10:45:44 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | CPRS v31A.zip\CPRS v31A\VITL5_P34_src.zip\Source\VS_Monitors | RS232.pas | Tue Dec 13 18:26:14 2016 UTC |
2 | CPRS v31A.zip\CPRS v31A\VITL5_P34_src.zip\Source\VS_Monitors | RS232.pas | Fri Mar 31 15:01:54 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 610 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | unit RS232 ; | |
2 | { | |
3 | ========== ========== ========== ========== ========== ========== ========== ========== | |
4 | * | |
5 | * Ap plication: Vitals | |
6 | * Re vision: $Revisio n: 1 $ $M odtime: 2/ 20/09 3:21 p $ | |
7 | * De veloper: PII | |
8 | * Si te: Hines OI FO | |
9 | * | |
10 | * De scription: COM supp ort for CA SMED Vital s Signs Mo nitor | |
11 | * | |
12 | * No tes: | |
13 | * The or iginal ver sion of un it provide d by CASME D supporte d | |
14 | * ports COM1 and C OM2 only. | |
15 | * Change s allow pr ovide the port numbe r as a par ameter | |
16 | ========== ========== ========== ========== ========== ========== ========== ========== | |
17 | } | |
18 | //******** ********** ********** ********** ********** ********** ********** ********** | |
19 | // uses o nly this u nit (RS232 ) and ATE7 40X: Use ATE740X c alls only. | |
20 | // TODO: 1) Deter mine XON X OFF capabi lities. | |
21 | // 2) Tight en FNewCom PortTimeOu ts setting s. | |
22 | // 3) Deter mine if Ex ception me ssages her e are real ly necessa ry. | |
23 | //******** ********** ********** ********** ********** ********** ********** ********** | |
24 | ||
25 | interface | |
26 | ||
27 | uses | |
28 | Windows, SysUtils, Dialogs; | |
29 | ||
30 | type | |
31 | TComPort Status = ( cpsOpened, cpsClosed ); | |
32 | ||
33 | TCharArr ay = array [0..25] of AnsiChar; | |
34 | ||
35 | TComPort = class(T Object) | |
36 | private | |
37 | { Priv ate declar ations } | |
38 | FComPo rtName: st ring; | |
39 | FComPo rtHandle: THandle; | |
40 | FPrevi ousComPort : TDCB; | |
41 | FNewCo mPort: TDC B; | |
42 | FPrevi ousComPort Timeouts: TCommTimeo uts; | |
43 | FNewCo mPortTimeO uts: TComm Timeouts; | |
44 | FComPo rtInputBuf fer: TChar Array; //? ??? | |
45 | FComma ndResults: String; | |
46 | public | |
47 | { Publ ic declara tions } | |
48 | ComPor tStatus: T ComPortSta tus; | |
49 | proper ty ComPort name: stri ng read FC omPortName ; | |
50 | functi on Open(aN ame: strin g = ''): b oolean; | |
51 | functi on GetPrev iousComPor tSettings: boolean; | |
52 | functi on SetNewC omPortSett ings: bool ean; | |
53 | functi on Config: boolean; | |
54 | functi on Read(Nu mberOfByte sExpected: integer): boolean; | |
55 | functi on Write(C ommand: st ring): boo lean; | |
56 | functi on Purge: boolean; | |
57 | proper ty Command Results: s tring read FCommandR esults wri te FComman dResults; | |
58 | proced ure Close; | |
59 | constr uctor Crea te; | |
60 | ||
61 | end; | |
62 | //******** ********** ********** ********** ********** ********** ********** ********** | |
63 | //var | |
64 | // ComPor t: TComPor t; | |
65 | ||
66 | const | |
67 | // buffer sizes -- ---------- ---------- -------- | |
68 | RX_BUFFE R_SIZE = 1 024; | |
69 | TX_BUFFE R_SIZE = 1 024; | |
70 | // CAS 74 0X COMM PR OTOCOLS - ---------- -------- | |
71 | CAS_COMM _PROTOCOL_ BAUD = CBR _115200; // 115200 B aud | |
72 | CAS_COMM _PROTOCOL_ FLAGS = $0 001; // FLAGS >> binary on ly. | |
73 | CAS_COMM _PROTOCOL_ DATA_BITS = DATABITS _8; // 8 DataBi ts | |
74 | CAS_COMM _PROTOCOL_ PARITY = N OPARITY; // No Parit y | |
75 | CAS_COMM _PROTOCOL_ STOP_BIT = ONESTOPBI T; // 1 Stop B it | |
76 | //-------- ---------- ---------- ---------- -------- | |
77 | ||
78 | DefaultP ortName = 'COM1'; | |
79 | ||
80 | implementa tion | |
81 | ||
82 | //******** ********** ********** ********** ********** ********** ********** ********** | |
83 | ||
84 | constructo r TComPort .Create; | |
85 | begin | |
86 | inherite d Create; | |
87 | FComPort Handle := INVALID_HA NDLE_VALUE ; | |
88 | ComPortS tatus := c psClosed; | |
89 | end; | |
90 | ||
91 | function T ComPort.Ge tPreviousC omPortSett ings: bool ean; | |
92 | begin | |
93 | if not G etCommStat e(FComPort Handle, FP reviousCom Port) then | |
94 | begin | |
95 | Except ion.Create ('COM PORT ERROR: Ge tCommState failed. ( previous s ettings)') ; | |
96 | result := FALSE; | |
97 | exit; | |
98 | end; | |
99 | if not G etCommTime outs(FComP ortHandle, FPrevious ComPortTim eouts) the n | |
100 | begin | |
101 | Except ion.Create ('COM PORT ERROR: Ge tCommTimeo uts failed .'); | |
102 | result := FALSE; | |
103 | exit; | |
104 | end; | |
105 | result : = TRUE; | |
106 | end; | |
107 | ||
108 | function T ComPort.Se tNewComPor tSettings: boolean; | |
109 | begin | |
110 | result : = TRUE; | |
111 | with FNe wComPortTi meOuts do | |
112 | begin | |
113 | ReadIn tervalTime out := 200 ; | |
114 | ReadTo talTimeout Multiplier := 0; | |
115 | ReadTo talTimeout Constant : = 0; | |
116 | WriteT otalTimeou tMultiplie r := 0; | |
117 | WriteT otalTimeou tConstant := 0; | |
118 | end; | |
119 | if not S etCommTime outs(FComP ortHandle, FNewComPo rtTimeOuts ) then | |
120 | begin | |
121 | Except ion.Create ('COM PORT ERROR: Se tCommTimeo uts failed .'); | |
122 | result := FALSE; | |
123 | exit; | |
124 | end; | |
125 | end; | |
126 | ||
127 | function T ComPort.Co nfig: bool ean; | |
128 | begin | |
129 | if not G etCommStat e(FComPort Handle, FN ewComPort) then | |
130 | Except ion.Create ('COM PORT ERROR: Ge tCommState failed. ( config)'); | |
131 | ||
132 | with FNe wComPort d o | |
133 | begin | |
134 | DCBLen gth := siz eof(TDCB); | |
135 | BaudRa te := CAS_ COMM_PROTO COL_BAUD; | |
136 | Flags := CAS_COM M_PROTOCOL _FLAGS; | |
137 | ByteSi ze := CAS_ COMM_PROTO COL_DATA_B ITS; | |
138 | Parity := CAS_CO MM_PROTOCO L_PARITY; | |
139 | StopBi ts := CAS_ COMM_PROTO COL_STOP_B IT; | |
140 | end; | |
141 | ||
142 | if not S etCommStat e(FComPort Handle, FN ewComPort) then | |
143 | Except ion.Create ('COM PORT ERROR: Se tCommState failed.') ; | |
144 | ||
145 | if not S etupComm(F ComPortHan dle, RX_BU FFER_SIZE, TX_BUFFER _SIZE) the n | |
146 | Except ion.Create ('COM PORT ERROR: Se tupComm fa iled.'); | |
147 | ||
148 | result : = (FComPor tHandle <> INVALID_H ANDLE_VALU E); | |
149 | end; | |
150 | ||
151 | function T ComPort.Op en(aName: string = ' '): boolea n; | |
152 | ||
153 | function setPortBy Name(_Name : string): Boolean; | |
154 | begin | |
155 | Result := False; | |
156 | FComPo rtName := _Name; | |
157 | FComPo rtHandle : = CreateFi le(pchar(_ Name), | |
158 | GENE RIC_READ o r GENERIC_ WRITE, | |
159 | 0, // Excl usive. (No Sharing) | |
160 | nil, // No i nheritance . | |
161 | OPEN _EXISTING, // Devi ces use OP EN_EXISTIN G. | |
162 | FILE _ATTRIBUTE _NORMAL, // Devi ces use FI LE_ATTRIBU TE_NORMAL. | |
163 | 0); // Devi ces use No hTemplate File. | |
164 | if FCo mPortHandl e <> INVAL ID_HANDLE_ VALUE then | |
165 | if ( GetPreviou sComPortSe ttings) th en | |
166 | if (SetNewCo mPortSetti ngs) then | |
167 | result := TRUE; | |
168 | end; | |
169 | ||
170 | function setPort(a Names: arr ay of stri ng): Boole an; | |
171 | var | |
172 | sMsg, | |
173 | sNam e: string; | |
174 | i: Int eger; | |
175 | begin | |
176 | sMsg : = ''; | |
177 | Result := False; | |
178 | for i := Low(aNa mes) to Hi gh(aNames) do | |
179 | begin | |
180 | sNam e := aName s[i]; | |
181 | sMsg := sMsg + ' ' + sNa me + ','; | |
182 | if s etPortByNa me(sName) then | |
183 | begi n | |
184 | Re sult := Tr ue; | |
185 | fC omPortName := sName; | |
186 | br eak; | |
187 | end; | |
188 | end; | |
189 | if not Result th en | |
190 | Exce ption.Crea te('Failt to connect to ports: ' + copy(s Msg, 1, le ngth(sMsg) - 1)); | |
191 | end; | |
192 | ||
193 | begin | |
194 | Result : = False; | |
195 | // ignor e if there is a port opened -- ---------- -------- v haishandri a 20090115 | |
196 | if ComPo rtStatus = cpsOpened then | |
197 | Exit; | |
198 | ||
199 | if aName = '' then | |
200 | Result := setPor tByName(De faultPortN ame) | |
201 | else | |
202 | Result := setPor tByName(aN ame); | |
203 | ||
204 | if Resul t then | |
205 | ComPor tStatus := cpsOpened ; | |
206 | end; | |
207 | ||
208 | function T ComPort.Pu rge: boole an; | |
209 | begin | |
210 | result : = PurgeCom m(FComPort Handle, PU RGE_TXABOR T or PURGE _RXABORT o r PURGE_TX CLEAR or P URGE_RXCLE AR); | |
211 | end; | |
212 | ||
213 | function T ComPort.Re ad(NumberO fBytesExpe cted: inte ger): bool ean; | |
214 | var | |
215 | ComPortE rror, Byte sRead: DWO RD; | |
216 | ComPortS tat: TComS tat; | |
217 | ReadStri ng: AnsiSt ring; | |
218 | I: Integ er; | |
219 | begin | |
220 | // Sleep( 1); // T his seems to alievea te hangs.. . | |
221 | ClearCom mError(FCo mPortHandl e, ComPort Error, @Co mPortStat) ; | |
222 | ClearCom mError(FCo mPortHandl e, ComPort Error, @Co mPortStat) ; | |
223 | setLengt h(ReadStri ng, ComPor tStat.cbIn Que); | |
224 | ReadFile (FComPortH andle, Rea dString[1] , ComPortS tat.cbInQu e, BytesRe ad, nil); | |
225 | FCommand Results := String(Re adString); | |
226 | result : = (ComPort Stat.cbInQ ue = Lengt h(FCommand Results)); | |
227 | end; | |
228 | ||
229 | function T ComPort.Wr ite(Comman d: string) : boolean; | |
230 | var | |
231 | BytesWri tten: DWOR D; | |
232 | charComm andBuffer: array[0.. 5] of Ansi Char; | |
233 | begin | |
234 | Purge; | |
235 | StrPCopy (charComma ndBuffer, Command); // Null t erminated strings... | |
236 | WriteFil e(FComPort Handle, ch arCommandB uffer, Len gth(Comman d), BytesW ritten, ni l); | |
237 | result : = (Integer (BytesWrit ten) = Len gth(Comman d)); | |
238 | end; | |
239 | ||
240 | procedure TComPort.C lose; | |
241 | begin | |
242 | if (FCom PortHandle <> INVALI D_HANDLE_V ALUE) then | |
243 | begin | |
244 | SetCom mTimeouts( FComPortHa ndle, FPre viousComPo rtTimeouts ); | |
245 | SetCom mState(FCo mPortHandl e, FPrevio usComPort) ; | |
246 | CloseH andle(FCom PortHandle ); | |
247 | FComPo rtHandle : = INVALID_ HANDLE_VAL UE; | |
248 | ComPor tStatus := cpsClosed ; | |
249 | end; | |
250 | end; | |
251 | ||
252 | (* ======= ========== ========== ====== Ori ginal Open method. v haishandri a 20090112 | |
253 | function T ComPort.Op en: boolea n; | |
254 | begin | |
255 | FComPort Name := 'C OM1'; | |
256 | //-------- ---------- ---------- ---------- -------- | |
257 | FComPort Handle := CreateFile (pchar(FCo mPortName) , | |
258 | GENERI C_READ or GENERIC_WR ITE, | |
259 | 0, // Exclusive . (No Shar ing) | |
260 | nil, / / No inhe ritance. | |
261 | OPEN_E XISTING, / / Devices use OPEN_ EXISTING. | |
262 | FILE_A TTRIBUTE_N ORMAL, // Devices u se FILE_AT TRIBUTE_NO RMAL. | |
263 | 0); // Devices use No hTe mplateFile . | |
264 | //-------- ---------- ---------- ---------- -------- | |
265 | if (FCom PortHandle <> INVALI D_HANDLE_V ALUE) then | |
266 | begin | |
267 | if (Ge tPreviousC omPortSett ings) then | |
268 | if ( SetNewComP ortSetting s) then | |
269 | re sult := TR UE | |
270 | else | |
271 | re sult := FA LSE // fa iled to Se tCommTimeo uts | |
272 | else | |
273 | resu lt := FALS E // fail ed to GetC ommTimeout s/GetCommS tate | |
274 | end else | |
275 | begin | |
276 | FComPo rtName := 'COM2'; | |
277 | //-------- ---------- ---------- ---------- -------- | |
278 | FComPo rtHandle : = CreateFi le(pchar(F ComPortNam e), | |
279 | GENE RIC_READ o r GENERIC_ WRITE, | |
280 | 0, / / Exclusi ve. (No Sh aring) | |
281 | nil, // No in heritance. | |
282 | OPEN _EXISTING, // Devic es use OPE N_EXISTING . | |
283 | FILE _ATTRIBUTE _NORMAL, / / Devices use FILE_ ATTRIBUTE_ NORMAL. | |
284 | 0); // Device s use No h TemplateFi le. | |
285 | //-------- ---------- ---------- ---------- -------- | |
286 | if (FC omPortHand le <> INVA LID_HANDLE _VALUE) th en | |
287 | begin | |
288 | if ( GetPreviou sComPortSe ttings) th en | |
289 | if (SetNewCo mPortSetti ngs) then | |
290 | result := TRUE | |
291 | el se | |
292 | result := FALSE // failed to SetCommTim eouts | |
293 | else | |
294 | re sult := FA LSE // fa iled to Ge tCommTimeo uts/GetCom mState | |
295 | end el se | |
296 | begin | |
297 | Exce ption.Crea te('COM PO RT ERROR: CreateFile failed.') ; | |
298 | resu lt := FALS E; // fai led to Get Handle. | |
299 | exit ; | |
300 | end; | |
301 | end; | |
302 | end; | |
303 | ========== ========== ========== ========== ========== ========== ========== ========*) | |
304 | ||
305 | end. | |
306 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.