473,698 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

close existing port using Ports.SerialPor t 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.I sOpen)
{
serialPort.Clos e();
}
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.IsOp en 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 8255

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.IsOp en 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.c om/group/microsoft.publi c.dotnet.langua ges.csharp/browse_thread/thread/e7079eeca74325f b/9b30f797a59faa5 8?lnk=st&q=RAS+ c%23+dial&rnum= 1&hl=en#9b30f79 7a59faa58>

Oct 20 '06 #2
Hi Eric,

Thanks for the response. You're right, I am using the win32 RAS, to
programmaticall y 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.IsOp en 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.c om/group/microsoft.publi c.dotnet.langua ges.csharp/browse_thread/thread/e7079eeca74325f b/9b30f797a59faa5 8?lnk=st&q=RAS+ c%23+dial&rnum= 1&hl=en#9b30f79 7a59faa58>
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
1817
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 code? Thank you Michel
1
8470
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 C# program and see it appear in a Hyperterminal window open on comm port 2. Hyperterminal is configured with the same settings that the port 1 is opened with (see below), but I do not get an 'a', I get some funky ASCII character that looks like a...
0
1437
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
10142
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 "connection" with my PDA. I need 2 ports, one for ingoing data, one for outgoing data (that's how serial port profile in bluetooth is made)
7
4937
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 my own component and then put it in <object> but it doesnt seem to work, any suggestions?
0
385
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 SerialPort ("COM1"); if(serialPort.IsOpen)
4
8658
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 want to set the fRtsControl to RTS_CONTROL_TOGGLE so the RTS signal will be reset automatically when the TX buffer is empty. - Kristoffer -
2
5495
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. From what I understand this can be accomplished relativly easy using .net 2.0 SerialPort component over a COM port. My question: because most newer computers don't have 9 pin serial ports (COM), can the SerialPort component use a USB connection...
0
1557
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. PinChangedEvent ). Please, Help? Regards,
1
2889
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 of seconds. I'm able to write and read from the parallel port, but after a few reads and writes it crashes... how many reads and writes before it crashes is not always the same.. sometimes it crashes at the first write or read.. other times it...
0
8672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9155
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9018
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7711
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.