//枚举机器串口个数
int EnumerateCOMPort()
{
int portcnt = 0;
TCHAR port[MAX_PATH];
COMMCONFIG comcfg;
ULONG BuffSize = sizeof(port);
for (int i = 1; i < 255 ; i++)
{
_stprintf(port,_T( "COM%d "),i);
BuffSize = sizeof(port);
if (GetDefaultCommConfig(port,&comcfg,&BuffSize))
portcnt ++;
memset(port,0,sizeof(port));
}
TRACE(_T( "/nThis computer has %d COM/n "),portcnt);
return portcnt;
}