diff --git a/device/hgscanner.vcxproj b/device/hgscanner.vcxproj index 1d68b79..ec4dca9 100644 --- a/device/hgscanner.vcxproj +++ b/device/hgscanner.vcxproj @@ -1,4 +1,4 @@ - + @@ -73,14 +73,14 @@ true $(SolutionDir)..\..\code_device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\opencv\include\win;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\code_device\sdk\;$(SolutionDir)..\..\code_device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\code_device\hgdriver\hgdev\;$(SolutionDir)..\..\code_device\hgdriver\wrapper\;$(ProjectDir);$(IncludePath) - $(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath) + $(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath) $(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\ $(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\ false $(SolutionDir)..\..\code_device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\opencv\include\win;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\code_device\sdk\;$(SolutionDir)..\..\code_device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\code_device\hgdriver\hgdev\;$(SolutionDir)..\..\code_device\hgdriver\wrapper\;$(ProjectDir);$(IncludePath) - $(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath) + $(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath) $(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\ $(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\ @@ -311,6 +311,12 @@ move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$ + + + + + + diff --git a/device/hgscanner.vcxproj.filters b/device/hgscanner.vcxproj.filters index 5b564a2..56fd8b4 100644 --- a/device/hgscanner.vcxproj.filters +++ b/device/hgscanner.vcxproj.filters @@ -356,6 +356,24 @@ 头文件 + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + diff --git a/device/win_usb/usbview/enum.c b/device/win_usb/usbview/enum.c index dc4dfbe..51a7e62 100644 --- a/device/win_usb/usbview/enum.c +++ b/device/win_usb/usbview/enum.c @@ -3374,20 +3374,20 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) BOOL success = 0; HRESULT hr = S_OK; PCHAR driverKeyName = NULL; - PUSB_DEVICE_PNP_STRINGS DevProps; + PUSB_DEVICE_PNP_STRINGS DevProps = NULL; DWORD dwSizeOfLeafName = 0; - CHAR leafName[512]; + CHAR leafName[512] = { 0 }; int icon = 0; - PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfoEx; - PUSB_PORT_CONNECTOR_PROPERTIES pPortConnectorProps; - USB_PORT_CONNECTOR_PROPERTIES portConnectorProps; - PUSB_DESCRIPTOR_REQUEST configDesc; - PUSB_DESCRIPTOR_REQUEST bosDesc; - PSTRING_DESCRIPTOR_NODE stringDescs; - PUSBDEVICEINFO info; - PUSB_NODE_CONNECTION_INFORMATION_EX_V2 connectionInfoExV2; - PDEVICE_INFO_NODE pNode; + PUSBDEVICEINFO info = NULL; + PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfoEx = NULL; + PUSB_PORT_CONNECTOR_PROPERTIES pPortConnectorProps = NULL; + USB_PORT_CONNECTOR_PROPERTIES portConnectorProps = { 0 }; + PUSB_DESCRIPTOR_REQUEST configDesc = NULL; + PUSB_DESCRIPTOR_REQUEST bosDesc = NULL; + PSTRING_DESCRIPTOR_NODE stringDescs = NULL; + PUSB_NODE_CONNECTION_INFORMATION_EX_V2 connectionInfoExV2 = NULL; + PDEVICE_INFO_NODE pNode = NULL; // Loop over all ports of the hub. // @@ -3395,21 +3395,10 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) // //for (index = 1; index <= NumPorts; index++) { - ULONG nBytesEx; + ULONG usb_pipes = 30; + ULONG nBytesEx = sizeof(USB_NODE_CONNECTION_INFORMATION_EX) + (sizeof(USB_PIPE_INFO) * usb_pipes); ULONG nBytes = 0; - connectionInfoEx = NULL; - pPortConnectorProps = NULL; - ZeroMemory(&portConnectorProps, sizeof(portConnectorProps)); - configDesc = NULL; - bosDesc = NULL; - stringDescs = NULL; - info = NULL; - connectionInfoExV2 = NULL; - pNode = NULL; - DevProps = NULL; - ZeroMemory(leafName, sizeof(leafName)); - // // Allocate space to hold the connection info for this port. // For now, allocate it big enough to hold info for 30 pipes. @@ -3422,12 +3411,7 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) // // Should probably size this dynamically at some point. // - - nBytesEx = sizeof(USB_NODE_CONNECTION_INFORMATION_EX) + - (sizeof(USB_PIPE_INFO) * 30); - connectionInfoEx = (PUSB_NODE_CONNECTION_INFORMATION_EX)ALLOC(nBytesEx); - if (connectionInfoEx == NULL) { OOPS(); @@ -3435,9 +3419,7 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) return NULL; } - connectionInfoExV2 = (PUSB_NODE_CONNECTION_INFORMATION_EX_V2) - ALLOC(sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2)); - + connectionInfoExV2 = (PUSB_NODE_CONNECTION_INFORMATION_EX_V2)ALLOC(sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2)); if (connectionInfoExV2 == NULL) { OOPS(); @@ -3453,7 +3435,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) // portConnectorProps.ConnectionIndex = index; - success = DeviceIoControl(hHubDevice, IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES, &portConnectorProps, @@ -3465,13 +3446,11 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) if (success && nBytes == sizeof(USB_PORT_CONNECTOR_PROPERTIES)) { - pPortConnectorProps = (PUSB_PORT_CONNECTOR_PROPERTIES) - ALLOC(portConnectorProps.ActualLength); + pPortConnectorProps = (PUSB_PORT_CONNECTOR_PROPERTIES)ALLOC(portConnectorProps.ActualLength); if (pPortConnectorProps != NULL) { pPortConnectorProps->ConnectionIndex = index; - success = DeviceIoControl(hHubDevice, IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES, pPortConnectorProps, @@ -3480,7 +3459,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) portConnectorProps.ActualLength, &nBytes, NULL); - if (!success || nBytes < portConnectorProps.ActualLength) { FREE(pPortConnectorProps); @@ -3492,7 +3470,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) connectionInfoExV2->ConnectionIndex = index; connectionInfoExV2->Length = sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2); connectionInfoExV2->SupportedUsbProtocols.Usb300 = 1; - success = DeviceIoControl(hHubDevice, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX_V2, connectionInfoExV2, @@ -3501,7 +3478,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2), &nBytes, NULL); - if (!success || nBytes < sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2)) { FREE(connectionInfoExV2); @@ -3509,7 +3485,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) } connectionInfoEx->ConnectionIndex = index; - success = DeviceIoControl(hHubDevice, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, connectionInfoEx, @@ -3518,7 +3493,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) nBytesEx, &nBytesEx, NULL); - if (success) { // @@ -3545,11 +3519,8 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) // instead of IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX // - nBytes = sizeof(USB_NODE_CONNECTION_INFORMATION) + - sizeof(USB_PIPE_INFO) * 30; - + nBytes = sizeof(USB_NODE_CONNECTION_INFORMATION) + sizeof(USB_PIPE_INFO) * usb_pipes; connectionInfo = (PUSB_NODE_CONNECTION_INFORMATION)ALLOC(nBytes); - if (connectionInfo == NULL) { OOPS(); @@ -3568,7 +3539,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) } connectionInfo->ConnectionIndex = index; - success = DeviceIoControl(hHubDevice, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION, connectionInfo, @@ -3608,9 +3578,7 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index) connectionInfoEx->NumberOfOpenPipes = connectionInfo->NumberOfOpenPipes; connectionInfoEx->ConnectionStatus = connectionInfo->ConnectionStatus; - memcpy(&connectionInfoEx->PipeList[0], - &connectionInfo->PipeList[0], - sizeof(USB_PIPE_INFO) * 30); + memcpy(&connectionInfoEx->PipeList[0], &connectionInfo->PipeList[0], sizeof(USB_PIPE_INFO) * usb_pipes); FREE(connectionInfo); } @@ -3845,9 +3813,9 @@ void free_usb_device_info(PUSBDEVICEINFO pudi) if (pudi->ConnectionInfoV2) FREE(pudi->ConnectionInfoV2); if (pudi->UsbDeviceProperties) - FREE(pudi->UsbDeviceProperties); - if (pudi->DeviceInfoNode) - FREE(pudi->DeviceInfoNode); + FreeDeviceProperties(&pudi->UsbDeviceProperties); + //if (pudi->DeviceInfoNode) + // FREE(pudi->DeviceInfoNode); FREE(pudi); } diff --git a/device/win_usb/win_usb.cpp b/device/win_usb/win_usb.cpp index e872ed4..3a23e4a 100644 --- a/device/win_usb/win_usb.cpp +++ b/device/win_usb/win_usb.cpp @@ -653,6 +653,9 @@ int usb_device::transfer_bulk(unsigned endpoint, unsigned char* data, int* lengt BOOL result = FALSE; HANDLE he = ovl->hEvent; + if (!GetOverlappedResult(h, ovl, &io, FALSE) && GetLastError() == ERROR_IO_INCOMPLETE) + return LIBUSB_ERROR_BUSY; + memset(ovl, 0, sizeof(*ovl)); ovl->hEvent = he; result = fio(h, data, *length, &io, ovl); @@ -667,10 +670,12 @@ int usb_device::transfer_bulk(unsigned endpoint, unsigned char* data, int* lengt io = GetLastError(); if (io == ERROR_IO_PENDING) { - WaitForSingleObject(he, 500); - GetOverlappedResult(h, &ovl_[OVL_BULK_IN], &io, FALSE); - *length = io; - ret = LIBUSB_SUCCESS; + if (WaitForSingleObject(he, timeout) == WAIT_OBJECT_0) + { + GetOverlappedResult(h, ovl, &io, FALSE); + *length = io; + ret = LIBUSB_SUCCESS; + } } } } @@ -928,7 +933,6 @@ void usb_monitor::thread_run_device_event_wnd(void) wnd_monitor_ = CreateWindowW(cls, L"usb", WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandleW(NULL), this); if (!IsWindow(wnd_monitor_)) { - // HG_VLOG_MINI_1(HG_LOG_LEVEL_FATAL, "create monitor window failed: %d\n", GetLastError()); if(run_) Sleep(1000); @@ -954,14 +958,10 @@ void usb_monitor::thread_run_device_event_wnd(void) dbh.dbch_devicetype = DBT_DEVTYP_DEVICEINTERFACE; notify = RegisterDeviceNotificationW(wnd_monitor_, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); ret = GetLastError(); - // find_usb(); while (run_ && (ret = GetMessageW(&msg, wnd_monitor_, 0, 0))) { if (ret == -1) - { - // HG_VLOG_MINI_1(HG_LOG_LEVEL_FATAL, "GetMessageW returned -1 with error: %d\n", GetLastError()); break; - } TranslateMessage(&msg); DispatchMessageW(&msg);