MSCOMM Control Problem

sangeet302
01-23-2002, 03:52 AM
I want to communicate through COM PORT. I have an third party application which writes to COM1.

I want to develop a VB application which reads the data from COM1. I have used MSCOMM Control in VB but whenever i use portopen command it says "Port allready open"

Please suggest some method.

Bye
Sangeet

divil
01-23-2002, 04:41 AM
You can't access a COM port if another application already has it open.

Michael Freeman
01-23-2002, 07:18 PM
Sangeet,

You should check to make your the port is not currently open by another application, before you attempt to open that port.


Here is a simple routine that traps on the error generated when VB tries to open a port already in use:

Sub OpenSerialPort()

On Error GoTo SerialPortOpenErrorHandler

'Open com port
MSComm1.PortOpen = True
Exit Sub

SerialPortOpenErrorHandler:
If Err.Number = 8005 Then
'COM Port Already Opened!
MsgBox "COM Port is already opened by another application!" & vbCrLf & "Please Close Serial Port.", vbOKOnly + vbCritical, "Comm Error"
End If
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum