Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey everyone.

I've problem with serial port.

I've written a program that can read ports COM1 to COM9, but can open COMXX(like com10, com11, etc.)

I've searched and learnt that tCOM1–COM9 are part of the reserved names in the NT namespaces.
it says that "To acces files like COMXX you need to write "\\.\COMXX".

I've tried this, but didn't make it.

Does anybody have an idea?
My best regards...

The code below return an invalid handle value because of this problem:

VB
myPort = CreateFile("\\.\COM14",
              GENERIC_READ | GENERIC_WRITE,
              0,    /* exclusive access  */
              NULL, /* no security attrs */
              OPEN_EXISTING,
              0,
              NULL );
Posted

1 solution

You should escape backslashes in C/C++, write
C++
myPort = CreateFile("\\\\.\\COM14",
..
 
Share this answer
 
Comments
Un_NaMeD 8-Mar-12 6:13am    
Thank you CPallini..
My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900