Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trouble opening connection to serial port through "CreateFile"

Posted on 2004-09-07
4
Medium Priority
?
799 Views
Last Modified: 2010-04-24
Hey Everybody,

I am trying to get access to my serial port through the CreateFile Method like this

HANDLE portHandle = CreateFile( "COM2",  GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);

but it keeps giving me an invalid handle. I suspect it is the name of the port. I want to access comm port 2 (like if I were in hyperterminal it would be com2) but have no clue if I am using the right name here. Any help would be greatly appreciated.
0
Comment
Question by:komeisa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 12002626
This looks correct.  If your result is portHandle == INVALID_HANDLE_VALUE, what error is reported by GetLastError()?  Are you sure COM2 is configured on your machine?
0
 

Author Comment

by:komeisa
ID: 12008004
I figured out the problem. My application is in managed C++. And I guess it doesn't like the CreateFile Routine. Any clue on how I might get this to work in a managed C++ environment
0
 
LVL 19

Accepted Solution

by:
drichards earned 300 total points
ID: 12009339
I use CreateFile in managed C++ and it works just fine.  You can't see the handle value in the debugger, but the call succeeds and communications work.  In the debugger the handle value goes from <undefined value> to {void} when CreateFile is called.
0
 

Author Comment

by:komeisa
ID: 12011517
Yeah,

I finally got it to work, it wasn't because of the managed c++. I think it was an error in my code.  I reailized that I was connecting okay to the port but when I would try to write something out onto the port it would come back with an error. It turns out I wasn't passing the buffer with the data to transmit correctly. Thanks for you help, I really appreciate it.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question