serial: Support COM ports > COM9 on Windows

COM ports greater than COM9 on Windows can only be opened using
the DOS device UNC path \\.\.

Prefix the filename passed to CreateFile() with this prefix to
address this issue.
This commit is contained in:
Howard M. Harte 2021-12-17 15:06:41 -08:00
parent 121b0323a6
commit d8d324ded6

View file

@ -582,6 +582,7 @@ COMMCONFIG commdefault;
DWORD error;
DWORD commsize = sizeof (commdefault);
COMMTIMEOUTS cto;
char dosname[1028];
if (!GetDefaultCommConfig (name, &commdefault, &commsize)) { /* get default comm parameters */
error = GetLastError (); /* function failed; get error */
@ -592,7 +593,10 @@ if (!GetDefaultCommConfig (name, &commdefault, &commsize)) { /* get default c
return INVALID_HANDLE; /* indicate bad port name */
}
hPort = CreateFile (name, GENERIC_READ | GENERIC_WRITE, /* open the port */
strncpy(dosname, "\\\\.\\", 4);
strncat(dosname, name, sizeof(dosname));
hPort = CreateFile (dosname, GENERIC_READ | GENERIC_WRITE, /* open the port */
0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (hPort == INVALID_HANDLE_VALUE) { /* open failed? */