MSCOMM32.OCX error


Thread Starter


I am Writing serial port communication application in VC++6 using MSCOMM32.OCX, Application when is run, and trying to connect to any of the serial ports it is giving an error saying, "Device not open".

I am sure this error is being thrown by MSCOMM32.OCX , but i really don't know what that means and what to do to resolve that.

I have been working on this from past one week and could not find any clue ....

Please help me ....

Thanks in advance ..


Have you opened the port?
Because the first that you have to do to read or write data to a serial port is open it. (mscomm1.portopen = true) And don't forget to close it when you finish your job (mscomm1.portopen = false).

I hope that this helps you.

Armando Abraham
Actually error is getting displayed when trying to open the port, I am using a Toshiba laptop running Win XP. when tried connecting to the port through HYPERTERMINAL it worked i.e i could open the com port and dail up the modem attached to com port 3 ,but when trying to open the port through my application "Device is not open " error is getting thrown .

When i tried my application on another system it worked !!

What does this error exactly mean ? Please let me know.

following is the piece of code which Iam using..
to open the port.

pCommCtrl is pointer to my mscomm32.ocx::

pCommCtrl->SetPortOpen(TRUE); //throwing the
CATCH_ALL(e) //catching that exception here
TCHAR szCause[255];
CString strFormatted;
e->GetErrorMessage(szCause, 255);
strFormatted += szCause;
//message which i am getting is "Deice not open"


David Wooden

Hello Sirisha:

Before you can use a com port, the port must be opened. This tells the system that the MSComm control you've created in your program is now using the port you've opened, and no other program can use it until you close it. Here are the calls (Assuming pMSComm is already defined as a pointer to an instance of MSComm, and you are using Com1 at 9600 baud, Even parity, 7 data bits and 2 stop bits):
pMSComm->SetCommPort(1); // Select the port (Com1)
pMSComm->SetSettings("9600,E,7,2"); // Set communication settings
pMSComm->SetPortOpen(TRUE); // Open the port

When you are finished with the port, close it.
pMSComm->SetPortOpen(FALSE); // Close the port

Best of luck,

David Wooden
Senior Software Engineer, Systems Integration
Automation and Enterprise Solutions Group
TAS Division of Omron Electronics LLC
Office: (847) 884-7034 Extension 432
Fax: (847) 884-9383
E-mail: [email protected]

Piotr Kowalski


You should use MSComm1.PortOpen = True, before you use the controll (assuming the controls name is "MSComm1")
Piotr Kowalski