473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 8532
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CM | last post by:
Hi there: I have a web project which can be open and run without problem. I didn't open the web application for a period and during which I didn't modified any IIS items, but now I cannot open any...
0
by: hugo batista | last post by:
Hi everybody I'm having a problem with the following environment: - Windows 2003 web edition - .net framework 1.1 I created a dummy web services that accepts a string in a webmethod. With...
2
by: jyotish.bora | last post by:
Hi , i m trying to send a message packet to a RS232 port. I have created the handle and set the parameters. Now the general format of the packet is <STX>command<ETX><LRC> I have also written...
1
by: vhrao | last post by:
I created asp.net project with location http://localhost/proj1, which works fine. Now I found out that I have to change port from 80 to 8080. I changed TCP port for deafult website from 80 to...
3
by: Mugunth | last post by:
Hi, I've a strange problem with serial port class of .NET Framework 2.0 I use com0com (Null Modem COM Port emulator) to emulate a virtual port. This application creates virtual com port pairs...
1
by: Laszlo Nagy | last post by:
Hi All, I'm using a simple program that uploads a file on a remote ftp server. This is an example (not the whole program): def store(self,hostname,username,password,destdir,srcpath):...
4
by: Soren | last post by:
Hi, I want to control some motors using the parallel port.. however, my laptop does not have any parallel ports (very few do). What I do have is a USB->Parallel converter... I thought about...
3
by: Jeff | last post by:
hi I'm wondering how to open a web browser window in VS2008. I've created a simple windows Live Agent and just want to test it in the VS2008 before I deploy it... any ideas how to open a...
2
dlite922
by: dlite922 | last post by:
Hello Hello! I'm trying to connect to a host that accepts UDP on a port I setup and tested from a command line too called udp_write. However a PHP fsocketopen() call doesn't work nor does it give...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.