add OCR; IO on USB has problem yet, should rewrite it.

This commit is contained in:
gb 2022-05-16 13:52:27 +08:00
parent e692886e0b
commit 3d2f54f113
4 changed files with 56 additions and 64 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
@ -73,14 +73,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>$(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)</IncludePath> <IncludePath>$(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)</IncludePath>
<LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath> <LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir> <IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir> <OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<IncludePath>$(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)</IncludePath> <IncludePath>$(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)</IncludePath>
<LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath> <LibraryPath>$(ProjectDir)lib\$(PlatformTarget)\$(Configuration);$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath)</LibraryPath>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir> <IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir> <OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\$(Configuration)\</OutDir>
</PropertyGroup> </PropertyGroup>
@ -311,6 +311,12 @@ move /Y "$(OutDirFullPath)$(ProjectName).pdb" "$(SolutionDir)..\..\sdk\lib\win\$
<ClInclude Include="..\..\sdk\hginclude\hgscanner_error.h" /> <ClInclude Include="..\..\sdk\hginclude\hgscanner_error.h" />
<ClInclude Include="..\..\sdk\hginclude\hg_log.h" /> <ClInclude Include="..\..\sdk\hginclude\hg_log.h" />
<ClInclude Include="..\..\sdk\hginclude\huagaoxxx_warraper_ex.h" /> <ClInclude Include="..\..\sdk\hginclude\huagaoxxx_warraper_ex.h" />
<ClInclude Include="..\..\sdk\include\sane\sane.h" />
<ClInclude Include="..\..\sdk\include\sane\sanei.h" />
<ClInclude Include="..\..\sdk\include\sane\sanei_backend.h" />
<ClInclude Include="..\..\sdk\include\sane\sanei_debug.h" />
<ClInclude Include="..\..\sdk\include\sane\sane_ex.h" />
<ClInclude Include="..\..\sdk\include\sane\sane_option_definitions.h" />
<ClInclude Include="win_usb\usbview\enum.h" /> <ClInclude Include="win_usb\usbview\enum.h" />
<ClInclude Include="win_usb\usbview\usbdesc.h" /> <ClInclude Include="win_usb\usbview\usbdesc.h" />
<ClInclude Include="win_usb\usbview\uvcdesc.h" /> <ClInclude Include="win_usb\usbview\uvcdesc.h" />

View File

@ -356,6 +356,24 @@
<ClInclude Include="..\..\code_device\hgdriver\hgdev\char_const.h"> <ClInclude Include="..\..\code_device\hgdriver\hgdev\char_const.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sane.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sane_ex.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sanei.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sanei_backend.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sanei_debug.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\..\sdk\include\sane\sane_option_definitions.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="device.def"> <None Include="device.def">

View File

@ -3374,20 +3374,20 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
BOOL success = 0; BOOL success = 0;
HRESULT hr = S_OK; HRESULT hr = S_OK;
PCHAR driverKeyName = NULL; PCHAR driverKeyName = NULL;
PUSB_DEVICE_PNP_STRINGS DevProps; PUSB_DEVICE_PNP_STRINGS DevProps = NULL;
DWORD dwSizeOfLeafName = 0; DWORD dwSizeOfLeafName = 0;
CHAR leafName[512]; CHAR leafName[512] = { 0 };
int icon = 0; int icon = 0;
PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfoEx; PUSBDEVICEINFO info = NULL;
PUSB_PORT_CONNECTOR_PROPERTIES pPortConnectorProps; PUSB_NODE_CONNECTION_INFORMATION_EX connectionInfoEx = NULL;
USB_PORT_CONNECTOR_PROPERTIES portConnectorProps; PUSB_PORT_CONNECTOR_PROPERTIES pPortConnectorProps = NULL;
PUSB_DESCRIPTOR_REQUEST configDesc; USB_PORT_CONNECTOR_PROPERTIES portConnectorProps = { 0 };
PUSB_DESCRIPTOR_REQUEST bosDesc; PUSB_DESCRIPTOR_REQUEST configDesc = NULL;
PSTRING_DESCRIPTOR_NODE stringDescs; PUSB_DESCRIPTOR_REQUEST bosDesc = NULL;
PUSBDEVICEINFO info; PSTRING_DESCRIPTOR_NODE stringDescs = NULL;
PUSB_NODE_CONNECTION_INFORMATION_EX_V2 connectionInfoExV2; PUSB_NODE_CONNECTION_INFORMATION_EX_V2 connectionInfoExV2 = NULL;
PDEVICE_INFO_NODE pNode; PDEVICE_INFO_NODE pNode = NULL;
// Loop over all ports of the hub. // 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++) //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; 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. // Allocate space to hold the connection info for this port.
// For now, allocate it big enough to hold info for 30 pipes. // 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. // 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); connectionInfoEx = (PUSB_NODE_CONNECTION_INFORMATION_EX)ALLOC(nBytesEx);
if (connectionInfoEx == NULL) if (connectionInfoEx == NULL)
{ {
OOPS(); OOPS();
@ -3435,9 +3419,7 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
return NULL; return NULL;
} }
connectionInfoExV2 = (PUSB_NODE_CONNECTION_INFORMATION_EX_V2) connectionInfoExV2 = (PUSB_NODE_CONNECTION_INFORMATION_EX_V2)ALLOC(sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2));
ALLOC(sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2));
if (connectionInfoExV2 == NULL) if (connectionInfoExV2 == NULL)
{ {
OOPS(); OOPS();
@ -3453,7 +3435,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
// //
portConnectorProps.ConnectionIndex = index; portConnectorProps.ConnectionIndex = index;
success = DeviceIoControl(hHubDevice, success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES, IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES,
&portConnectorProps, &portConnectorProps,
@ -3465,13 +3446,11 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
if (success && nBytes == sizeof(USB_PORT_CONNECTOR_PROPERTIES)) if (success && nBytes == sizeof(USB_PORT_CONNECTOR_PROPERTIES))
{ {
pPortConnectorProps = (PUSB_PORT_CONNECTOR_PROPERTIES) pPortConnectorProps = (PUSB_PORT_CONNECTOR_PROPERTIES)ALLOC(portConnectorProps.ActualLength);
ALLOC(portConnectorProps.ActualLength);
if (pPortConnectorProps != NULL) if (pPortConnectorProps != NULL)
{ {
pPortConnectorProps->ConnectionIndex = index; pPortConnectorProps->ConnectionIndex = index;
success = DeviceIoControl(hHubDevice, success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES, IOCTL_USB_GET_PORT_CONNECTOR_PROPERTIES,
pPortConnectorProps, pPortConnectorProps,
@ -3480,7 +3459,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
portConnectorProps.ActualLength, portConnectorProps.ActualLength,
&nBytes, &nBytes,
NULL); NULL);
if (!success || nBytes < portConnectorProps.ActualLength) if (!success || nBytes < portConnectorProps.ActualLength)
{ {
FREE(pPortConnectorProps); FREE(pPortConnectorProps);
@ -3492,7 +3470,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
connectionInfoExV2->ConnectionIndex = index; connectionInfoExV2->ConnectionIndex = index;
connectionInfoExV2->Length = sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2); connectionInfoExV2->Length = sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2);
connectionInfoExV2->SupportedUsbProtocols.Usb300 = 1; connectionInfoExV2->SupportedUsbProtocols.Usb300 = 1;
success = DeviceIoControl(hHubDevice, success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX_V2, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX_V2,
connectionInfoExV2, connectionInfoExV2,
@ -3501,7 +3478,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2), sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2),
&nBytes, &nBytes,
NULL); NULL);
if (!success || nBytes < sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2)) if (!success || nBytes < sizeof(USB_NODE_CONNECTION_INFORMATION_EX_V2))
{ {
FREE(connectionInfoExV2); FREE(connectionInfoExV2);
@ -3509,7 +3485,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
} }
connectionInfoEx->ConnectionIndex = index; connectionInfoEx->ConnectionIndex = index;
success = DeviceIoControl(hHubDevice, success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX,
connectionInfoEx, connectionInfoEx,
@ -3518,7 +3493,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
nBytesEx, nBytesEx,
&nBytesEx, &nBytesEx,
NULL); NULL);
if (success) if (success)
{ {
// //
@ -3545,11 +3519,8 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
// instead of IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX // instead of IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX
// //
nBytes = sizeof(USB_NODE_CONNECTION_INFORMATION) + nBytes = sizeof(USB_NODE_CONNECTION_INFORMATION) + sizeof(USB_PIPE_INFO) * usb_pipes;
sizeof(USB_PIPE_INFO) * 30;
connectionInfo = (PUSB_NODE_CONNECTION_INFORMATION)ALLOC(nBytes); connectionInfo = (PUSB_NODE_CONNECTION_INFORMATION)ALLOC(nBytes);
if (connectionInfo == NULL) if (connectionInfo == NULL)
{ {
OOPS(); OOPS();
@ -3568,7 +3539,6 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
} }
connectionInfo->ConnectionIndex = index; connectionInfo->ConnectionIndex = index;
success = DeviceIoControl(hHubDevice, success = DeviceIoControl(hHubDevice,
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,
connectionInfo, connectionInfo,
@ -3608,9 +3578,7 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
connectionInfoEx->NumberOfOpenPipes = connectionInfo->NumberOfOpenPipes; connectionInfoEx->NumberOfOpenPipes = connectionInfo->NumberOfOpenPipes;
connectionInfoEx->ConnectionStatus = connectionInfo->ConnectionStatus; connectionInfoEx->ConnectionStatus = connectionInfo->ConnectionStatus;
memcpy(&connectionInfoEx->PipeList[0], memcpy(&connectionInfoEx->PipeList[0], &connectionInfo->PipeList[0], sizeof(USB_PIPE_INFO) * usb_pipes);
&connectionInfo->PipeList[0],
sizeof(USB_PIPE_INFO) * 30);
FREE(connectionInfo); FREE(connectionInfo);
} }
@ -3845,9 +3813,9 @@ void free_usb_device_info(PUSBDEVICEINFO pudi)
if (pudi->ConnectionInfoV2) if (pudi->ConnectionInfoV2)
FREE(pudi->ConnectionInfoV2); FREE(pudi->ConnectionInfoV2);
if (pudi->UsbDeviceProperties) if (pudi->UsbDeviceProperties)
FREE(pudi->UsbDeviceProperties); FreeDeviceProperties(&pudi->UsbDeviceProperties);
if (pudi->DeviceInfoNode) //if (pudi->DeviceInfoNode)
FREE(pudi->DeviceInfoNode); // FREE(pudi->DeviceInfoNode);
FREE(pudi); FREE(pudi);
} }

View File

@ -653,6 +653,9 @@ int usb_device::transfer_bulk(unsigned endpoint, unsigned char* data, int* lengt
BOOL result = FALSE; BOOL result = FALSE;
HANDLE he = ovl->hEvent; HANDLE he = ovl->hEvent;
if (!GetOverlappedResult(h, ovl, &io, FALSE) && GetLastError() == ERROR_IO_INCOMPLETE)
return LIBUSB_ERROR_BUSY;
memset(ovl, 0, sizeof(*ovl)); memset(ovl, 0, sizeof(*ovl));
ovl->hEvent = he; ovl->hEvent = he;
result = fio(h, data, *length, &io, ovl); 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(); io = GetLastError();
if (io == ERROR_IO_PENDING) if (io == ERROR_IO_PENDING)
{ {
WaitForSingleObject(he, 500); if (WaitForSingleObject(he, timeout) == WAIT_OBJECT_0)
GetOverlappedResult(h, &ovl_[OVL_BULK_IN], &io, FALSE); {
*length = io; GetOverlappedResult(h, ovl, &io, FALSE);
ret = LIBUSB_SUCCESS; *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); wnd_monitor_ = CreateWindowW(cls, L"usb", WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandleW(NULL), this);
if (!IsWindow(wnd_monitor_)) if (!IsWindow(wnd_monitor_))
{ {
// HG_VLOG_MINI_1(HG_LOG_LEVEL_FATAL, "create monitor window failed: %d\n", GetLastError());
if(run_) if(run_)
Sleep(1000); Sleep(1000);
@ -954,14 +958,10 @@ void usb_monitor::thread_run_device_event_wnd(void)
dbh.dbch_devicetype = DBT_DEVTYP_DEVICEINTERFACE; dbh.dbch_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
notify = RegisterDeviceNotificationW(wnd_monitor_, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); notify = RegisterDeviceNotificationW(wnd_monitor_, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
ret = GetLastError(); ret = GetLastError();
// find_usb();
while (run_ && (ret = GetMessageW(&msg, wnd_monitor_, 0, 0))) while (run_ && (ret = GetMessageW(&msg, wnd_monitor_, 0, 0)))
{ {
if (ret == -1) if (ret == -1)
{
// HG_VLOG_MINI_1(HG_LOG_LEVEL_FATAL, "GetMessageW returned -1 with error: %d\n", GetLastError());
break; break;
}
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessageW(&msg); DispatchMessageW(&msg);