PDA

View Full Version : How to Know Active COM port Dynamically



sudheer168
20th June 2009, 07:49
Hi,
I am using QT4.4 on windows to develop a GUI application which will communicate with a Electronic Unit (named data processing system) using MOXA USB which I have bought in market, they provide the drivers to make work.If I insert the USb cable and install the drivers of it ,it will be installed to that COM port (either it is COM1/COM2/COM3).Now I am using QExtSerialport library to make communicate through the USB. In this QExtSerialport library they provided member functions to set the COM and to open it .Now ,what I am doing is ,I am manually looking the system device drivers to make confirm in which COM the USB is installed and knowing this I am writing code as QExtserial port port->setCom (COM NAME).But I want to kknow Dynamically through Program ,that which Comport is active with MOXA USB .How can I know the COM number Dynamically to make that port open using QT.
So please help me to solve this problem .

With Regards
Sudheer

wysota
20th June 2009, 14:52
You can try opening each port in sequence and trying to communicate with the device until you succeed. I don't think there is a way to detect the proper port automatically in a general way.

sudheer168
22nd June 2009, 07:43
Thanks for your kind reply.
You asked me to see which port is open. I did it and got the all open ports list with names as COM1,COM2,COM3.In these three COMs how can I know which one is MOXA USB(the USB which I connected to system to communicate) .So here I definitely have to know the name of the USB port which is connected to the COM port.One thing is in system decice manager.. Ports(COM &LPT) it is showing both COM name and USB device name as MOXA USB Serial Port (COM2).
So please help me to solve the problem.

With Regards,
Sudheer.

wysota
22nd June 2009, 08:31
You have to use native API for this, if it allows to query for such information (which is doubtful).

sudheer168
22nd June 2009, 10:15
Thanks for your kind reply.If u don't mind please help me to get the name with a sample example code.


With Regards,
Sudheer.