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

close existing port using Ports.SerialPort component

P: n/a
Hi Everyone,

I'm using the System.IO.Ports.SerialPort component to attempt to kill
an existing component opened by another application.

I use the following code:

SerialPort serialPort = new SerialPort ("COM1");

if(serialPort.IsOpen)
{
serialPort.Close();
}
I cannot for the life of me close the opened connection. Each time I
create a dial up connection manually on COM 1, I run this code while
the connection is open. Each time, the serialPort.IsOpen is set to
false even though the dial up connection is open.

Can someone tell me how I can kill or close the COM 1 port if something
has it opened?

Thanks in advance

Eric

Oct 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

ri*******@gmail.com wrote:
I cannot for the life of me close the opened connection. Each time I
create a dial up connection manually on COM 1, I run this code while
the connection is open. Each time, the serialPort.IsOpen is set to
false even though the dial up connection is open.
Have you tried closing it without testing it first? Maybe do this in a
try/catch and ignore an exception that might be thrown if it was really
closed.

I bet RAS has opened the port, and .NET doesn't know that it's open.
Are you sure you want to control the port yourself? If you merely want
an internet connection you should probably go through RAS.

See here:
<http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/e7079eeca74325fb/9b30f797a59faa58?lnk=st&q=RAS+c%23+dial&rnum=1&hl= en#9b30f797a59faa58>

Oct 20 '06 #2

P: n/a
Hi Eric,

Thanks for the response. You're right, I am using the win32 RAS, to
programmatically open the internet connection. I disconnect the
connection using RAS when file copying across the network is done. The
problem is on the client side, the internet connection is unreliable,
meaning anytime the connection can just drop. I simulate this by
opening the internet connection using RAS, and then manually cancelling
the connection under "Network Connections" window from admin tools.
The problem is that since the RAS connection did not disconnect
gracefully, the computer still thinks the port is open (I'm getting a
633 connection still in use error when I connect ). I'm trying to use
the Serial Port to close this open connection.

I've also tried closing it without checking if port is opened. It
tells me that it successfully closed the port, but yet the internet
connection is still there.


Eric wrote:
ri*******@gmail.com wrote:
I cannot for the life of me close the opened connection. Each time I
create a dial up connection manually on COM 1, I run this code while
the connection is open. Each time, the serialPort.IsOpen is set to
false even though the dial up connection is open.

Have you tried closing it without testing it first? Maybe do this in a
try/catch and ignore an exception that might be thrown if it was really
closed.

I bet RAS has opened the port, and .NET doesn't know that it's open.
Are you sure you want to control the port yourself? If you merely want
an internet connection you should probably go through RAS.

See here:
<http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/e7079eeca74325fb/9b30f797a59faa58?lnk=st&q=RAS+c%23+dial&rnum=1&hl= en#9b30f797a59faa58>
Oct 20 '06 #3

P: n/a

ri*******@gmail.com wrote:
The problem is that since the RAS connection did not disconnect
gracefully, the computer still thinks the port is open
If you were on Win98 you could directly access the UART and force it
closed.

I'd seriously look at the RAS API (via pinvoke). I think there's a way
to force the port closed that way. As I recall, it was always a pain to
detect if the port was really open or closed, but I think you can force
it closed regardless of it's current status. But you may have to do
that through the RAS API, and not the WinNT SerialPort device control
mechanism. The problem with the WinNT model is that you can't close a
port you didn't open.

But maybe someone else can give you more specific assistance. Anyone?

Oct 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.