Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Open Com Port > 9 with C++ ?

Reply
Thread Tools

Open Com Port > 9 with C++ ?

 
 
Sylvain
Guest
Posts: n/a
 
      04-19-2004
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
 
Reply With Quote
 
 
 
 
George
Guest
Posts: n/a
 
      04-19-2004
> 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


 
Reply With Quote
 
 
 
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      04-19-2004
Sylvain <(E-Mail Removed)> 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.
 
Reply With Quote
 
Thomas Lutz
Guest
Posts: n/a
 
      04-21-2004
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, http://www.velocityreviews.com/forums/(E-Mail Removed) (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


 
Reply With Quote
 
Greg Schmidt
Guest
Posts: n/a
 
      04-24-2004
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 (E-Mail Removed)
Trawna Publications http://www.trawna.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
Overhead of 4-port over 2-port SRAM John T. Goodman VHDL 0 01-25-2005 04:27 PM
Port security on a Catalyst 4000 - fails to shut down port Jon Whitear Cisco 2 11-04-2003 11:01 PM
about "match ip rtp starting-port-number port-range" Weiguang Shi Cisco 1 10-25-2003 07:14 AM
Port 1033 (netinfo) port is open - what's it for and how do I close it Neil Armstrong Computer Security 3 09-18-2003 01:22 PM



Advertisments