Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I want to open a single com port from two or more applications. can anyone provide a some code or any link for achieving this in .net? I am searching the internet from last two days but, could not find any solution. I know, it is possible, because i have some applications that do this work. But, i have to write this functionality in my own application.
 
Thanks in advance.
Posted 17-Jan-13 21:25pm
Edited 17-Jan-13 21:29pm
v2
Comments
Sergey Alexandrovich Kryukov at 18-Jan-13 2:28am
   
Why?!
—SA
AnkitGoel.com at 18-Jan-13 2:33am
   
i have to trace the communication between an existing application and some manufacturing machine.
lukeer at 18-Jan-13 2:56am
   
Say you had the monitoring software already working, you could as well solder some special man-in-the-middle-three-plug-wire to listen to communication in one direction or the other.
Jochen Arndt at 18-Jan-13 3:09am
   
To trace the communication, use a serial port sniffer / monitor. Using the last three/four words you will get a lot of search hits including free utilities. An example application in C++ can be found here at CP: http://www.codeproject.com/Articles/311159/SIMPLE-SERIAL-PORT-MONITOR. It's not .NET but it explains how monitoring can be done.
AnkitGoel.com at 18-Jan-13 3:19am
   
thanks but, it could not work.
AnkitGoel.com at 18-Jan-13 3:19am
   
it cannot open an already open port.
Jochen Arndt at 18-Jan-13 3:32am
   
An already opened port can't be opened a second time. This can't be circumvented. Therefore, all software sniffers must be started before the port is opened.
 
What are these 'some applications' that claim to can do that?
AnkitGoel.com at 18-Jan-13 4:23am
   
one of them is HHD Serial Port Emulator
Jochen Arndt at 18-Jan-13 5:14am
   
Thank you for the information. I just tested it and it can monitor opened connections. So you are right that sniffing can be done this way. But it is not done by openening a port a second time (the Windows API CreateFile function used to open serial ports will fail when the port is already opened).
 
Because this is interesting, I googled a little bit:
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/108d65c6-dcc3-4483-a50c-ac540453f433
From the above:
http://www.drdobbs.com/a-serial-port-spy-for-nt/184416559
 
I hope this helps and you have some kind of success.
AnkitGoel.com at 21-Jan-13 0:06am
   
Thanks Jochen, did u try this code? Does it work for you?
Jochen Arndt at 21-Jan-13 3:28am
   
No, I did not tried it. It's too complex for a quick implementation.
AnkitGoel.com at 21-Jan-13 7:37am
   
I feel the same and don't have time to get into the depth at this time.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can not have more than one process opening a com port. If port is opened by a process, other process will simply not be able to open it. Best bet is to use simple TCP/IP, open the port from a server program, from other applications, interact with the server.
  Permalink  
Comments
AnkitGoel.com at 18-Jan-13 3:02am
   
AS i already said, i am able to open a port multiple times using a third party application. but i want to do it in my own code to make it user friendly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100