Получилось!
Кому интересно: код функции, которая реализует посылку хостом команды Reset устройству.
В качестве параметра в нее передается USB product string descriptor устройства.
/////////////////////////////////////////////////////////////////////////////
#include "SetupApi.h"
#pragma comment(lib, "SetupApi")
bool ResetPortDevice(const char *Name);
// Name - USB product string descriptor
/////////////////////////////////////////////////////////////////////////////
bool ResetPortDevice(const char *Name) {
BOOL bRes;
LPGUID pClassGuidList, piClassGuidList;
DWORD i, j, need_size;
HDEVINFO DeviceInfoSet;
SP_DEVINFO_DATA DeviceInfoData;
SP_PROPCHANGE_PARAMS PropChange;
BYTE *pData;
pData = new BYTE[1+strlen(Name)];
if (!pData) return false;
// Request number of 'Ports' items
need_size = 0;
pClassGuidList = NULL;
SetupDiClassGuidsFromName("Ports", pClassGuidList, need_size, &need_size);
if (!need_size) {
delete [] pData;
return false;
}
// Request all 'Ports' items
piClassGuidList = pClassGuidList = new GUID[need_size];
if (!pClassGuidList) {
delete [] pData;
return false;
}
bRes = SetupDiClassGuidsFromName("Ports", pClassGuidList, need_size, &need_size);
if (!bRes) {
delete [] pData;
delete [] pClassGuidList;
return false;
}
// Loop by all GUIDs
for (i = 0; i < need_size; i++, pClassGuidList++) {
// Get list of devices
DeviceInfoSet = SetupDiGetClassDevs(pClassGuidList, NULL, NULL, DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE) continue;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
PropChange.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
PropChange.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChange.StateChange = DICS_PROPCHANGE; // For reset !!!
PropChange.Scope = DICS_FLAG_CONFIGSPECIFIC;
PropChange.HwProfile = 0;
// Loop by all devices by given GUID
for (j = 0; SetupDiEnumDeviceInfo(DeviceInfoSet, j, &DeviceInfoData); j++) {
if (GetLastError() == ERROR_NO_MORE_ITEMS) break;
// Try get extended information
bRes = SetupDiGetDeviceRegistryProperty(DeviceInfoSet, &DeviceInfoData, SPDRP_LOCATION_INFORMATION, NULL, pData, 1+strlen(Name), NULL);
if (!bRes) continue;
if (strstr((const char *)pData, Name) == NULL) continue;
// Apply function for the found device (i.e. Reset)
bRes = SetupDiSetClassInstallParams(DeviceInfoSet, &DeviceInfoData, &PropChange.ClassInstallHeader, sizeof(PropChange));
if (!bRes) break;
bRes = SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DeviceInfoSet, &DeviceInfoData);
if (!bRes) break;
}
// Clear list of devices
bRes = SetupDiDestroyDeviceInfoList(DeviceInfoSet);
if (!bRes) break;
}
// Clear arrays
delete [] piClassGuidList;
delete [] pData;
if (!bRes) return false;
return true;
}
/////////////////////////////////////////////////////////////////////////////