CodePudding user response:
Why not VID=4 b4, PID=DB30 this usb deviceCodePudding user response:
PSP_DEVICE_INTERFACE_DETAIL_DATA HID_FindDevices (USHORT V_ID, USHORT P_ID, unsigned short * FIFO_Length);
Int main ()
{
USHORT VID=0 x04b4;
USHORT PID=0 xdb30;
Unsigned short * FIFO_Length=0;
HDEVINFO m_USB;
PSP_DEVICE_INTERFACE_DETAIL_DATA DevDetail;
DevDetail=HID_FindDevices (VID and PID, FIFO_Length);
If (DevDetail==NULL)
{
STD: : cout & lt; <"Access to equipment failure!"
The else
{
M_USB=CreateFile (DevDetail - & gt; DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
0 x40000000,
NULL
);
If (m_USB==INVALID_HANDLE_VALUE)
{
STD: : cout & lt; <"Open!"
The else
{
STD: : cout & lt; <"Open the success!"
The CloseHandle (m_USB);
}
return 0;
}
PSP_DEVICE_INTERFACE_DETAIL_DATA HID_FindDevices (USHORT V_ID, USHORT P_ID, unsigned short * FIFO_Length)
{
Xc465 x36fc9e60 GUID HidGuid={0, 0, 0 x11cf, 0 x8056, 0 x444553540000};
//HKEY_LOCAL_MACHINE \ SYSTEM \ ControlSet001 \ Control \ DeviceClasses \ {a5dcbf10-6530-11-901 - f - 00 c04fb951ed d2}
X6530 xa5dcbf10 GUID HidGuid2={0, 0, 0 x11d2, 0 x90, 0 x1f, 0 x00 to 0 xc0, 0 x4f, 0 xb9, 0 x51, 0 xed};
HDEVINFO DevInfo;
HIDD_ATTRIBUTES DevAttributes;
SP_DEVICE_INTERFACE_DATA DevData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DevDetail;
PHIDP_PREPARSED_DATA PreparsedData;
HIDP_CAPS "Capabilities;
ULONG Length;
Int Index;
DWORD k;
BOOL ok;
HANDLE DevHandle;
Int DevCount=0;
/* Get GUID for all System HIDs that works */
//HidD_GetHidGuid (& amp; HidGuid);
/* Get Device Information for all the present devices */
DevInfo=SetupDiGetClassDevs (& amp; HidGuid2,
NULL,
NULL,
(DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)
);
K=GetLastError ();
If (DevInfo==NULL)
{
STD: : cout & lt; <"Access equipment set k=" & lt;
}
DevData. CbSize=sizeof (DevData);
DevDetail=NULL;
The Index=1;
//* FIFO_Length=0;
Scan all Devices *//*
Do {
Index++;
/* Device Interface Element of a Device Information set */
Ok=SetupDiEnumDeviceInterfaces (DevInfo,
0,
& HidGuid2,
The Index,
& DevData
);
K=GetLastError ();
STD: : cout & lt; <"K=" & lt;
/* Get Device Interface Details - Get Length */
Ok=SetupDiGetDeviceInterfaceDetail (DevInfo,
& DevData,
NULL,
0,
& Length,
NULL
);
/* the Allocate memory for Device the Detailed Data */
DevDetail=(PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc (Length);
/* Set cbSize in the DevDetail structure */
DevDetail - & gt; The cbSize=sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA);
/* Get Device Interface Details */
Ok=SetupDiGetDeviceInterfaceDetail (DevInfo,
& DevData,
DevDetail,
Length,
NULL,
NULL
);
if (! Ok)
{
Free (DevDetail);
DevDetail=NULL;
continue;
}
/* Create a File for Device the Read/Write */
DevHandle=CreateFile (DevDetail - & gt; DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
0,
NULL
);
If (DevHandle==INVALID_HANDLE_VALUE)
{
STD: : cout & lt; <"Open!"
DevDetail=NULL;
continue;
}
STD: : cout & lt; <"Open the success!"
Ok=HidD_GetAttributes (DevHandle, & amp; DevAttributes);
if (! Ok)
{
K=GetLastError ();
STD: : cout & lt; <"HidD_GetAttributesk=" & lt;
The CloseHandle (DevHandle);
DevDetail=NULL;
continue;
}
STD: : cout & lt; <"VID=" & lt;
{
Free (DevDetail);
The CloseHandle (DevHandle);
DevDetail=NULL;
continue;
}
/* Get Preparsed Data */
Ok=HidD_GetPreparsedData (DevHandle, & amp; PreparsedData);
if (! Ok)
{
Free (DevDetail); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull