¿Cómo identifica VC6.+ el puerto COM USB?
#¿Contiene? <stdio.h>?
#¿Incluir? <windows.h>?
#¿Incluir? <setupapi.h>?
#¿Incluir? <devguid.h>?
¿#pragma? comentario(lib,?"setupapi")?
int? principal(int?argc,?char*?argv[])?
{?
//?¿Obtener información del dispositivo configurada?
¿HDEVINFO? hDevInfo? =?SetupDiGetClassDevs(?
(lpg uid)&GUID_DEVCLASS_PORTS,?
NULL,?
0,?
DIGCF_PRESENT / *? |?DIGCF _ todas las clases */);?
¿Y si? (hDevInfo?==?invalid_handle_value)?
{?
printf("¿¡Error!? ¿SetupDiGetClassDevs()? ¿Regresión? %d\n ", GetLastError());?
SetupDiDestroyDeviceInfoList(hde info);?
¿Volver? 0;?
}?
TCHAR? SZ buf[MAX_PATH];?
¿SP_DEVINFO_DATA? spDevInfoData? =?{ tamaño de (SP _ DEVINFO _ DATA)};?
//?¿Comenzar a enumerar dispositivos?
¿DWORD? ¿I? =?0;
¿Para qué? (?i?=?0;?SetupDiEnumDeviceInfo(hDevInfo,?i,?&spDevInfoData);?i++)?
{?
//?¿Obtener descripción de categoría de dispositivo?
¿Y si? (?SetupDiGetClassDescription(?
& ampspDevInfoData.
Guía de clases,?
szBuf,?
MAX_PATH,?
¿NULL)? )?
{?
_tprintf("\n%03d?:?Descripción de categoría?=?%s\n ",I,?szBuf);?
}?
//?¿Obtener el ID de identificación único de la instancia del dispositivo (compuesto por la ruta del registro)?
¿Y si? (?SetupDiGetDeviceInstanceId(?
hDevInfo,?
& ampspDevInfoData,?
szBuf,?
MAX_PATH,?
NULL)? )?
{?
printf("%03d?:?InstanceId?=?%s\n ",I,?szBuf);?
}?
//?¿Obtener el nombre del dispositivo?
¿Y si? (?SetupDiGetDeviceRegistryProperty(?
hDevInfo,?
&spDevInfoData,?
SPDRP_DEVICEDESC,?
NULL,?
szBuf?
MAX_PATH,?
NULL)?
printf("%03d?: ?DeviceDesc? =?%s\n ",i ,?szBuf);?
}?
//?¿Obtienes el modelo del dispositivo?
¿Y si? (?SetupDiGetDeviceRegistryProperty(?
hDevInfo,?
& ampspDevInfoData,?
SPDRP_FRIENDLYNAME,?
NULL,?
szBuf?
MAX_PATH,?
NULL)?
printf("%03d?: ?FriendName? =?%s\n ", Yo,?szBuf);?
}?
//?¿Obtener la subruta del dispositivo en el registro?
¿Y si? (?SetupDiGetDeviceRegistryProperty(?
hDevInfo,?
&spDevInfoData,?
SPDRP_DRIVER,?
NULL,?
szBuf?
MAX_PATH,?
NULL)?
printf("%03d?: ?Regedit?=?%s\n",? szBuf);?
}?
}?
printf("\nPortcount?=?%d\n ",I);?
getchar();?
¿Volver? 0;?
}Este es un ejemplo estándar, puede consultar el uso de funciones.
Su requisito es en realidad atravesar el puerto serie y luego identificar el dispositivo a través de DeviceDesc.