1 | /* $Id: comm.cpp,v 1.8 2001-11-28 15:35:15 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Comport functions
|
---|
5 | *
|
---|
6 | * Copyright 1998 Patrick Haller (?)
|
---|
7 | * Copyright 1998 Felix Maschek (?)
|
---|
8 | * Copyright 2000 Markus Montkowski
|
---|
9 | *
|
---|
10 | * Partly based on Wine code (BuildCommDCBAndTimeoutsA; misc\comm.c)
|
---|
11 | *
|
---|
12 | * Copyright 1996 Marcus Meissner, Erik Bos
|
---|
13 | *
|
---|
14 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
15 | *
|
---|
16 | */
|
---|
17 | #include <os2win.h>
|
---|
18 | #include <odinwrap.h>
|
---|
19 | #include <ctype.h>
|
---|
20 | #include <string.h>
|
---|
21 | #include <stdio.h>
|
---|
22 | #include "winreg.h"
|
---|
23 | #include "global.h"
|
---|
24 | #include "winnt.h"
|
---|
25 | #include "winerror.h"
|
---|
26 | #include "winreg.h"
|
---|
27 |
|
---|
28 | #include "unicode.h"
|
---|
29 | #include "handlemanager.h"
|
---|
30 |
|
---|
31 | #define DBG_LOCALLOG DBG_comm
|
---|
32 | #include "dbglocal.h"
|
---|
33 | ODINDEBUGCHANNEL(KERNEL32-COMM)
|
---|
34 |
|
---|
35 | /*****************************************************************************
|
---|
36 | * @returns True on success and fills the COMMCONFIG structure
|
---|
37 | * @param lpDef Pointer to device-control string
|
---|
38 | * @param lpDCB Pointer to device-control buffer
|
---|
39 | * @remark
|
---|
40 | * @status untested
|
---|
41 | * @author Markus Montkowski
|
---|
42 | *****************************************************************************/
|
---|
43 |
|
---|
44 | BOOL WIN32API BuildCommDCBA( LPCSTR lpDef, LPDCB lpDCB )
|
---|
45 | {
|
---|
46 | return BuildCommDCBAndTimeoutsA(lpDef,lpDCB,NULL);
|
---|
47 | }
|
---|
48 |
|
---|
49 | //------------------------------------------------------------------------------
|
---|
50 |
|
---|
51 | BOOL WIN32API BuildCommDCBW( LPCWSTR lpDef, LPDCB lpDCB )
|
---|
52 | {
|
---|
53 | char *asciiname;
|
---|
54 | BOOL rc;
|
---|
55 |
|
---|
56 | asciiname = UnicodeToAsciiString((LPWSTR)lpDef);
|
---|
57 | rc = BuildCommDCBAndTimeoutsA(asciiname, lpDCB, NULL);
|
---|
58 | FreeAsciiString(asciiname);
|
---|
59 | return(rc);
|
---|
60 | }
|
---|
61 |
|
---|
62 | //------------------------------------------------------------------------------
|
---|
63 |
|
---|
64 | BOOL ValidCOMPort(int Port)
|
---|
65 | {
|
---|
66 | // @@@ Todo check in the handlemanager for a registered COM DeviceHandle for this number
|
---|
67 | // We currently only do static add COM1-COM8 so we simply check for 8
|
---|
68 | return (Port <=8);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /*****************************************************************************
|
---|
72 | * @returns True on success and fills the COMMCONFIG structure
|
---|
73 | * @param lpDef Pointer to device-control string
|
---|
74 | * @param lpDCB Pointer to device-control buffer
|
---|
75 | * @param lpCommTimeouts Pointer to COMMTIMEOUTS
|
---|
76 | * @remark
|
---|
77 | * @status partly implemented
|
---|
78 | * @author Markus Montkowski
|
---|
79 | *****************************************************************************/
|
---|
80 |
|
---|
81 |
|
---|
82 | BOOL WIN32API BuildCommDCBAndTimeoutsA( LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts )
|
---|
83 | {
|
---|
84 | int port,i;
|
---|
85 | char szNumber[4];
|
---|
86 | char *ptr,*temp;
|
---|
87 |
|
---|
88 | dprintf(("(%s,%p,%p)\n",lpDef,lpDCB,lpCommTimeouts));
|
---|
89 |
|
---|
90 | port = -1;
|
---|
91 |
|
---|
92 | if (!strnicmp(lpDef,"COM",3))
|
---|
93 | {
|
---|
94 |
|
---|
95 | for(i=0;((lpDef[3+i]!=':') && (i<3));i++)
|
---|
96 | szNumber[i] = lpDef[3+i];
|
---|
97 | szNumber[i] = 0;
|
---|
98 |
|
---|
99 | port = atoi(szNumber);
|
---|
100 | if (port==0 || lpDef[i]!=':')
|
---|
101 | {
|
---|
102 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
103 | return FALSE;
|
---|
104 | }
|
---|
105 |
|
---|
106 | if (!ValidCOMPort(port))
|
---|
107 | {
|
---|
108 | SetLastError(ERROR_FILE_NOT_FOUND);
|
---|
109 | return FALSE;
|
---|
110 | }
|
---|
111 | temp=(LPSTR)(lpDef+4+i);
|
---|
112 | }
|
---|
113 | else
|
---|
114 | temp=(LPSTR)lpDef;
|
---|
115 |
|
---|
116 | lpDCB->DCBlength = sizeof(DCB);
|
---|
117 | if (strchr(temp,','))
|
---|
118 | {
|
---|
119 | // old style
|
---|
120 |
|
---|
121 | char last=temp[strlen(temp)-1];
|
---|
122 |
|
---|
123 | ptr = strtok(temp, ", ");
|
---|
124 |
|
---|
125 |
|
---|
126 | lpDCB->BaudRate = atoi(ptr);
|
---|
127 | dprintf(("baudrate (%d)\n", lpDCB->BaudRate));
|
---|
128 |
|
---|
129 | ptr = strtok(NULL, ", ");
|
---|
130 | if (islower(*ptr))
|
---|
131 | *ptr = toupper(*ptr);
|
---|
132 |
|
---|
133 | dprintf(("parity (%c)\n", *ptr));
|
---|
134 | lpDCB->fParity = TRUE;
|
---|
135 | switch (*ptr)
|
---|
136 | {
|
---|
137 | case 'N':
|
---|
138 | lpDCB->Parity = NOPARITY;
|
---|
139 | lpDCB->fParity = FALSE;
|
---|
140 | break;
|
---|
141 | case 'E':
|
---|
142 | lpDCB->Parity = EVENPARITY;
|
---|
143 | break;
|
---|
144 | case 'M':
|
---|
145 | lpDCB->Parity = MARKPARITY;
|
---|
146 | break;
|
---|
147 | case 'O':
|
---|
148 | lpDCB->Parity = ODDPARITY;
|
---|
149 | break;
|
---|
150 | default:
|
---|
151 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
152 | dprintf(("Unknown parity `%c'!\n", *ptr));
|
---|
153 | return FALSE;
|
---|
154 | }
|
---|
155 |
|
---|
156 | ptr = strtok(NULL, ", ");
|
---|
157 | dprintf(("charsize (%c)\n", *ptr));
|
---|
158 | lpDCB->ByteSize = *ptr - '0';
|
---|
159 |
|
---|
160 | if((lpDCB->ByteSize<5) ||
|
---|
161 | (lpDCB->ByteSize>8))
|
---|
162 | {
|
---|
163 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
164 | dprintf(("Unsupported bytesize `%d'!\n", lpDCB->ByteSize));
|
---|
165 | return FALSE;
|
---|
166 | }
|
---|
167 |
|
---|
168 | ptr = strtok(NULL, ", ");
|
---|
169 | dprintf(("stopbits (%c%c%c)\n", *ptr,*(ptr+1)=='.'?'.':' ',*(ptr+1)=='.'?*(ptr+2):' '));
|
---|
170 | switch (*ptr)
|
---|
171 | {
|
---|
172 | case '1':
|
---|
173 | if(*(ptr+1)=='.')
|
---|
174 | {
|
---|
175 | if(*(ptr+2)=='5')
|
---|
176 | lpDCB->StopBits = ONE5STOPBITS;
|
---|
177 | else
|
---|
178 | {
|
---|
179 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
180 | dprintf(("Unsupported # of stopbits !\n"));
|
---|
181 | return FALSE;
|
---|
182 | }
|
---|
183 | }
|
---|
184 | else
|
---|
185 | lpDCB->StopBits = ONESTOPBIT;
|
---|
186 | break;
|
---|
187 | case '2':
|
---|
188 | lpDCB->StopBits = TWOSTOPBITS;
|
---|
189 | break;
|
---|
190 | default:
|
---|
191 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
192 | dprintf(("Unknown # of stopbits `%c'!\n", *ptr));
|
---|
193 | return FALSE;
|
---|
194 | }
|
---|
195 |
|
---|
196 | if(lpDCB->BaudRate==110)
|
---|
197 | lpDCB->StopBits =2;
|
---|
198 |
|
---|
199 | if(((lpDCB->ByteSize==5)&&(lpDCB->StopBits==TWOSTOPBITS))||
|
---|
200 | ((lpDCB->ByteSize!=5)&&(lpDCB->StopBits==ONE5STOPBITS)) )
|
---|
201 | {
|
---|
202 | dprintf(("Unsupported Combination of Bytesize `%d' and StopBits %s!\n",
|
---|
203 | lpDCB->ByteSize,lpDCB->StopBits==ONE5STOPBITS?"1.5":"2"));
|
---|
204 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
205 | return FALSE;
|
---|
206 | }
|
---|
207 |
|
---|
208 | lpDCB->fBinary = TRUE;
|
---|
209 | lpDCB->fNull = FALSE;
|
---|
210 |
|
---|
211 | if (last == 'x')
|
---|
212 | {
|
---|
213 | lpDCB->fInX = TRUE;
|
---|
214 | lpDCB->fOutX = TRUE;
|
---|
215 | lpDCB->fOutxCtsFlow = FALSE;
|
---|
216 | lpDCB->fOutxDsrFlow = FALSE;
|
---|
217 | lpDCB->fDtrControl = DTR_CONTROL_ENABLE;
|
---|
218 | lpDCB->fRtsControl = RTS_CONTROL_ENABLE;
|
---|
219 | }
|
---|
220 | else
|
---|
221 | if (last=='p')
|
---|
222 | {
|
---|
223 | lpDCB->fInX = FALSE;
|
---|
224 | lpDCB->fOutX = FALSE;
|
---|
225 | lpDCB->fOutxCtsFlow = TRUE;
|
---|
226 | lpDCB->fOutxDsrFlow = TRUE;
|
---|
227 | lpDCB->fDtrControl = DTR_CONTROL_HANDSHAKE;
|
---|
228 | lpDCB->fRtsControl = RTS_CONTROL_HANDSHAKE;
|
---|
229 | }
|
---|
230 | else
|
---|
231 | {
|
---|
232 | lpDCB->fInX = FALSE;
|
---|
233 | lpDCB->fOutX = FALSE;
|
---|
234 | lpDCB->fOutxCtsFlow = FALSE;
|
---|
235 | lpDCB->fOutxDsrFlow = FALSE;
|
---|
236 | lpDCB->fDtrControl = DTR_CONTROL_ENABLE;
|
---|
237 | lpDCB->fRtsControl = RTS_CONTROL_ENABLE;
|
---|
238 | }
|
---|
239 | lpDCB->XonChar = 0;
|
---|
240 | lpDCB->XoffChar = 0;
|
---|
241 | lpDCB->ErrorChar = 0;
|
---|
242 | lpDCB->fErrorChar = 0;
|
---|
243 | lpDCB->EofChar = 0;
|
---|
244 | lpDCB->EvtChar = 0;
|
---|
245 | lpDCB->XonLim = 0;
|
---|
246 | lpDCB->XoffLim = 0;
|
---|
247 | return TRUE;
|
---|
248 | }
|
---|
249 |
|
---|
250 | ptr=strtok(temp," ");
|
---|
251 | while (ptr)
|
---|
252 | {
|
---|
253 | DWORD flag,x;
|
---|
254 |
|
---|
255 | flag=0;
|
---|
256 | if (!strnicmp("baud=",ptr,5))
|
---|
257 | {
|
---|
258 | if (!sscanf(ptr+5,"%ld",&x))
|
---|
259 | {
|
---|
260 | dprintf(("Couldn't parse %s\n",ptr));
|
---|
261 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
262 | return FALSE;
|
---|
263 | }
|
---|
264 | lpDCB->BaudRate = x;
|
---|
265 | flag=1;
|
---|
266 | }
|
---|
267 | if (!strnicmp("stop=",ptr,5))
|
---|
268 | {
|
---|
269 | if (!sscanf(ptr+5,"%ld",&x))
|
---|
270 | {
|
---|
271 | dprintf(("Couldn't parse %s\n",ptr));
|
---|
272 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
273 | return FALSE;
|
---|
274 | }
|
---|
275 | lpDCB->StopBits = x;
|
---|
276 | flag=1;
|
---|
277 | }
|
---|
278 | if (!strnicmp("data=",ptr,5))
|
---|
279 | {
|
---|
280 | if (!sscanf(ptr+5,"%ld",&x))
|
---|
281 | {
|
---|
282 | dprintf(("Couldn't parse %s\n",ptr));
|
---|
283 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
284 | return FALSE;
|
---|
285 | }
|
---|
286 | lpDCB->ByteSize = x;
|
---|
287 | flag=1;
|
---|
288 | }
|
---|
289 | if (!strnicmp("parity=",ptr,7))
|
---|
290 | {
|
---|
291 | lpDCB->fParity = TRUE;
|
---|
292 | switch (ptr[8])
|
---|
293 | {
|
---|
294 | case 'N':case 'n':
|
---|
295 | lpDCB->fParity = FALSE;
|
---|
296 | lpDCB->Parity = NOPARITY;
|
---|
297 | break;
|
---|
298 | case 'E':case 'e':
|
---|
299 | lpDCB->Parity = EVENPARITY;
|
---|
300 | break;
|
---|
301 | case 'O':case 'o':
|
---|
302 | lpDCB->Parity = ODDPARITY;
|
---|
303 | break;
|
---|
304 | case 'M':case 'm':
|
---|
305 | lpDCB->Parity = MARKPARITY;
|
---|
306 | break;
|
---|
307 | }
|
---|
308 | flag=1;
|
---|
309 | }
|
---|
310 | if (!strnicmp("to=",ptr,3))
|
---|
311 | {
|
---|
312 | if (!strnicmp("on",ptr+3,2))
|
---|
313 | {
|
---|
314 | if(NULL==lpCommTimeouts)
|
---|
315 | {
|
---|
316 | dprintf(("TO=ON and no lpCommTimeout"));
|
---|
317 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
318 | return FALSE;
|
---|
319 | }
|
---|
320 | else
|
---|
321 | {
|
---|
322 | // @@@ Todo Implement timout handling
|
---|
323 | flag=1;
|
---|
324 | }
|
---|
325 | }
|
---|
326 | if (!strnicmp("off",ptr+3,3))
|
---|
327 | {
|
---|
328 | flag=1;
|
---|
329 | }
|
---|
330 | }
|
---|
331 |
|
---|
332 | if (!flag)
|
---|
333 | {
|
---|
334 | dprintf(("Unhandled specifier '%s', please report.\n",ptr));
|
---|
335 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
336 | return FALSE;
|
---|
337 | }
|
---|
338 | ptr=strtok(NULL," ");
|
---|
339 | }
|
---|
340 |
|
---|
341 | if (lpDCB->BaudRate==110)
|
---|
342 | lpDCB->StopBits = 2;
|
---|
343 | return TRUE;
|
---|
344 | }
|
---|
345 |
|
---|
346 | //------------------------------------------------------------------------------
|
---|
347 |
|
---|
348 | BOOL WIN32API BuildCommDCBAndTimeoutsW( LPCWSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts )
|
---|
349 | {
|
---|
350 | char *asciiname;
|
---|
351 | BOOL rc;
|
---|
352 |
|
---|
353 | asciiname = UnicodeToAsciiString((LPWSTR)lpDef);
|
---|
354 | rc = BuildCommDCBAndTimeoutsA(asciiname, lpDCB, lpCommTimeouts);
|
---|
355 | FreeAsciiString(asciiname);
|
---|
356 | return(rc);
|
---|
357 | }
|
---|
358 |
|
---|
359 | //------------------------------------------------------------------------------
|
---|
360 |
|
---|
361 | typedef BOOL (* WIN32API COMMDLGFUNC)(LPCSTR, HWND, LPCOMMCONFIG );
|
---|
362 |
|
---|
363 | BOOL WIN32API CommConfigDialogA( LPCSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC )
|
---|
364 | {
|
---|
365 | COMMDLGFUNC lpfnCommDialog;
|
---|
366 | HMODULE hConfigModule;
|
---|
367 | char szSerialUI[MAX_PATH+1];
|
---|
368 | char szKeyname[5];
|
---|
369 | BOOL r;
|
---|
370 | HKEY hkPorts, hkName;
|
---|
371 | LONG rc;
|
---|
372 | DWORD dwType,dwSize;
|
---|
373 | int port;
|
---|
374 |
|
---|
375 | dprintf(("CommConfigDialogA (%p %x %p)\n",lpszName, hWnd, lpCC));
|
---|
376 |
|
---|
377 | if( strnicmp(lpszName,"com",3) ||
|
---|
378 | strlen(lpszName)<4 ||
|
---|
379 | strlen(lpszName)>7)
|
---|
380 | {
|
---|
381 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
382 | return FALSE;
|
---|
383 | }
|
---|
384 | port = atoi(lpszName+3);
|
---|
385 | if( (0==port) ||(port>9999))
|
---|
386 | {
|
---|
387 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
388 | return FALSE;
|
---|
389 | }
|
---|
390 | port--;
|
---|
391 |
|
---|
392 | sprintf(szKeyname,"%04d",port);
|
---|
393 | dprintf(("CommConfigDialogA look in reg for port %s",szKeyname));
|
---|
394 | rc = RegOpenKeyExA( HKEY_LOCAL_MACHINE,
|
---|
395 | "System\\CurrentControlSet\\Services\\Class\\Ports",
|
---|
396 | 0,
|
---|
397 | KEY_READ,
|
---|
398 | &hkPorts);
|
---|
399 |
|
---|
400 | if(rc!=ERROR_SUCCESS)
|
---|
401 | {
|
---|
402 | SetLastError(ERROR_DEV_NOT_EXIST);
|
---|
403 | return FALSE;
|
---|
404 | }
|
---|
405 |
|
---|
406 | rc = RegOpenKeyExA( hkPorts,
|
---|
407 | szKeyname,
|
---|
408 | 0,
|
---|
409 | KEY_READ,
|
---|
410 | &hkName);
|
---|
411 |
|
---|
412 | if(rc!=ERROR_SUCCESS)
|
---|
413 | {
|
---|
414 | SetLastError(ERROR_DEV_NOT_EXIST);
|
---|
415 | RegCloseKey(hkPorts);
|
---|
416 | return FALSE;
|
---|
417 | }
|
---|
418 |
|
---|
419 | dwSize = sizeof(szSerialUI);
|
---|
420 |
|
---|
421 | rc = RegQueryValueExA( hkName,
|
---|
422 | "ConfigDialog",
|
---|
423 | NULL,
|
---|
424 | &dwType,
|
---|
425 | (LPBYTE)szSerialUI,
|
---|
426 | &dwSize);
|
---|
427 |
|
---|
428 | RegCloseKey(hkName);
|
---|
429 | RegCloseKey(hkPorts);
|
---|
430 | if( (rc!=ERROR_SUCCESS) && (dwType!=REG_SZ) )
|
---|
431 | {
|
---|
432 | SetLastError(ERROR_DEV_NOT_EXIST);
|
---|
433 | return FALSE;
|
---|
434 | }
|
---|
435 |
|
---|
436 | hConfigModule = LoadLibraryA(szSerialUI);
|
---|
437 | if(!hConfigModule)
|
---|
438 | return FALSE;
|
---|
439 |
|
---|
440 | lpfnCommDialog = (COMMDLGFUNC)GetProcAddress(hConfigModule, (LPCSTR)3L);
|
---|
441 |
|
---|
442 | if(!lpfnCommDialog)
|
---|
443 | return FALSE;
|
---|
444 |
|
---|
445 | SetLastError(ERROR_SUCCESS);
|
---|
446 |
|
---|
447 | r = lpfnCommDialog(lpszName,hWnd,lpCC);
|
---|
448 |
|
---|
449 | FreeLibrary(hConfigModule);
|
---|
450 |
|
---|
451 | return r;
|
---|
452 | }
|
---|
453 |
|
---|
454 | //------------------------------------------------------------------------------
|
---|
455 |
|
---|
456 | BOOL WIN32API CommConfigDialogW( LPCWSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC )
|
---|
457 | {
|
---|
458 | char *asciiname;
|
---|
459 | BOOL rc;
|
---|
460 |
|
---|
461 | asciiname = UnicodeToAsciiString((LPWSTR)lpszName);
|
---|
462 | rc = CommConfigDialogA(asciiname,hWnd,lpCC);
|
---|
463 | FreeAsciiString(asciiname);
|
---|
464 | return rc;
|
---|
465 | }
|
---|
466 |
|
---|
467 | /*****************************************************************************
|
---|
468 | * @returns True on success and fills the COMMCONFIG structure
|
---|
469 | * @param lpszName Pointer to devicename
|
---|
470 | * @param lpCC Pointer to COMMCONFIG buffer.
|
---|
471 | * @param lpdwSize [in] Pointer to size of Buffer pointed to by lpCC
|
---|
472 | * [out] Number of bytes copied to the buffer
|
---|
473 | * [error] If buffer to small Number of bytes needed
|
---|
474 | * @remark
|
---|
475 | * @status untested
|
---|
476 | * @author Markus Montkowski
|
---|
477 | *****************************************************************************/
|
---|
478 |
|
---|
479 | ODINFUNCTION3(BOOL,GetDefaultCommConfigA,
|
---|
480 | LPCSTR, lpszName,
|
---|
481 | LPCOMMCONFIG, lpCC,
|
---|
482 | LPDWORD, lpdwSize )
|
---|
483 | {
|
---|
484 | HFILE hCOM;
|
---|
485 | BOOL rc;
|
---|
486 |
|
---|
487 | dprintf(("GetDefaultCommConfigA untested stub \n"));
|
---|
488 | SetLastError(ERROR_SUCCESS);
|
---|
489 |
|
---|
490 | if(IsBadReadPtr(lpszName,5) ||
|
---|
491 | IsBadWritePtr(lpdwSize,sizeof(DWORD)) ||
|
---|
492 | IsBadWritePtr(lpCC,*lpdwSize) )
|
---|
493 | {
|
---|
494 | SetLastError(ERROR_INVALID_PARAMETER); /* set win32 error information */
|
---|
495 | return(FALSE);
|
---|
496 | }
|
---|
497 |
|
---|
498 | if(strnicmp(lpszName,"COM",3) &&
|
---|
499 | strnicmp(lpszName,"\\COM",4) &&
|
---|
500 | strnicmp(lpszName,"\\dev\\COM",8) )
|
---|
501 | {
|
---|
502 | SetLastError(ERROR_FILE_NOT_FOUND); /* set win32 error information */
|
---|
503 | return(FALSE);
|
---|
504 | }
|
---|
505 |
|
---|
506 | hCOM = HMCreateFile( lpszName,
|
---|
507 | GENERIC_READ | GENERIC_WRITE,
|
---|
508 | 0,
|
---|
509 | NULL,
|
---|
510 | OPEN_EXISTING,
|
---|
511 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
---|
512 | NULL);
|
---|
513 | if(0!=hCOM)
|
---|
514 | {
|
---|
515 | rc = HMCommGetDefaultCommConfig(hCOM, lpCC, lpdwSize);
|
---|
516 | HMCloseHandle(hCOM);
|
---|
517 | return(rc);
|
---|
518 | }
|
---|
519 | return(FALSE);
|
---|
520 | }
|
---|
521 |
|
---|
522 | //------------------------------------------------------------------------------
|
---|
523 |
|
---|
524 | BOOL WIN32API GetDefaultCommConfigW( LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize )
|
---|
525 | {
|
---|
526 | char *asciiname;
|
---|
527 | BOOL rc;
|
---|
528 |
|
---|
529 | asciiname = UnicodeToAsciiString((LPWSTR)lpszName);
|
---|
530 | rc = GetDefaultCommConfigA(asciiname, lpCC, lpdwSize);
|
---|
531 | FreeAsciiString(asciiname);
|
---|
532 | return(rc);
|
---|
533 | }
|
---|
534 |
|
---|
535 | /*****************************************************************************
|
---|
536 | * @returns True on Success
|
---|
537 | * @param lpszName Pointer to devicename
|
---|
538 | * @param lpCC Pointer to COMMCONFIG buffer.
|
---|
539 | * @param dwSize Size of Buffer pointed to by lpCC
|
---|
540 | * @remark
|
---|
541 | * @status untested
|
---|
542 | * @author Markus Montkowski
|
---|
543 | *****************************************************************************/
|
---|
544 |
|
---|
545 | ODINFUNCTION3(BOOL, SetDefaultCommConfigA,
|
---|
546 | LPCSTR, lpszName,
|
---|
547 | LPCOMMCONFIG, lpCC,
|
---|
548 | DWORD, dwSize )
|
---|
549 | {
|
---|
550 | HFILE hCOM;
|
---|
551 | BOOL rc;
|
---|
552 |
|
---|
553 | dprintf(("SetDefaultCommConfigA untested stub \n"));
|
---|
554 | SetLastError(ERROR_INVALID_PARAMETER); /* set win32 error information */
|
---|
555 | rc = FALSE;
|
---|
556 |
|
---|
557 | if(!IsBadReadPtr(lpszName,5) &&
|
---|
558 | !IsBadWritePtr(lpCC,dwSize)&&
|
---|
559 | lpCC->dwSize== dwSize )
|
---|
560 | {
|
---|
561 | switch(lpCC->dwProviderSubType)
|
---|
562 | {
|
---|
563 | case PST_RS232:
|
---|
564 | if(strnicmp(lpszName,"COM",3) &&
|
---|
565 | strnicmp(lpszName,"\\COM",4) &&
|
---|
566 | strnicmp(lpszName,"\\dev\\COM",8) )
|
---|
567 | {
|
---|
568 | SetLastError(ERROR_FILE_NOT_FOUND); /* set win32 error information */
|
---|
569 | return(FALSE);
|
---|
570 | }
|
---|
571 |
|
---|
572 | SetLastError(ERROR_SUCCESS);
|
---|
573 |
|
---|
574 | hCOM = HMCreateFile( lpszName,
|
---|
575 | GENERIC_READ | GENERIC_WRITE,
|
---|
576 | 0,
|
---|
577 | NULL,
|
---|
578 | OPEN_EXISTING,
|
---|
579 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
---|
580 | NULL);
|
---|
581 | if(0!=hCOM)
|
---|
582 | {
|
---|
583 | rc = HMCommSetDefaultCommConfig(hCOM, lpCC, dwSize);
|
---|
584 | HMCloseHandle(hCOM);
|
---|
585 | return(rc);
|
---|
586 | }
|
---|
587 | break;
|
---|
588 | case PST_PARALLELPORT:
|
---|
589 | case PST_MODEM:
|
---|
590 | default:
|
---|
591 | SetLastError(ERROR_FILE_NOT_FOUND);
|
---|
592 | dprintf(("SetDefaultCommConfigA: ProviderSubType &d Not implemented (FALSE)\n",lpCC->dwProviderSubType));
|
---|
593 | break;
|
---|
594 | }
|
---|
595 | }
|
---|
596 | return(rc);
|
---|
597 | }
|
---|
598 |
|
---|
599 | //------------------------------------------------------------------------------
|
---|
600 |
|
---|
601 | BOOL WIN32API SetDefaultCommConfigW( LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize )
|
---|
602 | {
|
---|
603 | char *asciiname;
|
---|
604 | BOOL rc;
|
---|
605 |
|
---|
606 | asciiname = UnicodeToAsciiString((LPWSTR)lpszName);
|
---|
607 | rc = SetDefaultCommConfigA(asciiname, lpCC, dwSize);
|
---|
608 | FreeAsciiString(asciiname);
|
---|
609 | return(rc);
|
---|
610 | }
|
---|
611 |
|
---|
612 | /*****************************************************************************
|
---|
613 | * @returns
|
---|
614 | * @param hFile Comport handle
|
---|
615 | * @remark
|
---|
616 | * @status untested
|
---|
617 | * @author Markus Montkowski
|
---|
618 | *****************************************************************************/
|
---|
619 |
|
---|
620 | ODINFUNCTION1(BOOL, ClearCommBreak, HANDLE, hFile )
|
---|
621 | {
|
---|
622 | return HMCommClearCommBreak(hFile);
|
---|
623 | }
|
---|
624 |
|
---|
625 | /*****************************************************************************
|
---|
626 | * @returns
|
---|
627 | * @param hFile Comport handle
|
---|
628 | * @param dwInQueue recommended internal buffer size in bytes
|
---|
629 | * @param dwOutQueue recommended internal buffer size in bytes
|
---|
630 | * @remark
|
---|
631 | * @status untested
|
---|
632 | * @author Markus Montkowski
|
---|
633 | *****************************************************************************/
|
---|
634 |
|
---|
635 | ODINFUNCTION3(BOOL, SetupComm,
|
---|
636 | HANDLE, hFile,
|
---|
637 | DWORD, dwInQueue,
|
---|
638 | DWORD, dwOutQueue )
|
---|
639 | {
|
---|
640 | return HMCommSetupComm(hFile, dwInQueue, dwOutQueue);
|
---|
641 | }
|
---|
642 |
|
---|
643 | /*****************************************************************************
|
---|
644 | * @returns
|
---|
645 | * @param hFile Comport handle
|
---|
646 | * @param dwFunc extended function to perform
|
---|
647 | * @remark
|
---|
648 | * @status untested
|
---|
649 | * @author Markus Montkowski
|
---|
650 | *****************************************************************************/
|
---|
651 |
|
---|
652 | ODINFUNCTION2 (BOOL, EscapeCommFunction,
|
---|
653 | HANDLE, hFile,
|
---|
654 | UINT, dwFunc )
|
---|
655 | {
|
---|
656 | return HMCommEscapeCommFunction(hFile, dwFunc);
|
---|
657 | }
|
---|
658 |
|
---|
659 | //------------------------------------------------------------------------------
|
---|
660 |
|
---|
661 | BOOL WIN32API GetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, LPDWORD lpdwSize )
|
---|
662 | {
|
---|
663 | return HMCommGetCommConfig(hCommDev,lpCC, lpdwSize);
|
---|
664 | }
|
---|
665 |
|
---|
666 | //------------------------------------------------------------------------------
|
---|
667 |
|
---|
668 | BOOL WIN32API GetCommModemStatus( HANDLE hFile, LPDWORD lpModemStat )
|
---|
669 | {
|
---|
670 | return HMCommGetCommModemStatus(hFile,lpModemStat);
|
---|
671 | }
|
---|
672 |
|
---|
673 | //------------------------------------------------------------------------------
|
---|
674 |
|
---|
675 | BOOL WIN32API SetCommBreak( HANDLE hFile )
|
---|
676 | {
|
---|
677 | return HMCommSetCommBreak(hFile);
|
---|
678 | }
|
---|
679 |
|
---|
680 | //------------------------------------------------------------------------------
|
---|
681 |
|
---|
682 | BOOL WIN32API SetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, DWORD dwSize )
|
---|
683 | {
|
---|
684 | return HMCommSetCommConfig(hCommDev,lpCC, dwSize);
|
---|
685 | }
|
---|
686 |
|
---|
687 | //------------------------------------------------------------------------------
|
---|
688 |
|
---|
689 | BOOL WIN32API TransmitCommChar( HANDLE hFile, CHAR cChar )
|
---|
690 | {
|
---|
691 | return HMCommTransmitCommChar(hFile,cChar);
|
---|
692 | }
|
---|
693 |
|
---|
694 | //------------------------------------------------------------------------------
|
---|
695 |
|
---|
696 | BOOL WIN32API SetCommTimeouts( HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo)
|
---|
697 | {
|
---|
698 | return HMCommSetCommTimeouts(hCommDev, lpctmo);
|
---|
699 | }
|
---|
700 |
|
---|
701 | //------------------------------------------------------------------------------
|
---|
702 |
|
---|
703 | BOOL WIN32API GetCommTimeouts(HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo)
|
---|
704 | {
|
---|
705 | return HMCommGetCommTimeouts(hCommDev, lpctmo);
|
---|
706 | }
|
---|
707 |
|
---|
708 | //------------------------------------------------------------------------------
|
---|
709 |
|
---|
710 | BOOL WIN32API GetCommState(HANDLE hCommDev, LPDCB lpDCB)
|
---|
711 | {
|
---|
712 | return HMCommGetCommState(hCommDev, lpDCB);
|
---|
713 | }
|
---|
714 |
|
---|
715 | //------------------------------------------------------------------------------
|
---|
716 |
|
---|
717 | BOOL WIN32API SetCommState(HANDLE hCommDev, LPDCB lpDCB)
|
---|
718 | {
|
---|
719 | return HMCommSetCommState(hCommDev, lpDCB);
|
---|
720 | }
|
---|
721 |
|
---|
722 | //------------------------------------------------------------------------------
|
---|
723 |
|
---|
724 | BOOL WIN32API ClearCommError(HANDLE hCommDev, LPDWORD lpdwErrors, LPCOMSTAT lpcst)
|
---|
725 | {
|
---|
726 | return HMCommClearCommError(hCommDev, lpdwErrors, lpcst);
|
---|
727 | }
|
---|
728 |
|
---|
729 | //------------------------------------------------------------------------------
|
---|
730 |
|
---|
731 | BOOL WIN32API PurgeComm(HANDLE hCommDev, DWORD fdwAction)
|
---|
732 | {
|
---|
733 | return HMCommPurgeComm(hCommDev,fdwAction);
|
---|
734 | }
|
---|
735 |
|
---|
736 | //------------------------------------------------------------------------------
|
---|
737 |
|
---|
738 | BOOL WIN32API SetCommMask(HANDLE hCommDev, DWORD fdwEvtMask)
|
---|
739 | {
|
---|
740 | return HMCommSetCommMask( hCommDev,fdwEvtMask);
|
---|
741 | }
|
---|
742 |
|
---|
743 | //------------------------------------------------------------------------------
|
---|
744 |
|
---|
745 | BOOL WIN32API GetCommMask(HANDLE hCommDev, LPDWORD lpfdwEvtMask)
|
---|
746 | {
|
---|
747 | return HMCommGetCommMask( hCommDev,lpfdwEvtMask);
|
---|
748 | }
|
---|
749 |
|
---|
750 | //------------------------------------------------------------------------------
|
---|
751 |
|
---|
752 | BOOL WIN32API GetCommProperties(HANDLE hCommDev, LPCOMMPROP lpcmmp)
|
---|
753 | {
|
---|
754 | return HMCommGetCommProperties(hCommDev, lpcmmp);
|
---|
755 | }
|
---|
756 |
|
---|
757 | //------------------------------------------------------------------------------
|
---|
758 |
|
---|
759 | BOOL WIN32API WaitCommEvent( HANDLE hCommDev,
|
---|
760 | LPDWORD lpfdwEvtMask,
|
---|
761 | LPOVERLAPPED lpo)
|
---|
762 | {
|
---|
763 | return HMCommWaitCommEvent(hCommDev, lpfdwEvtMask, lpo);
|
---|
764 | }
|
---|
765 |
|
---|
766 | //------------------------------------------------------------------------------
|
---|
767 |
|
---|