Member Login
member
passwd
remember me on
this computer.

- join now -
- forgot username or password? -

Search

Jump to a Date

Sponsored Communities
Cool stuff
Select a topic of interest:
...and press:
Neat Stuff
Control.com Stuff

Visit our shop for nerds in control lifestyle products.

Fortune
"Not only is this incomprehensible, but the ink is ugly and the paper
is from the wrong kind of tree."
-- Professor W.
RSS Feed
RSS feed Use this link to get an RSS feed of the Control.com article flow, for private, non-commercial use only:
www.control.com/rss/
To get a personalized feed, become a member at no cost.
Select a Page Style
Select one of the following styles:
- BluFu
- Classic
(cookies required)
advertisement
from the vb department...
Error in opening Comm port in VB
Programming languages. topic
Posted by mr jj on 5 March, 2004 - 7:42 pm

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.

my source code is as follows:


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


Posted by Anonymous on 11 March, 2004 - 10:03 pm
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


Posted by Jim Aulgur on 11 March, 2004 - 10:44 pm
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


Posted by MJ on 15 March, 2004 - 3:41 pm
What about using the err object in order to retrieve the error code you get?


Posted by Gregorio Cavazos on 19 March, 2004 - 6:06 pm
It may be not opened by your application but can be in use by another software running.

Gregorio Cavazos C.


Posted by alvin on 3 March, 2007 - 2:24 pm
perhaps you can do try catch statement to detect whether the port has been opened. just include the open port code in try statement


Posted by Nile on 26 March, 2004 - 2:04 pm
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


Posted by Anonymous on 2 April, 2004 - 6:25 pm
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...


Posted by mutlyp on 30 November, 2004 - 9:29 pm
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!!!!


Posted by Joe on 8 December, 2004 - 5:33 pm
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


Posted by newbie on 30 August, 2005 - 2:29 pm
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!


Posted by Shailesh C Patel on 31 August, 2005 - 8:03 pm
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.


Posted by sachinda thakur on 25 February, 2006 - 4:41 pm
Thank you Shri Shailesh C Patel , your tip has solved my problem.On my pc there was some irda s/w using COM1 port


Posted by Lynn A Linse on 28 September, 2005 - 11:38 pm
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


Posted by Jason on 18 August, 2007 - 2:33 pm
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.

From Control Engineering magazine...
Related articles from Control Engineering magazine
Above articles copyright 2009 Reed Business Information. Subject to its Terms of Use.
Your use of this site is subject to the terms and conditions set forth under Legal Notices and the Privacy Policy. Please read those terms and conditions carefully. Subject to the rights expressly reserved to others under Legal Notices, the content of this site and the compilation thereof is © 1999-2009 Control Technology Corporation. All rights reserved.

Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.

Internet Explorer 6.0 Fix

Advertisement
Our Advertisers
Help keep our servers running...
Patronize our advertisers!