From 7cdf5a4e19e787853a50a7d48e97fb0a8d994924 Mon Sep 17 00:00:00 2001 From: 13038267101 Date: Sun, 23 Apr 2023 15:07:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AF=BB=E5=9B=BE=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E6=9C=89=E4=B8=AA=E8=B6=85=E6=97=B6=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=9B=B4=E6=8E=A5=E8=B7=B3?= =?UTF-8?q?=E5=87=BA=E5=BE=AA=E7=8E=AF=E5=86=8D=E6=AC=A1=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/hg_scanner_239.cpp | 95 ++++++++++++++++--------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/hgdriver/hgdev/hg_scanner_239.cpp b/hgdriver/hgdev/hg_scanner_239.cpp index c83470e..1ca6c9a 100644 --- a/hgdriver/hgdev/hg_scanner_239.cpp +++ b/hgdriver/hgdev/hg_scanner_239.cpp @@ -630,18 +630,14 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu) break; } block = size; - ret = io_->read_bulk(buff, &block); + ret = io_->read_bulk(buff, &block); //可能会出现TIME_OUT 然后只能退出去,下一次再来取 - if (ret != SCANNER_ERR_OK && ret != SCANNER_ERR_TIMEOUT) + if (ret != SCANNER_ERR_OK) { - VLOG_MINI_1(LOG_LEVEL_FATAL, "read_one_image_from_usb read_data:%s!!! \n", hg_scanner_err_name(ret)); - break; - } - else if (ret == SCANNER_ERR_TIMEOUT && io_->get_timeout() > 3000) - { - VLOG_MINI_2(LOG_LEVEL_FATAL, "read_one_image_from_usb read_data:%s!!! ,get_timeout is %d\n", hg_scanner_err_name(ret), io_->get_timeout()); + VLOG_MINI_3(LOG_LEVEL_FATAL, "read_one_image_from_usb read_data:%s!!! read data[%d/:%d]\n", hg_scanner_err_name(ret),size, block); break; } + off += block; r -= block; } @@ -666,10 +662,6 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu) else { VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image data from USB err: %s\n", hg_scanner_err_name(ret)); - stop(); - string str = STATU_DESC_SCANNER_ERR_DEVICE_GET_IMAGE_ERR; - str = str + '-' + STATU_DESC_SCANNER_ERR_DEVICE_STOPPED; - notify_ui_working_status(str.c_str(), SANE_EVENT_ERROR, ret); } } } @@ -691,43 +683,54 @@ int hg_scanner_239::discard_all_images(void) // ret = io_->read_bulk(&str[0], &block); // } //} - - char buf[64]; - int size = sizeof(buf); - ret = SCANNER_ERR_OK; - setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf; - { - std::lock_guard lock(io_lock_); - oto = io_->get_timeout(); - io_->set_timeout(100); - ret = io_->read_interrupt(buf, &size); - } - while (ret == SCANNER_ERR_OK) - { - pre_int++; - if (info->From == setting3399::IMG) - { - while (get_image_count() > 0) - { - pop_first_image(); - pre_img++; - } - } - - size = sizeof(buf); { std::lock_guard lock(io_lock_); - ret = io_->read_interrupt(buf, &size); + + + char buf[64]; + int size = sizeof(buf); + ret = SCANNER_ERR_OK; + setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf; + { + + if (!io_) + { + return 0; + } + oto = io_->get_timeout(); + io_->set_timeout(100); + ret = io_->read_interrupt(buf, &size); + } + while (ret == SCANNER_ERR_OK) + { + pre_int++; + if (info->From == setting3399::IMG) + { + while (get_image_count() > 0) + { + pop_first_image(); + pre_img++; + } + } + + size = sizeof(buf); + { + ret = io_->read_interrupt(buf, &size); + } + } + { + io_->set_timeout(oto); + } + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + if (!io_) + { + return 0; + } + if (is_read_int) + { + init_version(); } - } - { - std::lock_guard lock(io_lock_); - io_->set_timeout(oto); - } - if (is_read_int) - { - init_version(); - } if (pre_int) VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "prev-connection has left %d interrupt packet(s) && %d image(s).\n", pre_int, pre_img);