zenwalker

Hello Guys,

I am working on a C++ and C# integrated developed product. This product uses User32.dll and Kernel32.dll (of windows i belive) for accessing (Acquiring) and releasing COM ports in the system. For some reason (Which i am not sure how either) the COM2 or some times other COM ports wont responds and let me acquire it (Through Code) and access the devices connected under that port.

So i hereby request any body to guide me, how to get over this problem , i mean, a code or some windows defined API to release these ports explictiely and release them when ever needed or not.

Thanks,
Zen Smile


P.S: I hope i have made myself clear. Any more info needed, please let me know.

Operating System: Windows XP SP2.
IDE : Visual Studio 2005




Re: Visual C++ General Info about Releasing COM1,2,3,4 ports explicitely using Windows API or C++ code. [HOW TO]?

zenwalker

Any body please





Re: Visual C++ General Info about Releasing COM1,2,3,4 ports explicitely using Windows API or C++ code. [HOW TO]?

Frank Boyne

The more detail you can provide, the more likely you are to find someone who knows the answer to your question.

For example, what functions are you calling to access a COM port and to release it again What happens when it won't let you acquire the port - do you get an error Exception Just hang in the function call Are you calling those functions from native C++ or from managed code via P/Invoke





Re: Visual C++ General Info about Releasing COM1,2,3,4 ports explicitely using Windows API or C++ code. [HOW TO]?

zenwalker

Hey,
As much info i know, i have given out. The WIN API has been made to get the COM port access. Once i get a change to aquire it through our project and in the second time, i cant. This happens randomly. But at only one time i can get an access to COM port. Yes as soon as my job is over with COM access, i am releasing it. And no, my project just tries to acquire COM port for 3 times, if WIN doesnt release it, then my project just drops out of loop. So hence i need the COM port to be manually handled by my code. And no exceptions i am getting. The project is using Standard WIN API umm... like User32.dll and Kernel32.dll and many more. So i exactly dont know, why COM port is not made free by WIN. So hence, i want to manage it manually.

Thanks.





Re: Visual C++ General Info about Releasing COM1,2,3,4 ports explicitely using Windows API or C++ code. [HOW TO]?

Simple Samples

Frank asked you a few questions, most or all that you can answer if you developed the program yourself. In particulr, you have not provided any of the function you are using. You just say you are using the SDK but it would be very easy for you to tell us specifically what functions you are using. In particular, what functions are you calling to access a COM port






Re: Visual C++ General Info about Releasing COM1,2,3,4 ports explicitely using Windows API or C++ code. [HOW TO]?

Paul Marriott

I have seen this with UPS software, it was scanning the COM ports looking for a UPS on a regular basis and if you happened to try to open a port when the UPS software was scanning, then you couldn't get it.

If you open a port and can't get a handle, GetLastError returns ACCESS_DENIED from memory to indicate the port is there, but in use by another program.

I dont know any way to grab a COM port to take it over, short of finding out the names of the processes that could have the port open and terminating them.





Re: Visual C++ General Info about Releasing COM1,2,3,4 ports explicitely using Windows API or C++ code. [HOW TO]?

zenwalker

No, i heavent developed the software. Its been developed long back. Now we are just improving it for more options and stuffs. So at the drvier level, i want to change the code, where i can acquire the COM manually. According to the code tracing done by me, all i know is, they are calling some User32.dll and Kernel32.dll methods like GetComPort(), i dont even know if this method is windows API or self done by the past developers. Unfortunately no one is avail here to have a reference.

Thanks