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);
#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;
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