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