469,658 Members | 1,702 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,658 developers. It's quick & easy.

Open Com Port > 9 with C++ ?

Hi everybody !

I need some help in programming an RS232 serial interface.

Opening a com port upper than "COM9:" (for example "COM10:", "COM11:"
etc)returns ERROR_INVALID_NAME error.
Details:
I use C++ with MFC with Wisual Studio 6.0 on XP.
The example code:
-----------------------------------------------------------------
m_hPort = CreateFile (lpszPortName, // Pointer to name of the
port
GENERIC_READ | GENERIC_WRITE,
// Access (read/write) mode
0, // Share mode
NULL, // Pointer to security
attribute
OPEN_EXISTING, // How to open
0, // Port attributes
NULL); // Handle to port with
attribute

With lpszPortName from "COM1:" to "COM9:" it works well.
With lpszPortName equal to "COM10:" and more error 123
ERROR_INVALID_NAME occurs !

I tried in HyperTerminal, and I hav no problem to open com port 10,
11, 12 ...

Any ideas what causes the Port to respond with "INVALID_NAME"`?

Help is greatly appreciated.
Thanks in advance,
bye,
Sylvain
Jul 22 '05 #1
4 8253
> With lpszPortName from "COM1:" to "COM9:" it works well.
With lpszPortName equal to "COM10:" and more error 123
ERROR_INVALID_NAME occurs !


Maybe there should be a HEX encoded number
Jul 22 '05 #2
Sylvain <sy********@wanadoo.fr> spoke thus:
I need some help in programming an RS232 serial interface. Any ideas what causes the Port to respond with "INVALID_NAME"`?


(This isn't the place to ask.)

Your post is off-topic for comp.lang.c++. Please visit

http://www.slack.net/~shiva/welcome.txt
http://www.parashift.com/c++-faq-lite/

for posting guidelines and frequently asked questions. Thank you.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #3
The cause of the problem is that CreateFile accepts strings "com1" -
"com9" as names of devices and reject to do so for two and more digit
numbers. In order to open "com10" and above we actually have to feed
"\\\\.\\com10" string to CreateFile.

For more serial I/O tips, tricks and free utilities, visit
www.taltech.com

On 19 Apr 2004 03:01:04 -0700, sy********@wanadoo.fr (Sylvain) wrote:
Hi everybody !

I need some help in programming an RS232 serial interface.

Opening a com port upper than "COM9:" (for example "COM10:", "COM11:"
etc)returns ERROR_INVALID_NAME error.
Details:
I use C++ with MFC with Wisual Studio 6.0 on XP.
The example code:
-----------------------------------------------------------------
m_hPort = CreateFile (lpszPortName, // Pointer to name of the
port
GENERIC_READ | GENERIC_WRITE,
// Access (read/write) mode
0, // Share mode
NULL, // Pointer to security
attribute
OPEN_EXISTING, // How to open
0, // Port attributes
NULL); // Handle to port with
attribute

With lpszPortName from "COM1:" to "COM9:" it works well.
With lpszPortName equal to "COM10:" and more error 123
ERROR_INVALID_NAME occurs !

I tried in HyperTerminal, and I hav no problem to open com port 10,
11, 12 ...

Any ideas what causes the Port to respond with "INVALID_NAME"`?

Help is greatly appreciated.
Thanks in advance,
bye,
Sylvain


Jul 22 '05 #4
On Wed, 21 Apr 2004 17:30:29 GMT, Thomas Lutz wrote:
The cause of the problem is that CreateFile accepts strings "com1" -
"com9" as names of devices and reject to do so for two and more digit
numbers. In order to open "com10" and above we actually have to feed
"\\\\.\\com10" string to CreateFile.


I wasn't going to reply to this thread because it's off topic, but I feel
that a partial off-topic answer is worse than a complete off-topic answer,
and hence I'll mention that the form Thomas gives above is also valid for
all of the single-digit com ports. IOW, there is no requirement to do any
special case checking: if you need to support high-numbered com ports, just
use the \\\\.\\comx form for everything from com1 up.

--
Greg Schmidt gr***@trawna.com
Trawna Publications http://www.trawna.com/
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by hugo batista | last post: by
2 posts views Thread by jyotish.bora | last post: by
1 post views Thread by Laszlo Nagy | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.