By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Help needed opening serial port in VB.NET

P: n/a
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 different
hardware devices to transfer binary data to the application. The setup
screen enables the user to select COM1 -- COM8 via combo boax for each port.
Then they click "Apply" to open the ports.

The code that I have written to open the ports is shown below. The code
works if you select valid ports first time but if you either select invalid
ports or the same port as previously selected you get the ACCESS DENIED
error.

I have attempted to ensure the port is closed before changing the
parameters. Also, the port gets closed if there is an error.

Any help much appreciated, Thanks.

If MasterPort.IsOpen Then MasterPort.Close()
While MasterPort.IsOpen
End While

MasterPort.Options = New Sax.Communications.SerialOptions(MasterPortname,
19200, _Sax.Communications.Parity.None, 8,
_Sax.Communications.CommStopBits.One, False, True, False, False, True, True)

Try
MasterPort.Open()
Catch exception As Exception
MsgBox( "Problem with Master Port : " & exception.message)
If MasterPort.IsOpen Then MasterPort.Close()
End Try

If HandheldPort.IsOpen Then HandheldPort.Close()
While HandheldPort.IsOpen
End While

HandheldPort.Options = New Sax.Communications.SerialOptions(MasterPortname,
19200, _Sax.Communications.Parity.None, 8,
_Sax.Communications.CommStopBits.One, False, True, False, False, True, True)

Try
HandheldPort.Open()
Catch exception As Exception
MsgBox( "Problem with Handheld Port : " & exception.message)
If HandheldPort.IsOpen Then HandheldPort.Close()
End Try
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.