]> sigrok.org Git - libserialport.git/commitdiff
On Windows, prefix port names with '\\.\' to work with ports above COM9.
authorMartin Ling <redacted>
Mon, 4 Nov 2013 13:08:09 +0000 (13:08 +0000)
committerUwe Hermann <redacted>
Thu, 14 Nov 2013 23:42:39 +0000 (00:42 +0100)
README
serialport.c

diff --git a/README b/README
index 6e3b480129b683e36104bf03609de245fc056eab..fefbef23ffd15c6ba3ab52005058b8bfb9f27c39 100644 (file)
--- a/README
+++ b/README
@@ -131,8 +131,8 @@ int sp_open(struct sp_port *port, int flags);
   flags:     Flags to use when opening the serial port. Possible
              flags are: SP_MODE_RDWR, SP_MODE_RDONLY, and SP_MODE_NONBLOCK.
 
- Returns: SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
-          if an invalid port is passed.
+ Returns: SP_OK on success, SP_ERR_FAIL on failure, SP_ERR_MEM on allocation
+          failure, or SP_ERR_ARG if an invalid port is passed.
 
 int sp_close(struct sp_port *port);
 
index ddddb518be2b1b4b9cb38d0fd1ca178bb48a5400..c891006ea19a622bc27d1794f8207ea142bd5c75 100644 (file)
@@ -343,6 +343,13 @@ int sp_open(struct sp_port *port, int flags)
 
 #ifdef _WIN32
        DWORD desired_access = 0, flags_and_attributes = 0;
+       char *escaped_port_name;
+
+       /* Prefix port name with '\\.\' to work with ports above COM9. */
+       if (!(escaped_port_name = malloc(strlen(port->name + 5))))
+               return SP_ERR_MEM;
+       sprintf(escaped_port_name, "\\\\.\\%s", port->name);
+
        /* Map 'flags' to the OS-specific settings. */
        desired_access |= GENERIC_READ;
        flags_and_attributes = FILE_ATTRIBUTE_NORMAL;
@@ -351,8 +358,11 @@ int sp_open(struct sp_port *port, int flags)
        if (flags & SP_MODE_NONBLOCK)
                flags_and_attributes |= FILE_FLAG_OVERLAPPED;
 
-       port->hdl = CreateFile(port->name, desired_access, 0, 0,
+       port->hdl = CreateFile(escaped_port_name, desired_access, 0, 0,
                         OPEN_EXISTING, flags_and_attributes, 0);
+
+       free(escaped_port_name);
+
        if (port->hdl == INVALID_HANDLE_VALUE)
                return SP_ERR_FAIL;
 #else