Menu

how to find OR getting a port list

2008-01-08
2012-09-26
  • ivan perino

    ivan perino - 2008-01-08

    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

     
    • cpns

      cpns - 2008-01-08

      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

       
    • ivan perino

      ivan perino - 2008-01-08

      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

       
    • ivan perino

      ivan perino - 2008-01-09

      Thank you very much Clifford, It was very useful.
      I have not tested it yet but I will do as soon as possible.

       
    • cpns

      cpns - 2008-01-08

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.