110,535
社区成员
发帖
与我相关
我的任务
分享
device = CreateFile(deviceList[i], DESIREDACCESS.GENERIC_READ | DESIREDACCESS.GENERIC_WRITE, 0, 0, CREATIONDISPOSITION.OPEN_EXISTING, FLAGSANDATTRIBUTES.FILE_FLAG_OVERLAPPED, 0);
if (!device.IsInvalid)
{ // strDevicePath = GetDevicePath(hInfoSet, ref oInterface);
HIDD_ATTRIBUTES attributes;
//IntPtr serialBuff = Marshal.AllocHGlobal(512);
HidD_GetAttributes(device, out attributes);
//HidD_GetSerialNumberString(device, serialBuff, 512);
//string deviceStr = Marshal.PtrToStringAuto(serialBuff);
//Marshal.FreeHGlobal(serialBuff);
if (attributes.VendorID == vID && attributes.ProductID == pID) // && deviceStr == serial
{
IntPtr preparseData;
HIDP_CAPS caps;
HidD_GetPreparsedData(device, out preparseData);
HidP_GetCaps(preparseData, out caps);
HidD_FreePreparsedData(preparseData);
outputReportLength = caps.OutputReportByteLength;
inputReportLength = caps.InputReportByteLength;
hidDevice = new FileStream (device, FileAccess.ReadWrite, inputReportLength, true);
deviceOpened = true;
//BeginAsyncRead();
Guid gHid = HIDGuid;
IntPtr hInfoSet = SetupDiGetClassDevs(ref gHid, null, IntPtr.Zero, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
DeviceInterfaceData oInterface = new DeviceInterfaceData();
strDevicePath = GetDevicePath(hInfoSet, ref oInterface);
return HID_RETURN.SUCCESS;
}
}
这个IF语句总是进不去能帮忙解释一下吗?