diff --git a/huagao/Device/GScanO200.cpp b/huagao/Device/GScanO200.cpp index ff24bd28..1e44aef5 100644 --- a/huagao/Device/GScanO200.cpp +++ b/huagao/Device/GScanO200.cpp @@ -156,7 +156,7 @@ GScanO200::~GScanO200() m_threadUsb->join(); m_threadUsb.reset(); } - if(m_usb.get()) + if (m_usb.get()) m_usb.reset(); } @@ -299,7 +299,7 @@ std::string GScanO200::GetSerialNum() if (m_usb.get() && m_usb->is_connected()) { std::lock_guard lck(m_imgLocker); - //if (SerialNum.empty()) { + if (SerialNum.empty()) { #ifndef G200 SerialNum.resize(14); #else // !G200 @@ -309,7 +309,7 @@ std::string GScanO200::GetSerialNum() m_usb->write_bulk(&usbcb, sizeof(usbcb)); m_usb->read_bulk(&SerialNum[0], SerialNum.size()); - //} + } return SerialNum; } return ""; @@ -352,69 +352,69 @@ void GScanO200::config_params(GScanCap& params) void GScanO200::Scanner_StartScan(UINT16 count) { - std::lock_guard lck(m_imgLocker); - if (m_threadUsb && m_threadUsb->joinable()) { - devState = DEV_STOP; - m_threadUsb->join(); - } + std::lock_guard lck(m_imgLocker); + if (m_threadUsb && m_threadUsb->joinable()) { + devState = DEV_STOP; + m_threadUsb->join(); + } - USBCB status = { GET_DSP_STATUS ,0,0 }; - if (m_usb.get() && m_usb->is_connected()) - m_usb->write_bulk(&status, sizeof(status)); + USBCB status = { GET_DSP_STATUS ,0,0 }; + if (m_usb.get() && m_usb->is_connected()) + m_usb->write_bulk(&status, sizeof(status)); - if (m_usb.get() && m_usb->is_connected()) - m_usb->read_bulk(&status, sizeof(status)); + if (m_usb.get() && m_usb->is_connected()) + m_usb->read_bulk(&status, sizeof(status)); - switch (status.u32_Data) - { - case COUNT_MODE: - case NO_FEED: - case OPEN_COVER: - case FEED_IN_ERROR: - case PAPER_JAM: - case DETECT_DOUBLE_FEED: - case DETECT_STAPLE: - case PAPER_SKEW: - case HARDWARE_ERROR: - case PC_SCAN_BUSY_or_ERROR: - m_pImages->setscanflags(false); - devState = DEV_WRONG; - Set_ErrorCode(status.u32_Data); - if (huagods) - dev_callback(status.u32_Data, huagods); - return; - default: - break; - } + switch (status.u32_Data) + { + case COUNT_MODE: + case NO_FEED: + case OPEN_COVER: + case FEED_IN_ERROR: + case PAPER_JAM: + case DETECT_DOUBLE_FEED: + case DETECT_STAPLE: + case PAPER_SKEW: + case HARDWARE_ERROR: + case PC_SCAN_BUSY_or_ERROR: + m_pImages->setscanflags(false); + devState = DEV_WRONG; + Set_ErrorCode(status.u32_Data); + if (huagods) + dev_callback(status.u32_Data, huagods); + return; + default: + break; + } -//#ifndef G200 - USBCB paperstatus = { GET_PAPER_STATUS ,0,0 }; - if (m_usb.get() && m_usb->is_connected()) - m_usb->write_bulk(&paperstatus, sizeof(paperstatus)); - if (m_usb.get() && m_usb->is_connected()) - m_usb->read_bulk(&paperstatus, sizeof(paperstatus)); - if (paperstatus.u32_Data == 0) { - m_pImages->setscanflags(false); - devState = DEV_WRONG; - Set_ErrorCode(NO_FEED); - if (huagods) - dev_callback(NO_FEED, huagods); - return; - } -//#endif // !G200 +#ifndef G200 + USBCB paperstatus = { GET_PAPER_STATUS ,0,0 }; + if (m_usb.get() && m_usb->is_connected()) + m_usb->write_bulk(&paperstatus, sizeof(paperstatus)); + if (m_usb.get() && m_usb->is_connected()) + m_usb->read_bulk(&paperstatus, sizeof(paperstatus)); + if (paperstatus.u32_Data == 0) { + m_pImages->setscanflags(false); + devState = DEV_WRONG; + Set_ErrorCode(NO_FEED); + if (huagods) + dev_callback(NO_FEED, huagods); + return; + } +#endif // !G200 - if (gcap.is_duplex) - count = count == 65535 ? 65535 : count / 2; - USBCB usbcb = { START_COMMAND,(UINT32)count ,0 }; - if (m_usb.get() && m_usb->is_connected()) - m_usb->write_bulk(&usbcb, sizeof(usbcb)); - this_thread::sleep_for(std::chrono::milliseconds(200)); - if (m_usb.get() && m_usb->is_connected()) - { - m_pImages->setscanflags(true); - m_threadUsb.reset(new std::thread(&GScanO200::usbmain, this)); - m_pImages->run(); - } + if (gcap.is_duplex) + count = count == 65535 ? 65535 : count / 2; + USBCB usbcb = { START_COMMAND,(UINT32)count ,0 }; + if (m_usb.get() && m_usb->is_connected()) + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + this_thread::sleep_for(std::chrono::milliseconds(200)); + if (m_usb.get() && m_usb->is_connected()) + { + m_pImages->setscanflags(true); + m_threadUsb.reset(new std::thread(&GScanO200::usbmain, this)); + m_pImages->run(); + } } void GScanO200::Stop_scan() @@ -425,6 +425,7 @@ void GScanO200::Stop_scan() m_usb->write_bulk(&usbcb, sizeof(usbcb)); } + void GScanO200::ResetScanner() { if (m_usb.get() && !m_usb->is_connected()) @@ -432,7 +433,7 @@ void GScanO200::ResetScanner() std::lock_guard lck(m_imgLocker); USBCB usbcb = { INIT_HARDWARE_SYS ,0,0 }; - if(m_usb.get() && m_usb->is_connected()) + if (m_usb.get() && m_usb->is_connected()) m_usb->write_bulk(&usbcb, sizeof(usbcb)); } @@ -556,7 +557,15 @@ void GScanO200::usbmain() return; } - if (gcap.resolution_dst >= 300.0f) + if (gcap.resolution_dst == 200.0f) + { + if (m_pImages->orginimgcount() > 5) + { + this_thread::sleep_for(chrono::milliseconds(10)); + continue; + } + } + else if(gcap.resolution_dst>200.0f) { if (m_pImages->orginimgcount() > 2) { @@ -578,6 +587,7 @@ void GScanO200::usbmain() writelog("imgData->size() error"); break; } + m_pImages->pushMat(std::shared_ptr(new G200Decode(imgData))); //static int rawdataindex = 0; //writelog("origin rawbuffer index " + std::to_string(++rawdataindex)); @@ -665,16 +675,29 @@ std::shared_ptr> GScanO200::Get_Img_Data(int bufferSize) std::shared_ptr> imData(new std::vector(bufferSize)); StopWatch sw; int readed = 0; - while (readed < bufferSize && sw.elapsed_ms() < 5000) { - USBCB usbcb = { GET_IMAGE,0,(UINT32)bufferSize }; - m_usb->write_bulk(&usbcb, sizeof(usbcb)); - readed = m_usb->read_bulk(imData->data(), bufferSize); + USBCB usbcb = { GET_IMAGE,0,bufferSize }; + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + int totalength = bufferSize; + int startindex = 0; + while (totalength > 0) + { + int dstlength = 1024 * 1024; + if (totalength <= dstlength) + { + dstlength = totalength; + totalength = 0; + } + else + totalength -= dstlength; + + int tt = m_usb->read_bulk(imData->data() + startindex, dstlength); + startindex += dstlength; } - if (sw.elapsed_ms() > 3000) { + if (sw.elapsed_ms() > 5000) + { writelog("Usb read data timeout\n"); } - return imData; }