473,563 Members | 2,762 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 8210

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
1795
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
8455
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...
0
1432
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
10117
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
4932
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
8647
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
5485
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...
0
1548
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
2878
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...
0
7664
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...
0
8106
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...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
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...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
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
0
923
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...

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.