473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Opening COM port Error

I have the following code: When i run this code it gieve me an error
saying the COM port isn;t opened?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If serialPort.IsOpen Then
serialPort.Close()
End If

Try
With serialPort
.PortName = ComboBox1.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One

End With
serialPort.Open()

BAIhomeaction()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Jun 27 '08 #1
4 3618
And the line that fails is ? Also you may want to consider dropping the
try/catch statement (you'll be placed at the location of the error)

"cmdolcet69" <co************@hotmail.coma écrit dans le message de groupe
de discussion :
40**********************************...oglegroups.com...
I have the following code: When i run this code it gieve me an error
saying the COM port isn;t opened?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If serialPort.IsOpen Then
serialPort.Close()
End If

Try
With serialPort
.PortName = ComboBox1.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One

End With
serialPort.Open()

BAIhomeaction()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Jun 27 '08 #2
On May 14, 2:17*pm, "Patrice" <http://www.chez.com/scribe/wrote:
And the line that fails is ? Also you may want to consider dropping the
try/catch statement (you'll be placed at the location of the error)

"cmdolcet69" <colin_dolce...@hotmail.coma écrit dans le message de groupe
de discussion :
40e0d15b-689f-4bee-987e-85149b174...@x35g2000hsb.googlegroups.com...
I have the following code: When i run this code it gieve me an error
saying the COM port isn;t opened?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
* * * *If serialPort.IsOpen Then
* * * * * *serialPort.Close()
* * * *End If
* * * *Try
* * * * * *With serialPort
* * * * * * * *.PortName = ComboBox1.Text
* * * * * * * *.BaudRate = 9600
* * * * * * * *.Parity = IO.Ports.Parity.None
* * * * * * * *.DataBits = 8
* * * * * * * *.StopBits = IO.Ports.StopBits.One
* * * * * *End With
* * * * * *serialPort.Open()
* * * * * *BAIhomeaction()
* * * *Catch ex As Exception
* * * * * *MsgBox(ex.ToString)
* * * *End Try
* *End Sub- Hide quoted text -

- Show quoted text -
It fails on the serialPort.Open() telling me its not opened.
Jun 27 '08 #3
See this note in MSDN for the SerialPort.Open() method:

' from msdn
Only one open connection can exist per SerialPort object.

The best practice for any application is to wait for some amount of time
after calling the Close method before attempting to call the Open method, as
the port may not be closed instantly.

' end of msdn remarks
"cmdolcet69" wrote:
I have the following code: When i run this code it gieve me an error
saying the COM port isn;t opened?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If serialPort.IsOpen Then
serialPort.Close()
End If

Try
With serialPort
.PortName = ComboBox1.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One

End With
serialPort.Open()

BAIhomeaction()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Jun 27 '08 #4
What is the .PortName property set to? It should be something like "COM1".

You don't say how your are filling the combobox text. Is it from the array
returned by the .GetPortNames method? Are there any unexpected characters
in the name (I've seen USB Bluetooth drivers add odd terminating
characters)?

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lizard King | last post by:
Hi. I have a computer running a third party software (POS). The thing is this application opens the printer port and I need to use another program while the first one is still running. Since...
1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
1
by: DavidE | last post by:
Hi, Recently, when I try to open files in web projects with visual interdev 6 I get this error message: Server error: Error 2 opening registry key Software/microsoft/shared tools/web server...
5
by: CeZaR | last post by:
Hi, I've posted earlier a question regarding the call to GetCommState. Here is the code for the function. The problem is that GetCommState always returns false!! Why? void Open() { // the...
0
by: David | last post by:
I am having trouble with "ACCESS DENIED" error messages in a VB.NET 2003 application when attempting to open serial comms ports. The application has 2 ports that connect via serial cable to 2...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
3
by: Luke Davis | last post by:
I'm looking for an effective way to open and close TCP ports. Can I do this through Tcpclient? And I know this is a potential security risk, so what kind of permission must the person running...
3
by: Suresh P | last post by:
Hi All, I tried to access the mysql database in ODBC using ip address and username/password. It returns, "cannot connect to MySQL server on IP ADDRESS(10060)". This could be related to Firewall...
1
by: Deigor | last post by:
Hi i am working on serial port programming using CreateFile function in VC. This function runs well in Visual Studio 6, while the same instruction fail to execute in VS2005. Can any one tell what...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.