COM port not opening

A

Alain Dekker

I'm trying to get access to a COM Port using this code:

HANDLE hCom = CreateFile("COM1",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);

This works almost all the time...but on this one machine we have it keeps
failing (hCOM == -1).

Device Manager shows the com port looks fine. I've tried changing COM1 to
COM2 without success. Any ideas?

Is it relevant whether I use "COM1" or "\\\\.\\COM1" ?

Thanks,
Alain
 
P

Paul

Alain said:
I'm trying to get access to a COM Port using this code:

HANDLE hCom = CreateFile("COM1",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);

This works almost all the time...but on this one machine we have it keeps
failing (hCOM == -1).

Device Manager shows the com port looks fine. I've tried changing COM1 to
COM2 without success. Any ideas?

Is it relevant whether I use "COM1" or "\\\\.\\COM1" ?

Thanks,
Alain

Throw your code into a search engine, and look for examples ?

http://vbnet.mvps.org/index.html?code/system/comtestapi.htm

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top