diff --git a/device/gxx-linux/packages/common.pkg/include/commondef.h b/device/gxx-linux/packages/common.pkg/include/commondef.h index 8cf3235..773df32 100644 --- a/device/gxx-linux/packages/common.pkg/include/commondef.h +++ b/device/gxx-linux/packages/common.pkg/include/commondef.h @@ -130,7 +130,7 @@ struct MotorBoardGlue struct ScannerNativeParam { - u32 TotalScanned; //扫描总计�? + u32 TotalScanned; //扫描总计? u32 RollerNum; //滚轴计数 u32 H_ratio; //横向修正系数 u32 V_ratio; //纵向修正系数 @@ -138,13 +138,13 @@ struct ScannerNativeParam u32 FeedErrorTimes; //搓纸失败次数 u32 DoubleFeedTimes; //双张次数 u32 ScanSessionsCount; //总计扫描次数 - u16 gray_sp; //灰度sp�? - u16 color_sp; //彩色sp�? - int sleeptime; //休眠模式时间 -1 不休�? - std::string SerialNum; //序列�? - std::string Token; //识别�? - u32 clr_maxbright; //彩色平场校正最大亮�? - u32 gray_maxbright; //灰度平场校正最大亮�? + u16 gray_sp; //灰度sp? + u16 color_sp; //彩色sp? + int sleeptime; //休眠模式时间 -1 不休? + std::string SerialNum; //序列? + std::string Token; //识别? + u32 clr_maxbright; //彩色平场校正最大亮? + u32 gray_maxbright; //灰度平场校正最大亮? u32 speedmode; //速度模式 G100 0->70 1->80 2->90 3->100 G200 0->100 1->110 2->120 3->130 u16 Vid; //USB vid u16 Pid; //USB Pid @@ -265,7 +265,7 @@ enum HGType STOPSCAN, }; -//usb int 端点通信结构�? +//usb int 端点通信结构? struct HGIntInfo { HGType From; @@ -440,7 +440,10 @@ enum Scanner_Reg_Defs SR_GET_MBVERSION_LENGHT, SR_GET_MBVERSION, SR_GET_USBVIDPID, - SR_SET_USBVIDPID + SR_SET_USBVIDPID, + + SR_SCAN_DPI = 0x600, + SR_SCAN_CNT, }; enum Updata_Stautus @@ -662,8 +665,8 @@ typedef struct tagCrop_Rect int enable; int x; /*****自定义裁切区域左上角x坐标*/ int y; /*****自定义裁切区域左上角y坐标*/ - int width; /*****自定义裁切区域宽�?******/ - int height; /*****自定义裁切区域高�?******/ + int width; /*****自定义裁切区域宽?******/ + int height; /*****自定义裁切区域高?******/ }CropRect; typedef enum tagMulti_Output { diff --git a/device/gxx-linux/scanner/scannerregs.cpp b/device/gxx-linux/scanner/scannerregs.cpp index dcd8492..46cac25 100644 --- a/device/gxx-linux/scanner/scannerregs.cpp +++ b/device/gxx-linux/scanner/scannerregs.cpp @@ -36,6 +36,26 @@ void get_system_output(char *cmd, char *output, int size) } } +static std::string load_mini_file(const char* path) +{ + // /root/.scanner/log + FILE *src = fopen(path, "rb"); + std::string ret(""); + + if(src) + { + int len = 0; + + fseek(src, 0, SEEK_END); + len = ftell(src); + fseek(src, 0, SEEK_SET); + ret.resize(len); + fread(&ret[0], 1, len, src); + fclose(src); + } + + return ret; +} static const std::string loggername = "ScannerRegAccess"; ScannerRegAccess::ScannerRegAccess(std::shared_ptr scanner, std::shared_ptr usbimages, std::shared_ptr transmit, std::shared_ptr receiv) @@ -55,10 +75,43 @@ ScannerRegAccess::~ScannerRegAccess() bool ScannerRegAccess::write(unsigned int addr, const unsigned int val) { - // printf("write(0x%x, 0x%x), sizeof(unsigned int) = %d, sizeof(long) = %d, sizeof(long long) = %d\n", addr, val - // , sizeof(unsigned int), sizeof(long), sizeof(long long)); + static uint64_t img_cb = 0, img_param = 0; + static uint32_t scan_dpi = 200, scan_cnt = -1; - printf("ScannerRegAccess::write(%d, %d)\n", addr, val); + if(addr == (unsigned int)-1) + { + img_cb = val; + img_cb <<= 32; + printf("image callback (1/2) = %p\n", img_cb); + + return true; + } + else if(addr == (unsigned int)-2) + { + img_cb |= val; + + return true; + } + else if(addr == (unsigned int)-3) + { + img_param = val; + img_param <<= 32; + printf("image callback (1/2) = %p\n", img_param); + + return true; + } + else if(addr == (unsigned int)-4) + { + void(*func)(MemoryPtr, bool, void*) = nullptr; + void* param = nullptr; + + img_param |= val; + param = (void*)img_param; + *((uint64_t*)&func) = img_cb; + usbimages->set_image_keeper(func, param); + + return true; + } switch (addr) { case SR_CMD: @@ -100,9 +153,23 @@ bool ScannerRegAccess::write(unsigned int addr, const unsigned int val) case SR_CONFIG_SCAN_PARAM: scanner->configparam(*((HGScanConfig *)&val)); return true; + case SR_SCAN_DPI: + scan_dpi = val; + return true; + case SR_SCAN_CNT: + scan_cnt = val; + return true; case SR_CONFIF_IMGPROCPARAM: { printf("\nSR_CONFIF_IMGPROCPARAM size =%d",val); +#ifdef ASYNC_EP + std::string cfg(load_mini_file("/root/.scanner/log/cfg_4308.bin")); + GScanCap cap = *(GScanCap*)&cfg[0]; + + cap.resolution_dst = cap.resolution_native = scan_dpi; + cap.scannum = scan_cnt; + printf("DPI: %d, Count: %d\n", scan_dpi, scan_cnt); +#else std::vector data(val); if(val==0) data.resize(116); @@ -111,6 +178,7 @@ bool ScannerRegAccess::write(unsigned int addr, const unsigned int val) printf("\n gcap size = %d \n",sizeof(GScanCap)); memcpy(capdata,data.data(),std::min(sizeof(GScanCap),data.size())); GScanCap cap = *(GScanCap *)capdata; +#endif scanner->set_hgimgconfig(cap); return true; } diff --git a/device/gxx-linux/usb/inc/usbdevice.h b/device/gxx-linux/usb/inc/usbdevice.h index 459aa17..a252df3 100644 --- a/device/gxx-linux/usb/inc/usbdevice.h +++ b/device/gxx-linux/usb/inc/usbdevice.h @@ -25,7 +25,9 @@ class UsbDevice uint32_t img_cnt_; uint32_t scan_id_; uint32_t dpi_; + uint32_t scan_cnt_; std::string cfg_text_; + dyn_mem_ptr scan_over_pack_; dyn_mem_ptr unhandled_ep0(struct usb_functionfs_event* pev); dyn_mem_ptr handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_data_base_ptr* required); diff --git a/device/gxx-linux/usb/src/common/ipc_util.cpp b/device/gxx-linux/usb/src/common/ipc_util.cpp index acbbcfc..4a887bc 100644 --- a/device/gxx-linux/usb/src/common/ipc_util.cpp +++ b/device/gxx-linux/usb/src/common/ipc_util.cpp @@ -19,7 +19,7 @@ unsigned long linux_event::to_abs_time_us = 0; linux_event::linux_event(const char* desc) : waiting_(false), sem_(nullptr), desc_(desc ? desc : ""), first_(true), multi_proc_(false) { - log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) unamed for '%s' constructing ...\n", this, desc_.c_str()); + //log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) unamed for '%s' constructing ...\n", this, desc_.c_str()); #if defined(WIN32) || defined(_WIN64) err_ = 0; @@ -40,7 +40,7 @@ linux_event::linux_event(const char* desc) : waiting_(false), sem_(nullptr), des } linux_event::linux_event(const char* name, const char* desc) : waiting_(false), sem_(nullptr), desc_(desc ? desc : ""), first_(true), multi_proc_(true) { - log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) of named '%s' for '%s' constructing ...\n", this, name, desc_.c_str()); + //log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) of named '%s' for '%s' constructing ...\n", this, name, desc_.c_str()); #if defined(WIN32) || defined(_WIN64) local_sem_ = CreateEventA(NULL, TRUE, FALSE, name); sem_ = &local_sem_; @@ -93,7 +93,7 @@ linux_event::linux_event(const char* name, const char* desc) : waiting_(false), } linux_event::linux_event(sem_t* mem_sem, bool first, const char* desc) : waiting_(false), sem_(mem_sem), desc_(desc ? desc : ""), first_(first), multi_proc_(true) { - log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) at mem(%p) for '%s' constructing ...\n", this, mem_sem, desc_.c_str()); + //log_cls::log(LOG_LEVEL_ALL, "+linux_event(%p) at mem(%p) for '%s' constructing ...\n", this, mem_sem, desc_.c_str()); if(first) { @@ -138,7 +138,7 @@ linux_event::~linux_event() #endif } } - log_cls::log(LOG_LEVEL_ALL, "-linux_event(%p) destroyed.\n", this); + //log_cls::log(LOG_LEVEL_ALL, "-linux_event(%p) destroyed.\n", this); } int32_t linux_event::clear_named_event(const char* name) diff --git a/device/gxx-linux/usb/src/usbdevice.cpp b/device/gxx-linux/usb/src/usbdevice.cpp index 0875e6d..36d2f47 100644 --- a/device/gxx-linux/usb/src/usbdevice.cpp +++ b/device/gxx-linux/usb/src/usbdevice.cpp @@ -326,7 +326,7 @@ UsbDevice::UsbDevice(std::functionpayload, cfg_ret = nullptr; std::string name(cfg->data + cfg->name_off); - size_t l = base_head_size + sizeof(CFGVAL) + name.length() + 1 + cfg->max_size + 1; + size_t l = base_head_size + sizeof(CFGVAL) + name.length() + 1 + cfg->max_size + 1, val_size = cfg->val_size; int32_t err = 0; + uint32_t after = 0; reply = dyn_mem::memory(l); pk = (LPPACK_BASE)reply->ptr(); @@ -1747,8 +1748,11 @@ dyn_mem_ptr UsbDevice::handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_ cfg_ret->val_size = cfg->val_size; cfg_ret->max_size = cfg->max_size; cfg_ret->type = cfg->type; - err = cfg_->set_config(cfg->data + cfg->name_off, cfg_ret->data + cfg_ret->val_off, (size_t*)&cfg_ret->val_size, (uint32_t*)&cfg_ret->after_do); + err = cfg_->set_config(cfg->data + cfg->name_off, cfg_ret->data + cfg_ret->val_off, &val_size, &after); + cfg_ret->after_do = after; + cfg_ret->val_size = val_size; BASE_PACKET_REPLY(*pk, pack->cmd + 1, pack->pack_id, err); + pk->payload_len = sizeof(CFGVAL) + name.length() + 1 + cfg->max_size + 1; reply->set_len(l); } break; @@ -1822,12 +1826,21 @@ dyn_mem_ptr UsbDevice::handle_bulk_cmd(LPPACK_BASE pack, uint32_t* used, packet_ int err = 0; img_cnt_ = 0; scan_id_ = pack->pack_id; - log_cls::log(LOG_LEVEL_ALL, "Start scanning ...\n"); + if(scan_over_pack_) + { + scan_over_pack_->release(); + scan_over_pack_ = nullptr; + } + { bool ret = ctrl_handler(-1, (usb_ctrlrequest*)15, (unsigned char*)0x160); // hardware configuration - - ret = ctrl_handler(-1, (usb_ctrlrequest*)20, (unsigned char*)dpi_); - ctrl_handler(-1, nullptr, nullptr); + + ctrl_handler(-1, (usb_ctrlrequest*)SR_SCAN_CNT, (unsigned char*)scan_cnt_); + ctrl_handler(-1, (usb_ctrlrequest*)SR_SCAN_DPI, (unsigned char*)dpi_); + ctrl_handler(-1, (usb_ctrlrequest*)SR_CONFIF_IMGPROCPARAM, (unsigned char*)0); + log_cls::log(LOG_LEVEL_ALL, "Start scanning with %d DPI ...\n", dpi_); + ret = ctrl_handler(-1, nullptr, nullptr); + log_cls::log(LOG_LEVEL_ALL, "Start scanning %s\n", ret ? "OK" : "Failed"); } reply = dyn_mem::memory(base_head_size); @@ -1871,8 +1884,9 @@ void UsbDevice::init(void) readonly_cfg* r = new readonly_cfg(); size_t l = sizeof(dpi_); - cfg_text_ = "{\"resolution\":{\"category\":\"base\",\"readonly\":false,\"affect\":2,\"ver\":1,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"cur\":200,\"default\":200,\"size\":4,\"range\":[100,150,200,300,600]}}"; + cfg_text_ = "{\"resolution\":{\"category\":\"base\",\"readonly\":false,\"affect\":2,\"ver\":1,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"cur\":200,\"default\":200,\"size\":4,\"range\":[100,150,200,300,600]},\"count\":{\"category\":\"base\",\"readonly\":false,\"affect\":0,\"ver\":1,\"group\":\"base\",\"visible\":true,\"field\":\"Common\",\"pos\":0,\"unit\":\"None\",\"title\":\"\\u626b\\u63cf\\u5f20\\u6570\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u7684\\u7eb8\\u5f20\\u6570\\u91cf\",\"type\":\"int\",\"cur\":-1,\"default\":-1,\"size\":4,\"range\":[-1,1]}}"; l = get_config(&dpi_, &l, "resolution"); + l = get_config(&scan_cnt_, &l, "count"); cfg_ = new sane_cfg_mgr(); cfg_->reg_sane_provider(dynamic_cast(r)); l = cfg_->reg_sane_provider(dynamic_cast(this)); @@ -1895,6 +1909,18 @@ void UsbDevice::save_image(MemoryPtr data, bool img) log_cls::log(LOG_LEVEL_ALL, "New image with bytes: %u\n", data->size()); usb_->write_bulk(ip); ip->release(); + + // check has completed ? + if(scan_over_pack_) + { + ctrl_handler(-2, (usb_ctrlrequest*)SR_GET_IMAGEPROCESSDONE, (unsigned char*)&n); + if(n) + { + usb_->write_bulk(scan_over_pack_); + scan_over_pack_->release(); + scan_over_pack_ = nullptr; + } + } } else { @@ -1954,14 +1980,22 @@ void UsbDevice::save_image(MemoryPtr data, bool img) { cmd = PACK_CMD_SCAN_FINISHED_ROGER; } - if(scan_id_ && cmd == PACK_CMD_SCAN_FINISHED_ROGER) + if(scan_id_ && cmd == PACK_CMD_SCAN_FINISHED_ROGER && scan_over_pack_ == nullptr) { log_cls::log(LOG_LEVEL_ALL, "Scan over with error: %d\n", err); BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), cmd, scan_id_, err); reply->set_len(sizeof(PACK_BASE)); scan_id_ = 0; - usb_->write_bulk(reply); + // check if the image-proc-queue has completed ... + ctrl_handler(-2, (usb_ctrlrequest*)SR_GET_IMAGEPROCESSDONE, (unsigned char*)&err); + if(err) + usb_->write_bulk(reply); + else + { + scan_over_pack_ = reply; + scan_over_pack_->add_ref(); + } } reply->release(); } @@ -2058,6 +2092,21 @@ int32_t UsbDevice::set_config(const char* cfg_name, void* data, size_t* len, uin log_cls::log(LOG_LEVEL_ALL, "Set %s to %d\n", cfg_name, dpi_); cfg_text_ = jsn->to_string(); } + else if(strcmp(cfg_name, "count") == 0) + { + child->get_value("cur", val); + ret = EUCLEAN; + val = *(int*)data; + if(val == -1 || val == 1) + ret = 0; + else + val = -1; + *(int*)data = val; + child->set_value("cur", val); + scan_cnt_ = val; + log_cls::log(LOG_LEVEL_ALL, "Set %s to %d\n", cfg_name, scan_cnt_); + cfg_text_ = jsn->to_string(); + } child->release(); } jsn->release(); diff --git a/device/gxx-linux/usb/usbservice.cpp b/device/gxx-linux/usb/usbservice.cpp index c09ece2..97adaa0 100644 --- a/device/gxx-linux/usb/usbservice.cpp +++ b/device/gxx-linux/usb/usbservice.cpp @@ -102,6 +102,14 @@ UsbService::UsbService(std::shared_ptr fgparegs, std::shared_ptrread(addr, val); + *(unsigned int*)buffer = val; + } printf("req = %x, type = %x, ind = %x, len = %x, val = %x\n", setup->bRequest, setup->bRequestType, setup->wIndex, setup->wLength, setup->wValue); if (!(setup->bRequestType & USB_TYPE_VENDOR) || (setup->bRequestType & USB_RECIP_MASK) != USB_RECIP_DEVICE) diff --git a/device/gxx-linux/usb/xmake.lua b/device/gxx-linux/usb/xmake.lua index 16c06a6..92a8321 100644 --- a/device/gxx-linux/usb/xmake.lua +++ b/device/gxx-linux/usb/xmake.lua @@ -3,7 +3,7 @@ add_rules("mode.debug", "mode.release") target("gusb") set_kind("static") add_syslinks("pthread") - add_files("*.cpp", "src/*.cpp", "src/common/*.cpp") + add_files("*.cpp", "src/*.cpp", "src/common/*.cpp", "src/common/json/*.c*") add_includedirs("inc") add_includedirs("src/common") add_includedirs(".", { public = true}) diff --git a/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe b/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe index 8dc425a..c38b6d8 100644 Binary files a/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe and b/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe differ diff --git a/pc/code_twain/sln/usb_tools/DlgScanner.cpp b/pc/code_twain/sln/usb_tools/DlgScanner.cpp index 1c565bb..9a320d1 100644 --- a/pc/code_twain/sln/usb_tools/DlgScanner.cpp +++ b/pc/code_twain/sln/usb_tools/DlgScanner.cpp @@ -667,6 +667,9 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp) KillTimer(TIMER_ID_REFRESH_BULK); ((CButton*)GetDlgItem(IDC_CHECK_AUTO))->SetCheck(BST_UNCHECKED); enable_buttons(pnp != NULL); + GetDlgItem(IDC_CHECK_AUTO)->EnableWindow(pnp != NULL); + GetDlgItem(IDC_BUTTON_RESET_BULK)->EnableWindow(pnp != NULL); + GetDlgItem(IDC_BUTTON_REFRESH)->EnableWindow(pnp != NULL); if (scanner_) { @@ -687,6 +690,8 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp) { CDlgScanner* dlg = (CDlgScanner*)user_data; + log_cls::log(LOG_LEVEL_DEBUG, "Finished in receiving new image = %d\r\n", err); + if (err) //::SetDlgItemTextW(m_hWnd, IDC_EDIT_COUNT, (L"Receive image " + std::to_wstring(img_cnt_) + L" error: " + std::to_wstring(err)).c_str()); dlg->set_text(IDC_EDIT_COUNT, (L"Receive image " + std::to_wstring(img_cnt_) + L" error: " + std::to_wstring(err)).c_str()); @@ -707,9 +712,12 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp) file_saver* saver = new file_saver(); std::string root(usb::u2a(img_root_.c_str())); char name[40] = { 0 }; + int err = 0; sprintf_s(name, _countof(name) - 1, "scan_%04d.jpg", ++img_cnt_); - if (saver->open((root + name).c_str(), size)) + err = saver->open((root + name).c_str(), size); + log_cls::log(LOG_LEVEL_DEBUG, "Begin receiving new image (%s + %llu) = %d\r\n", (root + name).c_str(), size, err); + if (err) { saver->release(); saver = NULL; @@ -733,6 +741,8 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp) ::SetTextColor(dc, size ? RGB(255, 0, 0) : RGB(0, 0, 0)); ::ReleaseDC(wnd, dc); + log_cls::log(LOG_LEVEL_DEBUG, "Scan stopped with error %s\r\n", usb::u2a(scanner_status(size, buf)).c_str()); + if (size) set_text(IDC_EDIT_COUNT, (std::to_wstring(img_cnt_) + L" (Error: " + scanner_status(size, buf) + L")").c_str()); else @@ -1174,6 +1184,7 @@ void CDlgScanner::OnBnClickedButtonScan() if (scanner_) { int err = scanner_->scan_start(); + log_cls::log(LOG_LEVEL_DEBUG, "Start to scan = %d\r\n", err); if (err) msg_box(m_hWnd, MB_OK, L"Error", L"Failed in startin scanning with code %d", err); else diff --git a/pc/code_twain/sln/usb_tools/resource.h b/pc/code_twain/sln/usb_tools/resource.h index 50b49e1..53a5877 100644 --- a/pc/code_twain/sln/usb_tools/resource.h +++ b/pc/code_twain/sln/usb_tools/resource.h @@ -88,8 +88,9 @@ #define IDC_STATIC_CMD_QUE 1061 #define IDC_STATIC_SENT_QUE 1062 #define IDC_STATIC_OPTS 1063 -#define IDC_CHECK1 1064 #define IDC_CHECK_AUTO_OPEN_IMG 1064 +#define IDC_EDIT1 1065 +#define IDC_EDIT_LOG_FILE 1065 #define ID_TRAY_EXIT 32771 // Next default values for new objects @@ -98,7 +99,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 137 #define _APS_NEXT_COMMAND_VALUE 32772 -#define _APS_NEXT_CONTROL_VALUE 1065 +#define _APS_NEXT_CONTROL_VALUE 1066 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp b/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp index a034a54..2376be6 100644 --- a/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp +++ b/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp @@ -574,6 +574,7 @@ int scanner_handler::scan_start(void) { auto call = [&](cmd_result* cmd) -> int { + cmd->set_timeout(4000); return usb_->scan_start(cmd->get_id()); }; auto clean = [&](cmd_result* cmd) -> int diff --git a/pc/code_twain/sln/usb_tools/usb_toolsDlg.cpp b/pc/code_twain/sln/usb_tools/usb_toolsDlg.cpp index 6fec7c9..f3f8848 100644 --- a/pc/code_twain/sln/usb_tools/usb_toolsDlg.cpp +++ b/pc/code_twain/sln/usb_tools/usb_toolsDlg.cpp @@ -271,6 +271,7 @@ CusbtoolsDlg::CusbtoolsDlg(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_USB_TOOLS_DIALOG, pParent) { log_cls::initialize(NULL); + log_cls::log(LOG_LEVEL_DEBUG, "--------------------New instance started ...--------------------\r\n"); m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } @@ -347,6 +348,7 @@ BOOL CusbtoolsDlg::OnInitDialog() usb::register_tray(m_hWnd, m_hIcon, true); SetPropW(m_hWnd, L"task_usb", m_hWnd); + ::SetDlgItemTextA(m_hWnd, IDC_EDIT_LOG_FILE, log_cls::get_log_file().c_str()); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } @@ -533,6 +535,7 @@ void CusbtoolsDlg::log_pnp(usb::LPUSBPNP pnp) swprintf_s(buf + lstrlenW(buf), _countof(buf) - 1, L"%s: %04X:%04X %s\r\n", usb::now().c_str(), pnp->vid, pnp->pid, pnp->arrive ? L"Arrive" : L"Left"); append_log(buf, IDC_EDIT_PNP_MSG); + log_cls::log(LOG_LEVEL_ALL, "%04X:%04X %s\r\n", pnp->vid, pnp->pid, pnp->arrive ? "Arrived" : "Left"); } bool CusbtoolsDlg::endpoint_from_combo_text(wchar_t* text, BYTE& type, BYTE& addr) { @@ -666,6 +669,13 @@ LRESULT CusbtoolsDlg::OnUsbPnp(WPARAM wp, LPARAM lp) usb::LPUSBPNP pnp = (usb::LPUSBPNP)lp; log_pnp(pnp); + if (pnp->pid == 0 && pnp->vid == 0) + { + delete pnp; + + return 0; + } + if (pnp->arrive) { ////for (auto& v : pnp_que_) diff --git a/pc/code_twain/sln/usb_tools/usbtools.rc b/pc/code_twain/sln/usb_tools/usbtools.rc index 70b31cc..62cd8bc 100644 Binary files a/pc/code_twain/sln/usb_tools/usbtools.rc and b/pc/code_twain/sln/usb_tools/usbtools.rc differ