调整读图时会有个超时错误的信息,直接跳出循环再次读取

This commit is contained in:
13038267101 2023-04-23 15:07:39 +08:00
parent a5926a14b9
commit 7cdf5a4e19
1 changed files with 49 additions and 46 deletions

View File

@ -630,18 +630,14 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
break; break;
} }
block = size; 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)); 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;
}
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());
break; break;
} }
off += block; off += block;
r -= block; r -= block;
} }
@ -666,10 +662,6 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
else else
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image data from USB err: %s\n", hg_scanner_err_name(ret)); 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,13 +683,20 @@ int hg_scanner_239::discard_all_images(void)
// ret = io_->read_bulk(&str[0], &block); // ret = io_->read_bulk(&str[0], &block);
// } // }
//} //}
{
std::lock_guard<std::mutex> lock(io_lock_);
char buf[64]; char buf[64];
int size = sizeof(buf); int size = sizeof(buf);
ret = SCANNER_ERR_OK; ret = SCANNER_ERR_OK;
setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf; setting3399::HGEIntInfo* info = (setting3399::HGEIntInfo*)buf;
{ {
std::lock_guard<std::mutex> lock(io_lock_);
if (!io_)
{
return 0;
}
oto = io_->get_timeout(); oto = io_->get_timeout();
io_->set_timeout(100); io_->set_timeout(100);
ret = io_->read_interrupt(buf, &size); ret = io_->read_interrupt(buf, &size);
@ -716,14 +715,18 @@ int hg_scanner_239::discard_all_images(void)
size = sizeof(buf); size = sizeof(buf);
{ {
std::lock_guard<std::mutex> lock(io_lock_);
ret = io_->read_interrupt(buf, &size); ret = io_->read_interrupt(buf, &size);
} }
} }
{ {
std::lock_guard<std::mutex> lock(io_lock_);
io_->set_timeout(oto); io_->set_timeout(oto);
} }
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
if (!io_)
{
return 0;
}
if (is_read_int) if (is_read_int)
{ {
init_version(); init_version();