1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

On Windows, prefix port names with '\\.\' to work with ports above COM9.

This commit is contained in:
Martin Ling 2013-11-04 13:08:09 +00:00 committed by Uwe Hermann
parent f6a1fb65ea
commit 99945a1fb5
2 changed files with 13 additions and 3 deletions

4
README
View File

@ -131,8 +131,8 @@ int sp_open(struct sp_port *port, int flags);
flags: Flags to use when opening the serial port. Possible flags: Flags to use when opening the serial port. Possible
flags are: SP_MODE_RDWR, SP_MODE_RDONLY, and SP_MODE_NONBLOCK. 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 Returns: SP_OK on success, SP_ERR_FAIL on failure, SP_ERR_MEM on allocation
if an invalid port is passed. failure, or SP_ERR_ARG if an invalid port is passed.
int sp_close(struct sp_port *port); int sp_close(struct sp_port *port);

View File

@ -343,6 +343,13 @@ int sp_open(struct sp_port *port, int flags)
#ifdef _WIN32 #ifdef _WIN32
DWORD desired_access = 0, flags_and_attributes = 0; 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. */ /* Map 'flags' to the OS-specific settings. */
desired_access |= GENERIC_READ; desired_access |= GENERIC_READ;
flags_and_attributes = FILE_ATTRIBUTE_NORMAL; flags_and_attributes = FILE_ATTRIBUTE_NORMAL;
@ -351,8 +358,11 @@ int sp_open(struct sp_port *port, int flags)
if (flags & SP_MODE_NONBLOCK) if (flags & SP_MODE_NONBLOCK)
flags_and_attributes |= FILE_FLAG_OVERLAPPED; 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); OPEN_EXISTING, flags_and_attributes, 0);
free(escaped_port_name);
if (port->hdl == INVALID_HANDLE_VALUE) if (port->hdl == INVALID_HANDLE_VALUE)
return SP_ERR_FAIL; return SP_ERR_FAIL;
#else #else