473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

close existing port using Ports.SerialPort component

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
3 8153

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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michel | last post by:
I'm looking for an asp code who can send an email without using a mail component. I started to write somethings using winsock but I don't have enough time to finish it. Does somebody have a such...
1
by: Don Tucker | last post by:
Hello, I am using Visual Studio .Net 2005 beta. I have my computer's two comm ports connected with a serial cable (and null modem). I'm trying to write the letter 'a' out on comm port 1 with the...
0
by: Piotrekk | last post by:
Hi My question is: How to conrol output pins of ( for example ) COM1 I found in .net System.IO.Ports.SerialPort class. Is there any posibility to set or not set pins D0-7? Thanks PK
3
by: SamB | last post by:
Hello all! MY CASE: I'm using VB.net 2005 express on a Dell Laptop with an USB Bluetooth key. I'm trying to send data to a pocketPC. COM numbers changes each time i've got a new bluetooh...
7
by: Tamir.D | last post by:
is there a way to embed the System.IO.Ports.SerialPort object in my html . so that the client can access to a device connected to his SerialCOM ? i tried to wrap the System.IO.Ports.SerialPort in...
0
by: ricolee99 | last post by:
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...
4
by: =?Utf-8?B?S3Jpc3RvZmZlciBQZXJzc29u?= | last post by:
Does anyone know if it's possible to get the Win32 handle to the serial port used under the hood in System.IO.SerialPort? The reason I want it is so I'd be able to make changes the DCB struct. I...
2
by: egress | last post by:
Forgive me for stupid questions for I am new to serial IO programming. I am developing an app that will need to communicate with a device via RS232 protocol using a standard 9 pin serial cable. ...
0
by: Bandu | last post by:
Hi, is System.IO.Ports.SerialPort supported in 64bit? I'm writing C# application and its worked fine with 32 bit. But in 64-bit, System.IO.Ports.SerialPort never fire up the Event Handler (e.g....
1
by: ssndk123 | last post by:
Hi, Using the UserPort program that changes permissions in XP so that I am able to write directly to the parallel port using assembler.. I'm trying to send out square wave pulses for x number...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.