From 5217432a8f670da42561548822ed99dbd3c1f5aa Mon Sep 17 00:00:00 2001 From: 13038267101 Date: Wed, 26 Apr 2023 15:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4twain=E5=9C=A8open=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=97=B6=E5=8F=AF=E8=83=BD=E4=BC=9A=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E6=9C=AA=E6=89=93=E5=BC=80=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twain/twain/huagaods.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp index b7634e4..ee5b467 100644 --- a/twain/twain/huagaods.cpp +++ b/twain/twain/huagaods.cpp @@ -1039,13 +1039,26 @@ Result huagao_ds::identityOpenDs(const Identity& id) return result; } - int err = 0; - Sleep(100); + int err = 0, attempt = 0; + // Sleep(500); scanner_.reset(load_sane_util::open(scanner_guid, &err)); + while (err == SCANNER_ERR_DEVICE_NOT_FOUND && attempt++ < 100) + { + if (attempt == 1) + { + load_sane_util::log_info(L"Driver is not ready, we wait ... \r\n", 0); + } + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + err = 0; + scanner_.reset(load_sane_util::open(scanner_guid, &err)); + } if (!scanner_.get()) { //CloseHandle(singleton_); //singleton_ = NULL; + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L"OpenDS error: %d\r\n", err); + load_sane_util::log_info(info, 0); load_sane_util::uninitialize(); return { ReturnCode::Failure, huagao_ds::condition_code_from_hg_error(err) }; @@ -1121,7 +1134,7 @@ Result huagao_ds::setupMemXferGet(const Identity& id, SetupMemXfer& data) { int def_w = 2000, def_h = 6000; - data.setMinSize(def_w * 3 * def_h); + data.setMinSize(def_w * 3/* * def_h*/); data.setPreferredSize(def_w * 3 * def_h); data.setMaxSize(def_w * 3 * def_h); } @@ -1635,7 +1648,7 @@ Result huagao_ds::call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, v trigger_ProcessEvent(dg, dat, msg); // some APPs may be not trigger (Control, Event, ProcessEvent), we help them :( ... // 云阅卷扫描端不等状态改变,直接取图,此处设置一次状态 2022-11-07 rt = Base::call(origin, dg, dat, msg, data); - if(log_all_triple_ || (int)rt.returnCode()) + if (log_all_triple_ || ((int)rt.returnCode() && rt.returnCode() != ReturnCode::NotDsEvent)) { wchar_t buf[128] = { 0 }, dgs[20] = { 0 }, dts[20] = { 0 }, ms[20] = { 0 }, ss[20] = { 0 }, rcs[20] = { 0 }, cs[20] = { 0 }; swprintf_s(buf, _countof(buf) - 1, L"[%x - %s]DSEntry(%s, %s, %s) = {%s, %s}\r\n", GetCurrentThreadId(), desc_state(state(), ss),