From 922d1e5465b8e6fd4514600be9e8fc7f06147812 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Thu, 2 Jul 2009 10:23:57 +0000 Subject: [PATCH] bug #22234: WINDOWS version: HOWTO: Specify Serial Ports Larger than COM9 * ser_win32.c (ser_open): prepend \\.\ to any COM port name, so it is safe to be used for COM ports above 9. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@825 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 6 ++++++ ser_win32.c | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d0bcf4a7..285983e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-07-02 Joerg Wunsch + + bug #22234: WINDOWS version: HOWTO: Specify Serial Ports Larger than COM9 + * ser_win32.c (ser_open): prepend \\.\ to any COM port name, so it is + safe to be used for COM ports above 9. + 2009-07-02 Joerg Wunsch bug #26408: Crash in stk500v2_open() diff --git a/ser_win32.c b/ser_win32.c index aa4cc34c..ed8eb29d 100644 --- a/ser_win32.c +++ b/ser_win32.c @@ -110,6 +110,7 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp) { LPVOID lpMsgBuf; HANDLE hComPort=INVALID_HANDLE_VALUE; + char *newname = 0; /* * If the port is of the form "net::", then @@ -125,10 +126,22 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp) exit(1); } - /* if (hComPort!=INVALID_HANDLE_VALUE) - fprintf(stderr, "%s: ser_open(): \"%s\" is already open\n", - progname, port); - */ + if (strncasecmp(port, "com", strlen("com")) == 0) { + + // prepend "\\\\.\\" to name, required for port # >= 10 + newname = malloc(strlen("\\\\.\\") + strlen(port) + 1); + + if (newname == 0) { + fprintf(stderr, + "%s: ser_open(): out of memory\n", + progname); + exit(1); + } + strcpy(newname, "\\\\.\\"); + strcat(newname, port); + + port = newname; + } hComPort = CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); @@ -174,6 +187,10 @@ static void ser_open(char * port, long baud, union filedescriptor *fdp) progname, port); exit(1); } + + if (newname != 0) { + free(newname); + } }