Serial port enumeration for BCB version

I have been doing automatic control for nearly 20 years, and I cannot do without serial communication. Originally, when it was necessary to obtain the serial port of the computer, the method of reading the registry was used, which has always been used normally. Unless computer system problems cause redundant virtual serial ports or usb serial port numbers, just clean up the registry:

 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control \COM Name Arbiter,
 Just delete the value item ComDB.

However, with the expansion of our business, our customers are becoming more and more high-end, and our software requirements have also made higher requirements in terms of details (so-called intelligence), so I have always wanted to find a better one Give the computer serial port method.

Later, I saw that chinayu2007 , a colleague of industrial control, released a method to enumerate serial ports. I tried it and found that there should be no serial ports, and there should be no serial ports. See the source code: EnumPorts enumerates the current computer ports
operation result:


Description: The real serial port of my computer is com1, and the virtual serial port com8---14:


In the past two days, I accidentally browsed a foreigner website and saw an enumeration serial port program released in 2005. It was also bcb6.0 version and downloaded it and tried it. Very good, the serial ports that the computer should have:


Download address : BCB serial port enumeration


It seems that it is not very noble to carry others, and I created my own method of sorting com numbers. Because the serial port numbers enumerated are not arranged according to com1/2/3----from small to large, you have to process them yourself.

My own method is the container, which releases the source program that has been enumerated and sorted using the registry:

#include <Registry.hpp>
#include <vector>
using namespace std;


   vector <int> com;
    TStringList* List=new TStringList();
    TRegistry *reg = new TRegistry;
    reg->RootKey = HKEY_LOCAL_MACHINE;
    reg->OpenKey("HARDWARE\\DEVICEMAP\\SERIALCOMM",true);
    reg->GetValueNames(List);
    ComboBox1->Items->Clear();

    for(int i=0;i<List->Count;i++)
    {
        com.push_back((reg->ReadString(List->Strings[i])).Delete(1,3).ToInt());
    }
    sort (com.begin (), com.end ());
    for(unsigned int i=0;i<com.size();i++)
    {
        ComboBox1->Items->Add("COM"+IntToStr(com[i]));
    }

    delete reg;
    delete List;
    ComboBox1->ItemIndex = 0;

No comments, no extra words.


Salute to colleagues who are still sticking to bcb6.0!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325800429&siteId=291194637