Error in opening Comm port in VB

M

Thread Starter

mr jj

<p>i'm doing a project in VB where i'm using comm port but when i try to open the port it gives the error as port already open though the port is not open.

<p>my source code is as follows:
<pre>
Private Sub Form_Load()
Dim str As String
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True



Text1.Text = "sending: hello"
MSComm1.Output = "hello"
Do
DoEvents

Loop Until MSComm1.InBufferCount = 0
str = MSComm1.Input
Text1.Text = "recived:" + str
MsgBox "recieved" + str
MSComm1.PortOpen = False

End Sub
</pre>
 
Hi..

I tried you code and it worked fine in my computer. You may have that port being used by an other program.

Try using the other serial port.

good luck!!
bye
 
J
Another program may have the port already open. Use hyper terminal and see if you can open com port 1. if you can make sure you close it and then make sure your not calling it twice insome other place your not aware of. Like Form Init.

Jim
 
G

Gregorio Cavazos

It may be not opened by your application but can be in use by another software running.

Gregorio Cavazos C.
 
Hi,

I hope ur problem is solved.I have a doubt to ask.U have sent text 'HELLO' to a port, what's the command i use in hyperterminal to read the string 'HELLO'.

Regards,
Nile
 
Another common problem when doing these kinds of things in VB is that the comm port may have been opened in a previous attempt to test your code.

If in a previous test run of your code, the port was opened but an error halted execution thereafter, the port will still be open. If this is your problem, closing the VB IDE will close the port...
 
I am having a similar problem. And what is really wierd is that right before the
MSComm1.PortOpen = True
line, I put in a msgbox and ask for the status of the port.

Example:
msgbox("The port is open " & MSComm1.PortOpen)
when that message comes up, it says that the port is False. Then the very next line is
MSComm1.PortOpen = True
and then I get the error saying that the port is already open?!?!?!?!?!
HELP!!!!
 
hi friends, i need your help also, i used VB6 for doing development for transfering data from pabx to pc and buffer to pc. my problem is let say i use Windows98, it's working fine. But if i use Windows2000 no error comes out, and my system can't receive any data from outside. means OS already open the port. I check with Microsoft site, they have patch file to disable the auto service. but it still gives same problem...

need your help...
Joe
 
Anyone solved this problem? I have the same problem. I use the code to open the port. It should gives me error if I have not hook up any cable to the port but it appears to have MSComm1.PortOpen=true anyways.

Please give me some insights.

Thanks!
 
S

Shailesh C Patel

If you install any one of following software that prob happen.

1> Irda driver
2> bluetooth driver
3> nokia pc suite

check this.

Regards,
Shailesh C Patel
FDC - Control Systems And Instrumentation
Reliance Engineering Associates(P) Ltd.
 
L
Sadly, this may be an MSCOMM issue - I stopped using it back when VB v4 existed because at times it would "drop the ball" and define a port as unavailable when it was unused - or worse - available when it was not. A PC reboot was the only solution. So I started using XCommm from Greenleaf (not sure who owns them now) and it proved very robust.

Also, are you sure a modem dialer isn't using that port? Check out your "network connections" entries. Otehrwise, do a search of the Windows registry for strings COM1 or COM2 and maybe you'll find some tool claiming it.

- LynnL, www.digi.com
 
S

sachinda thakur

Thank you Shri Shailesh C Patel , your tip has solved my problem.On my pc there was some irda s/w using COM1 port
 
perhaps you can do try catch statement to detect whether the port has been opened. just include the open port code in try statement
 
To LynnL, www.digi.com.

Absolutely spot on. Found the COM4 I needed assigned to another device even though it wasn't using it, it was talking to it all the time. I deleted the COM4 references and hardware assignment to the device that was hijacking it and rebooted and woohoo the port remained closed and is accessible to VB again... Thank you.
 
Top