Opening COM port Error

C

cmdolcet69

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
 
C

cmdolcet69

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" <[email protected]> a écrit dans le message de groupe
de discussion :
(e-mail address removed)...








- Show quoted text -

It fails on the serialPort.Open() telling me its not opened.
 
F

Family Tree Mike

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
 
D

Dick Grier

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top