Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Serial port reconnecting

$
0
0

Hi,

My application need to communicate a periferial using RS-232. My computer is connected to the periferial by RS232-to-USB of Prolific.

I’m trying to reconnect after the following scenario:

I take the RS232 cable out of the computer.

I run my application and try to connect to the port.

Of course, the connection fails.

I connect the RS232 cable to the computer.

I try to connect the port again.

And again, I fail.

The only way I can connect now is by closing the application and running it again.

It looks like I fail to clean something, but I don't know what...

My close function looks like this:

public

overridevoid Close()

{

Log4NetWrapper.Instance.LogDebug("Rs232Communicator","Closing","");

try

{

if (m_Port !=null&& m_Port.IsOpen == true)

{

m_Port.Close();

}

m_Port.Dispose();

m_Port =

null;

}

catch (Exception ex)

{

System.Windows.Forms.

MessageBox.Show(ex.Message +"\r\n"+ ex.StackTrace);

}

}


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>