From d8d324ded63cc6c84ff47b5b15c4bc5166851167 Mon Sep 17 00:00:00 2001 From: "Howard M. Harte" Date: Fri, 17 Dec 2021 15:06:41 -0800 Subject: [PATCH] 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. --- sim_serial.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sim_serial.c b/sim_serial.c index 74bdfb32..883f855b 100644 --- a/sim_serial.c +++ b/sim_serial.c @@ -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? */