我想在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();
}
}
感谢您的贡献...上述问题已解决。我对上面的代码进行了更改,这有助于我打开高于 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();
}
}