COM port not opening

  • Thread starter Thread starter Alain Dekker
  • Start date Start date
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
 
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
 
Back
Top