-1

我想在 VC++ 代码中打开高于 9 的 comport。以下代码可以打开高于9的comport。但是,我在组合框中得到的结果是“\.\COM10”。我不想在组合框中的 COM 名称之前出现“\.\”。请帮我解决这个问题。我的代码:

CString str;
int i;
for(i=1;i<30;i++)
{
    str.Format("\\\\.\\COM%d",i);
    ptrLC->comPort.CloseCommPort();

    if(ptrLC->comPort.OpenCommPort(str))
    {
        m_cCommPort.AddString(str);
        ptrLC->comPort.CloseCommPort();
    }
 }
4

1 回答 1

0

感谢您的贡献...上述问题已解决。我对上面的代码进行了更改,这有助于我打开高于 9 的 comport。而且组合框下拉列表在 COM 名称之前不包含 \.\。

更正的代码:

CString str, str1;
int i;
for(i=1;i<30;i++)
{
str.Format("COM%d",i);
ptrLC->comPort.CloseCommPort();

str1 = "\\\\.\\" + str;     // this is a I/O string format which helps to open comport higher than 9. 

if(ptrLC->comPort.OpenCommPort(str1))
{
    m_cCommPort.AddString(str);
    ptrLC->comPort.CloseCommPort();
}
}
于 2018-03-15T04:12:46.897 回答