I was looking for getting a list of serial port available on my computer but I have not been able to find a thread which explain it.
I know, nobody wants to explain something (already posted) again however I will appreciate any help about FINDING this issue.
I have put "port list", "getting ports", but nothing happened. Besides, if I put port list (without quotes) then 2960 threads appear.
thank you SO much
Ivan Perino
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It turns out to be far harder than you would imagine. The first thing to do is to use an appropriate search term. What you are looking for is "serial port enumeration". You will find that in Win95/98/Me you have to read this information from the registry, Win2k and after you can use the SetupAPI ( http://msdn2.microsoft.com/en-us/library/ms791318.aspx )and even then it is cumbersome. NT4 which has little or no PnP support requires a 'brute-force' approach. An example of these methods is provided at http://www.codeguru.com/cpp/w-p/system/hardwareinformation/article.php/c5721/ . I have not looked at it in detail, but it at least uses MFC CString and CArray classes, so you cannot use it directly with Dev-C++. However if that is all the MFC dependency it has, it should not be too much trouble to port it to use C++ string and vector classes for example.
There is a far easier method: I have done this very recently and very easily. Unfortunately, if you really insist on using Dev-C++, the method I used is not possible. I used the .NET framework's System::IO.Ports::SerialPort::GetPortNames().
To be honest .NET's System::IO.Ports::SerialPort class is no much easier to use that just about any other Windows serial port API it may be worth switching tools to VC++ or C#. The use of .NET in C++ requires C++/CLI extensions to the language, so I chose to use C# which is a more natural fit for .NET.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
wow, I would never had imagined. thanks anyway, I will follow your advices as much as I can. ( I am an electronic Designer, not a programmer at all!)
I am using Delphi 2007 in C++ language (C++ Builder)
Thanks Again
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Since the serial ports normally have device names of the form "COMn:" with or without the colon and where n is a number >=1. It is common to simply attempt to open them sequentially and try to communicate with whatever device you expect (i.e. a brute force approach) and validate any response.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hello Masters:
I was looking for getting a list of serial port available on my computer but I have not been able to find a thread which explain it.
I know, nobody wants to explain something (already posted) again however I will appreciate any help about FINDING this issue.
I have put "port list", "getting ports", but nothing happened. Besides, if I put port list (without quotes) then 2960 threads appear.
thank you SO much
Ivan Perino
It turns out to be far harder than you would imagine. The first thing to do is to use an appropriate search term. What you are looking for is "serial port enumeration". You will find that in Win95/98/Me you have to read this information from the registry, Win2k and after you can use the SetupAPI ( http://msdn2.microsoft.com/en-us/library/ms791318.aspx )and even then it is cumbersome. NT4 which has little or no PnP support requires a 'brute-force' approach. An example of these methods is provided at http://www.codeguru.com/cpp/w-p/system/hardwareinformation/article.php/c5721/ . I have not looked at it in detail, but it at least uses MFC CString and CArray classes, so you cannot use it directly with Dev-C++. However if that is all the MFC dependency it has, it should not be too much trouble to port it to use C++ string and vector classes for example.
There is a far easier method: I have done this very recently and very easily. Unfortunately, if you really insist on using Dev-C++, the method I used is not possible. I used the .NET framework's System::IO.Ports::SerialPort::GetPortNames().
To be honest .NET's System::IO.Ports::SerialPort class is no much easier to use that just about any other Windows serial port API it may be worth switching tools to VC++ or C#. The use of .NET in C++ requires C++/CLI extensions to the language, so I chose to use C# which is a more natural fit for .NET.
Clifford
wow, I would never had imagined. thanks anyway, I will follow your advices as much as I can. ( I am an electronic Designer, not a programmer at all!)
I am using Delphi 2007 in C++ language (C++ Builder)
Thanks Again
Thank you very much Clifford, It was very useful.
I have not tested it yet but I will do as soon as possible.
Ok, then I would search on "C++ Builder serial port enumeration. Here http://www.codeproject.com/KB/system/serial_portsenum_fifo.aspx an example.
Since the serial ports normally have device names of the form "COMn:" with or without the colon and where n is a number >=1. It is common to simply attempt to open them sequentially and try to communicate with whatever device you expect (i.e. a brute force approach) and validate any response.
Clifford