Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMPort::open should prepend port name with \\?\ #18

Closed
niconii opened this issue May 5, 2016 · 4 comments
Closed

COMPort::open should prepend port name with \\?\ #18

niconii opened this issue May 5, 2016 · 4 comments

Comments

@niconii
Copy link

niconii commented May 5, 2016

At the moment, COMPort::open only works for COM1-COM9 unless \\?\ is prepended to the string, because the filenames COM1-COM9 are handled specially by the Win32 subsystem, whereas others aren't, causing COMPort::open to attempt to open a file instead.

In contrast, a path like \\?\COM10 specifies a verbatim path, which will work with any COM port.

@dcuddeback
Copy link
Owner

@niconii Interesting. I didn't know this about Windows. I'll have to find a way to get 10 COM ports installed on Windows so that I can reproduce this.

@niconii
Copy link
Author

niconii commented May 12, 2016

I personally ran into this when using com0com, which is a driver that can create pairs of virtual COM ports. The newest version (3.0.0.0) isn't signed, thus it doesn't work easily on newer versions of Windows, but there is an older version (2.2.2.0) which is signed.

By default, it creates pairs of ports with names like CNCA0 and CNCB0, CNCA1 and CNCB1, and so on. Since these names don't start with COM at all, they fail to work without a \\?\ prefix. When looking into it, I found out that the same is true of ports that do start with COM, yet don't fall within the COM1-COM9 range.

@dcuddeback
Copy link
Owner

@niconii Thank you. I was able to reproduce it using com0com. I'm pushing up a fix that will go into the next release. I found this documentation on MSDN useful (https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx):

For example, if you want to open the system's serial communications port 1, you can use "COM1" in the call to the CreateFile function. This works because COM1–COM9 are part of the reserved names in the NT namespace, although using the "\." prefix will also work with these device names. By comparison, if you have a 100 port serial expansion board installed and want to open COM56, you cannot open it using "COM56" because there is no predefined NT namespace for COM56. You will need to open it using "\.\COM56" because "\." goes directly to the device namespace without attempting to locate a predefined alias.

@niconii
Copy link
Author

niconii commented May 13, 2016

Alright. AFAIK it shouldn't matter whether \\?\ or \\.\ is used (the difference has something to do with path canonicalization which shouldn't be relevant for this), but yeah, you might as well use the one Microsoft recommends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants