diff --git a/device/gxx-linux/usb/src/common/usb_io.cpp b/device/gxx-linux/usb/src/common/usb_io.cpp index 41e50fd..81f7b32 100644 --- a/device/gxx-linux/usb/src/common/usb_io.cpp +++ b/device/gxx-linux/usb/src/common/usb_io.cpp @@ -55,7 +55,7 @@ async_usb_gadget::async_usb_gadget(usb_gadget* gadget, std::functionthread_new(&async_usb_gadget::thread_pump_task); thread_ep0_id_ = threads_->thread_new(&async_usb_gadget::thread_read_ep0); - //threads_->thread_new(&async_usb_gadget::thread_check_ep0_status); + threads_->thread_new(&async_usb_gadget::thread_check_ep0_status); } async_usb_gadget::~async_usb_gadget() @@ -546,7 +546,7 @@ void async_usb_gadget::thread_read_bulk(void) // log_cls::log(LOG_LEVEL_ALL, "read bulk with 0 byte - %u time(s).\n", cnt_0); // cnt_0 = 0; // } - log_cls::log(LOG_LEVEL_ALL, "thread_pump_task do reset-bulk ...\n"); + log_cls::log(LOG_LEVEL_ALL, "thread_read_bulk do reset-bulk ...\n"); buf->release(); if(!run_) break; @@ -786,6 +786,7 @@ void async_usb_gadget::thread_pump_task(void) } void async_usb_gadget::thread_restart_bulk(void) { + log_cls::log(LOG_LEVEL_ALL, "reset bulk: 1/5 - clear command queue and sent queue ...\n"); dyn_mem_ptr data; while(cmd_que_.take(data, false)) data->release(); @@ -794,17 +795,25 @@ void async_usb_gadget::thread_restart_bulk(void) while(sent_que_.take(src, false)) src->release(); - sent_que_.quit(); - cmd_que_.quit(); + log_cls::log(LOG_LEVEL_ALL, "reset bulk: 2/5 - waiting for IN-endpoint to be idle ...\n"); + while (status_.in_status != BULK_STATUS_IDLE) + { + sent_que_.quit(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + log_cls::log(LOG_LEVEL_ALL, "reset bulk: 3/5 - waiting for task queue to be idle ...\n"); + while(status_.task_cmd) + { + cmd_que_.quit(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + log_cls::log(LOG_LEVEL_ALL, "reset bulk: 4/5 - waiting for OUT-endpoint to be idle(wait data) ...\n"); - // close_bulk(); - while(status_.in_status != BULK_STATUS_IDLE || status_.out_status != BULK_STATUS_IO || status_.task_cmd) + while(status_.out_status != BULK_STATUS_IO) std::this_thread::sleep_for(std::chrono::milliseconds(10)); - // open_bulk(); - // cmd_que_.quit(); reset_bulk_ = false; - log_cls::log(LOG_LEVEL_ALL, "reset bulk completed.\n"); + log_cls::log(LOG_LEVEL_ALL, "reset bulk: 5/5 - completed.\n"); } int async_usb_gadget::stop(void) diff --git a/pc/code_twain/sln/usb_tools/DlgScanner.cpp b/pc/code_twain/sln/usb_tools/DlgScanner.cpp index b20b220..9469f44 100644 --- a/pc/code_twain/sln/usb_tools/DlgScanner.cpp +++ b/pc/code_twain/sln/usb_tools/DlgScanner.cpp @@ -709,7 +709,14 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp) RECT r = { 0 }; std::string all(""); - scanner_->option_get_all(all); + if (scanner_->option_get_all(all) == ETIMEDOUT) + { + // reset it ... + msg_box(m_hWnd, MB_OK, L"Bulk Trouble", L"Bulk communication TIMEOUTED, will try reset bulk ..."); + scanner_->reset_message_que(); + refresh_bulk_status(); + scanner_->option_get_all(all); + } scanner_handler::reorder_device_config_json(all); sane::reset_opts(all.c_str()); 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 a7c9858..9e7befb 100644 --- a/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp +++ b/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp @@ -186,7 +186,7 @@ scanner_handler::scanner_handler(void) : usb_(nullptr), status_(SCANNER_STATUS_N *more = dynamic_cast(receiver); } } - else if (pack->cmd == PACK_CMD_SCAN_STOP_ROGER) + else if (pack->cmd == PACK_CMD_SCAN_FINISHED_ROGER) { data_holder_ptr receiver = img_receiver_(NULL, pack->data); if (receiver) diff --git a/pc/code_twain/sln/usb_tools/scanner/usb/async_usb_host.cpp b/pc/code_twain/sln/usb_tools/scanner/usb/async_usb_host.cpp index 5c81308..fd1955d 100644 --- a/pc/code_twain/sln/usb_tools/scanner/usb/async_usb_host.cpp +++ b/pc/code_twain/sln/usb_tools/scanner/usb/async_usb_host.cpp @@ -287,10 +287,10 @@ void async_usb_host::thread_pump_task(void) if (dh->is_complete() || err) { - reply = dyn_mem::memory(sizeof(PACK_BASE)); - pack = (LPPACK_BASE)reply->ptr(); - BASE_PACKET_REPLY(*pack, dh->get_packet_command() + 1, dh->get_packet_id(), err); - reply->set_len(sizeof(PACK_BASE)); + //reply = dyn_mem::memory(sizeof(PACK_BASE)); + //pack = (LPPACK_BASE)reply->ptr(); + //BASE_PACKET_REPLY(*pack, dh->get_packet_command() + 1, dh->get_packet_id(), err); + //reply->set_len(sizeof(PACK_BASE)); dh->release(); dh = nullptr; @@ -348,24 +348,27 @@ int async_usb_host::bulk_write_buf(uint8_t* buf, int* len) s = 0, err = 0; - while ((err = libusb_bulk_transfer(usb_handle_, bulk_out_.port, buf, l, &s, 1000)) == 0) + do { - if (cancel_write_) + while ((err = libusb_bulk_transfer(usb_handle_, bulk_out_.port, buf, l, &s, 1000)) == 0) { - err = ECANCELED; - break; + if (cancel_write_) + { + err = ECANCELED; + break; + } + + total += s; + if (total >= *len) + break; + + buf += s; + if (*len - total < bulk_size) + l = *len - total; + else + l = bulk_size; } - - total += s; - if (total >= *len) - break; - - buf += s; - if (*len - total < bulk_size) - l = *len - total; - else - l = bulk_size; - } + } while (err == LIBUSB_ERROR_INTERRUPTED); // should pay more attention to this error !!! *len = total; return err;