0

Possible Duplicate:
Releasing a unplugged virtual Serial Port

This is my code to connect a serial com port:

try{
SRR_serial_port.PortName = comboBox2.Text;
SRR_serial_port.BaudRate = 9600;
SRR_serial_port.Parity = System.IO.Ports.Parity.None;
SRR_serial_port.DataBits = 8;
SRR_serial_port.StopBits = System.IO.Ports.StopBits.One;
SRR_serial_port.Handshake = System.IO.Ports.Handshake.None;       
SRR_serial_port.WriteTimeout = 500;

SRR_serial_port.Open();
}
catch{}

and then close the port as follow:

SRR_serial_port.Close();

now i have a problem in this scenario:

  1. open port
  2. detach the serial port cable (from computer USB port)
  3. attach the cable again
  4. close port
  5. open port again

this leads to the following error:

access to the port is denied

In debug mode I see that this error occurs in the following lines of this line:

SRR_serial_port.Open();

I mean, this line executes and the port state change to open but after a while(during execution of next line) that error appears.

However, this scenario does not produce any error:

  1. open port
  2. close port
  3. detach and reattach cable
  4. open port
Community
  • 1
  • 1
ali motamedi
  • 103
  • 5

0 Answers0