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);