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:
- open port
- detach the serial port cable (from computer USB port)
- attach the cable again
- close port
- 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:
- open port
- close port
- detach and reattach cable
- open port