| 1 | /* $Id: comm.cpp,v 1.9 2002-02-09 12:45:11 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 | BOOL WIN32API GetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC,
|
|---|
| 480 | LPDWORD lpdwSize)
|
|---|
| 481 | {
|
|---|
| 482 | HFILE hCOM;
|
|---|
| 483 | BOOL rc;
|
|---|
| 484 |
|
|---|
| 485 | dprintf(("GetDefaultCommConfigA untested stub \n"));
|
|---|
| 486 | SetLastError(ERROR_SUCCESS);
|
|---|
| 487 |
|
|---|
| 488 | if(IsBadReadPtr(lpszName,5) ||
|
|---|
| 489 | IsBadWritePtr(lpdwSize,sizeof(DWORD)) ||
|
|---|
| 490 | IsBadWritePtr(lpCC,*lpdwSize) )
|
|---|
| 491 | {
|
|---|
| 492 | SetLastError(ERROR_INVALID_PARAMETER); /* set win32 error information */
|
|---|
| 493 | return(FALSE);
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | if(strnicmp(lpszName,"COM",3) &&
|
|---|
| 497 | strnicmp(lpszName,"\\COM",4) &&
|
|---|
| 498 | strnicmp(lpszName,"\\dev\\COM",8) )
|
|---|
| 499 | {
|
|---|
| 500 | SetLastError(ERROR_FILE_NOT_FOUND); /* set win32 error information */
|
|---|
| 501 | return(FALSE);
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| 504 | hCOM = HMCreateFile( lpszName,
|
|---|
| 505 | GENERIC_READ | GENERIC_WRITE,
|
|---|
| 506 | 0,
|
|---|
| 507 | NULL,
|
|---|
| 508 | OPEN_EXISTING,
|
|---|
| 509 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
|---|
| 510 | NULL);
|
|---|
| 511 | if(0!=hCOM)
|
|---|
| 512 | {
|
|---|
| 513 | rc = HMCommGetDefaultCommConfig(hCOM, lpCC, lpdwSize);
|
|---|
| 514 | HMCloseHandle(hCOM);
|
|---|
| 515 | return(rc);
|
|---|
| 516 | }
|
|---|
| 517 | return(FALSE);
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | //------------------------------------------------------------------------------
|
|---|
| 521 |
|
|---|
| 522 | BOOL WIN32API GetDefaultCommConfigW( LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize )
|
|---|
| 523 | {
|
|---|
| 524 | char *asciiname;
|
|---|
| 525 | BOOL rc;
|
|---|
| 526 |
|
|---|
| 527 | asciiname = UnicodeToAsciiString((LPWSTR)lpszName);
|
|---|
| 528 | rc = GetDefaultCommConfigA(asciiname, lpCC, lpdwSize);
|
|---|
| 529 | FreeAsciiString(asciiname);
|
|---|
| 530 | return(rc);
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|
| 533 | /*****************************************************************************
|
|---|
| 534 | * @returns True on Success
|
|---|
| 535 | * @param lpszName Pointer to devicename
|
|---|
| 536 | * @param lpCC Pointer to COMMCONFIG buffer.
|
|---|
| 537 | * @param dwSize Size of Buffer pointed to by lpCC
|
|---|
| 538 | * @remark
|
|---|
| 539 | * @status untested
|
|---|
| 540 | * @author Markus Montkowski
|
|---|
| 541 | *****************************************************************************/
|
|---|
| 542 |
|
|---|
| 543 | BOOL SetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize )
|
|---|
| 544 | {
|
|---|
| 545 | HFILE hCOM;
|
|---|
| 546 | BOOL rc;
|
|---|
| 547 |
|
|---|
| 548 | dprintf(("SetDefaultCommConfigA untested stub \n"));
|
|---|
| 549 | SetLastError(ERROR_INVALID_PARAMETER); /* set win32 error information */
|
|---|
| 550 | rc = FALSE;
|
|---|
| 551 |
|
|---|
| 552 | if(!IsBadReadPtr(lpszName,5) &&
|
|---|
| 553 | !IsBadWritePtr(lpCC,dwSize)&&
|
|---|
| 554 | lpCC->dwSize== dwSize )
|
|---|
| 555 | {
|
|---|
| 556 | switch(lpCC->dwProviderSubType)
|
|---|
| 557 | {
|
|---|
| 558 | case PST_RS232:
|
|---|
| 559 | if(strnicmp(lpszName,"COM",3) &&
|
|---|
| 560 | strnicmp(lpszName,"\\COM",4) &&
|
|---|
| 561 | strnicmp(lpszName,"\\dev\\COM",8) )
|
|---|
| 562 | {
|
|---|
| 563 | SetLastError(ERROR_FILE_NOT_FOUND); /* set win32 error information */
|
|---|
| 564 | return(FALSE);
|
|---|
| 565 | }
|
|---|
| 566 |
|
|---|
| 567 | SetLastError(ERROR_SUCCESS);
|
|---|
| 568 |
|
|---|
| 569 | hCOM = HMCreateFile( lpszName,
|
|---|
| 570 | GENERIC_READ | GENERIC_WRITE,
|
|---|
| 571 | 0,
|
|---|
| 572 | NULL,
|
|---|
| 573 | OPEN_EXISTING,
|
|---|
| 574 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
|
|---|
| 575 | NULL);
|
|---|
| 576 | if(0!=hCOM)
|
|---|
| 577 | {
|
|---|
| 578 | rc = HMCommSetDefaultCommConfig(hCOM, lpCC, dwSize);
|
|---|
| 579 | HMCloseHandle(hCOM);
|
|---|
| 580 | return(rc);
|
|---|
| 581 | }
|
|---|
| 582 | break;
|
|---|
| 583 | case PST_PARALLELPORT:
|
|---|
| 584 | case PST_MODEM:
|
|---|
| 585 | default:
|
|---|
| 586 | SetLastError(ERROR_FILE_NOT_FOUND);
|
|---|
| 587 | dprintf(("SetDefaultCommConfigA: ProviderSubType &d Not implemented (FALSE)\n",lpCC->dwProviderSubType));
|
|---|
| 588 | break;
|
|---|
| 589 | }
|
|---|
| 590 | }
|
|---|
| 591 | return(rc);
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | //------------------------------------------------------------------------------
|
|---|
| 595 |
|
|---|
| 596 | BOOL WIN32API SetDefaultCommConfigW( LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize )
|
|---|
| 597 | {
|
|---|
| 598 | char *asciiname;
|
|---|
| 599 | BOOL rc;
|
|---|
| 600 |
|
|---|
| 601 | asciiname = UnicodeToAsciiString((LPWSTR)lpszName);
|
|---|
| 602 | rc = SetDefaultCommConfigA(asciiname, lpCC, dwSize);
|
|---|
| 603 | FreeAsciiString(asciiname);
|
|---|
| 604 | return(rc);
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | /*****************************************************************************
|
|---|
| 608 | * @returns
|
|---|
| 609 | * @param hFile Comport handle
|
|---|
| 610 | * @remark
|
|---|
| 611 | * @status untested
|
|---|
| 612 | * @author Markus Montkowski
|
|---|
| 613 | *****************************************************************************/
|
|---|
| 614 |
|
|---|
| 615 | BOOL WIN32API ClearCommBreak(HANDLE hFile )
|
|---|
| 616 | {
|
|---|
| 617 | return HMCommClearCommBreak(hFile);
|
|---|
| 618 | }
|
|---|
| 619 |
|
|---|
| 620 | /*****************************************************************************
|
|---|
| 621 | * @returns
|
|---|
| 622 | * @param hFile Comport handle
|
|---|
| 623 | * @param dwInQueue recommended internal buffer size in bytes
|
|---|
| 624 | * @param dwOutQueue recommended internal buffer size in bytes
|
|---|
| 625 | * @remark
|
|---|
| 626 | * @status untested
|
|---|
| 627 | * @author Markus Montkowski
|
|---|
| 628 | *****************************************************************************/
|
|---|
| 629 |
|
|---|
| 630 | BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue )
|
|---|
| 631 | {
|
|---|
| 632 | return HMCommSetupComm(hFile, dwInQueue, dwOutQueue);
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | /*****************************************************************************
|
|---|
| 636 | * @returns
|
|---|
| 637 | * @param hFile Comport handle
|
|---|
| 638 | * @param dwFunc extended function to perform
|
|---|
| 639 | * @remark
|
|---|
| 640 | * @status untested
|
|---|
| 641 | * @author Markus Montkowski
|
|---|
| 642 | *****************************************************************************/
|
|---|
| 643 |
|
|---|
| 644 | BOOL WIN32API EscapeCommFunction(HANDLE hFile, UINT dwFunc )
|
|---|
| 645 | {
|
|---|
| 646 | return HMCommEscapeCommFunction(hFile, dwFunc);
|
|---|
| 647 | }
|
|---|
| 648 |
|
|---|
| 649 | //------------------------------------------------------------------------------
|
|---|
| 650 |
|
|---|
| 651 | BOOL WIN32API GetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, LPDWORD lpdwSize )
|
|---|
| 652 | {
|
|---|
| 653 | return HMCommGetCommConfig(hCommDev,lpCC, lpdwSize);
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | //------------------------------------------------------------------------------
|
|---|
| 657 |
|
|---|
| 658 | BOOL WIN32API GetCommModemStatus( HANDLE hFile, LPDWORD lpModemStat )
|
|---|
| 659 | {
|
|---|
| 660 | return HMCommGetCommModemStatus(hFile,lpModemStat);
|
|---|
| 661 | }
|
|---|
| 662 |
|
|---|
| 663 | //------------------------------------------------------------------------------
|
|---|
| 664 |
|
|---|
| 665 | BOOL WIN32API SetCommBreak( HANDLE hFile )
|
|---|
| 666 | {
|
|---|
| 667 | return HMCommSetCommBreak(hFile);
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|
| 670 | //------------------------------------------------------------------------------
|
|---|
| 671 |
|
|---|
| 672 | BOOL WIN32API SetCommConfig( HANDLE hCommDev, LPCOMMCONFIG lpCC, DWORD dwSize )
|
|---|
| 673 | {
|
|---|
| 674 | return HMCommSetCommConfig(hCommDev,lpCC, dwSize);
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | //------------------------------------------------------------------------------
|
|---|
| 678 |
|
|---|
| 679 | BOOL WIN32API TransmitCommChar( HANDLE hFile, CHAR cChar )
|
|---|
| 680 | {
|
|---|
| 681 | return HMCommTransmitCommChar(hFile,cChar);
|
|---|
| 682 | }
|
|---|
| 683 |
|
|---|
| 684 | //------------------------------------------------------------------------------
|
|---|
| 685 |
|
|---|
| 686 | BOOL WIN32API SetCommTimeouts( HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo)
|
|---|
| 687 | {
|
|---|
| 688 | return HMCommSetCommTimeouts(hCommDev, lpctmo);
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 | //------------------------------------------------------------------------------
|
|---|
| 692 |
|
|---|
| 693 | BOOL WIN32API GetCommTimeouts(HANDLE hCommDev, LPCOMMTIMEOUTS lpctmo)
|
|---|
| 694 | {
|
|---|
| 695 | return HMCommGetCommTimeouts(hCommDev, lpctmo);
|
|---|
| 696 | }
|
|---|
| 697 |
|
|---|
| 698 | //------------------------------------------------------------------------------
|
|---|
| 699 |
|
|---|
| 700 | BOOL WIN32API GetCommState(HANDLE hCommDev, LPDCB lpDCB)
|
|---|
| 701 | {
|
|---|
| 702 | return HMCommGetCommState(hCommDev, lpDCB);
|
|---|
| 703 | }
|
|---|
| 704 |
|
|---|
| 705 | //------------------------------------------------------------------------------
|
|---|
| 706 |
|
|---|
| 707 | BOOL WIN32API SetCommState(HANDLE hCommDev, LPDCB lpDCB)
|
|---|
| 708 | {
|
|---|
| 709 | return HMCommSetCommState(hCommDev, lpDCB);
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | //------------------------------------------------------------------------------
|
|---|
| 713 |
|
|---|
| 714 | BOOL WIN32API ClearCommError(HANDLE hCommDev, LPDWORD lpdwErrors, LPCOMSTAT lpcst)
|
|---|
| 715 | {
|
|---|
| 716 | return HMCommClearCommError(hCommDev, lpdwErrors, lpcst);
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | //------------------------------------------------------------------------------
|
|---|
| 720 |
|
|---|
| 721 | BOOL WIN32API PurgeComm(HANDLE hCommDev, DWORD fdwAction)
|
|---|
| 722 | {
|
|---|
| 723 | return HMCommPurgeComm(hCommDev,fdwAction);
|
|---|
| 724 | }
|
|---|
| 725 |
|
|---|
| 726 | //------------------------------------------------------------------------------
|
|---|
| 727 |
|
|---|
| 728 | BOOL WIN32API SetCommMask(HANDLE hCommDev, DWORD fdwEvtMask)
|
|---|
| 729 | {
|
|---|
| 730 | return HMCommSetCommMask( hCommDev,fdwEvtMask);
|
|---|
| 731 | }
|
|---|
| 732 |
|
|---|
| 733 | //------------------------------------------------------------------------------
|
|---|
| 734 |
|
|---|
| 735 | BOOL WIN32API GetCommMask(HANDLE hCommDev, LPDWORD lpfdwEvtMask)
|
|---|
| 736 | {
|
|---|
| 737 | return HMCommGetCommMask( hCommDev,lpfdwEvtMask);
|
|---|
| 738 | }
|
|---|
| 739 |
|
|---|
| 740 | //------------------------------------------------------------------------------
|
|---|
| 741 |
|
|---|
| 742 | BOOL WIN32API GetCommProperties(HANDLE hCommDev, LPCOMMPROP lpcmmp)
|
|---|
| 743 | {
|
|---|
| 744 | return HMCommGetCommProperties(hCommDev, lpcmmp);
|
|---|
| 745 | }
|
|---|
| 746 |
|
|---|
| 747 | //------------------------------------------------------------------------------
|
|---|
| 748 |
|
|---|
| 749 | BOOL WIN32API WaitCommEvent( HANDLE hCommDev,
|
|---|
| 750 | LPDWORD lpfdwEvtMask,
|
|---|
| 751 | LPOVERLAPPED lpo)
|
|---|
| 752 | {
|
|---|
| 753 | return HMCommWaitCommEvent(hCommDev, lpfdwEvtMask, lpo);
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | //------------------------------------------------------------------------------
|
|---|
| 757 |
|
|---|