diff --git a/huagao/Device/GScanO200.cpp b/huagao/Device/GScanO200.cpp index 279fb3d5..57fb3b92 100644 --- a/huagao/Device/GScanO200.cpp +++ b/huagao/Device/GScanO200.cpp @@ -307,9 +307,14 @@ BOOL GScanO200::Get_Scanner_PaperOn() return false; USBCB usbcb = { GET_PAPER_STATUS ,0,0 }; + usbcb.u32_Data = 1;//修改初始值防止通信异常时默认初始值为0报无纸 std::lock_guard lck(m_imgLocker); m_usb->write_bulk(&usbcb, sizeof(usbcb)); - m_usb->read_bulk(&usbcb, sizeof(usbcb)); + if (0 == m_usb->read_bulk(&usbcb, sizeof(usbcb))) + { + Set_ErrorCode(USB_DISCONNECTED); + return true; + } return usbcb.u32_Data != 0; } @@ -369,24 +374,23 @@ void GScanO200::Scanner_StartScan(UINT16 count) 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 }; +// paperstatus.u32_Data = 1; +// 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 m_pImages->reset_DogEar(); if (gcap.is_duplex) count = count == 65535 ? 65535 : count / 2; diff --git a/huagao/Device/GScanO400.cpp b/huagao/Device/GScanO400.cpp index 90eb7a0a..67f304b7 100644 --- a/huagao/Device/GScanO400.cpp +++ b/huagao/Device/GScanO400.cpp @@ -302,9 +302,14 @@ BOOL GScanO400::Get_Scanner_PaperOn() return false; USBCB usbcb = { GET_PAPER_STATUS ,0,0 }; + usbcb.u32_Data = 1; std::lock_guard lck(m_imgLocker); m_usb->write_bulk(&usbcb, sizeof(usbcb)); - m_usb->read_bulk(&usbcb, sizeof(usbcb)); + if (0 == m_usb->read_bulk(&usbcb, sizeof(usbcb))) + { + Set_ErrorCode(USB_DISCONNECTED); + return true; + } return usbcb.u32_Data != 0; } @@ -364,18 +369,21 @@ void GScanO400::Scanner_StartScan(UINT16 count) default: break; } - + int readlenght = 0; 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)); + readlenght= m_usb->read_bulk(&paperstatus, sizeof(paperstatus)); if (paperstatus.u32_Data == 0) { m_pImages->setscanflags(false); devState = DEV_WRONG; - Set_ErrorCode(NO_FEED); + int errorcode = 0; + readlenght == 0 ? errorcode = USB_DISCONNECTED : errorcode = NO_FEED; + + Set_ErrorCode(errorcode); if (huagods) - dev_callback(NO_FEED, huagods); + dev_callback(errorcode, huagods); return; } m_pImages->reset_DogEar(); diff --git a/huagao/GscanJsonConfig.cpp b/huagao/GscanJsonConfig.cpp index f47a8f45..4276adb0 100644 --- a/huagao/GscanJsonConfig.cpp +++ b/huagao/GscanJsonConfig.cpp @@ -728,7 +728,7 @@ json GscanJsonConfig::GscancapToJson(GScanCap& cap) js[CONFIG][SCREWLEVEL] = cap.hardwarecaps.skrewdetectlevel; js[CONFIG][NOISE] = cap.noise; js[CONFIG][INDENT] = cap.indent; - js[CONFIG][AUTOCROP_THRESHOLD] = cap.indent; + js[CONFIG][AUTOCROP_THRESHOLD] = cap.AutoCrop_threshold; js[CONFIG][ISCONVEX] = cap.is_convex; js[CONFIG][ITEMCAPTION] = cap.Caption; js[CONFIG][SAVEPATH] = cap.SavePath; @@ -737,6 +737,7 @@ json GscanJsonConfig::GscancapToJson(GScanCap& cap) GScanCap GscanJsonConfig::JsonToGscancap(json& js) { + if (!js.is_object()) js = GetDefaultJson(); GScanCap cap{ 0 }; @@ -844,8 +845,12 @@ json GscanJsonConfig::Readjson(std::string path) f.open(path, std::ios::in); json js; try { - f.is_open() ? (js = json::parse(std::string((std::ostringstream()<resize(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)); @@ -1789,23 +1792,6 @@ Result HuagaoDs::userInterfaceEnable(const Identity&, UserInterface& ui) { m_memXferYOff = 0; scanner->ResetMsgFiter(); - //if (m_capXferMech == Twpp::XferMech::Native) - //{ - // MessageBox(NULL, TEXT("Native"), _T("bb"), MB_OK); - //} - //else if (m_capXferMech == Twpp::XferMech::File) - //{ - // MessageBox(NULL, TEXT("File"), _T("bb"), MB_OK); - - //} - //else if (m_capXferMech == Twpp::XferMech::Memory) - //{ - // MessageBox(NULL, TEXT("Memory"), _T("bb"), MB_OK); - //} - //else - //{ - // MessageBox(NULL, TEXT("MemoryFile"), _T("bb"), MB_OK); - //} if (!ui.showUi()) { // this is an exception when we want to set state explicitly, notifyXferReady can be called only in enabled state @@ -2147,6 +2133,12 @@ Twpp::Result HuagaoDs::showTwainUI(Twpp::UserInterface& ui, bool bUiOnly) m_pendingXfers = 1; m_scanparam.reset(new GScanCap(caps)); saveGscanCapSetting(); + if (scanner->get_ErrorCode() == USB_DISCONNECTED) + { + MessageBox(NULL, L"USB连接异常,请连接USB后重新打开扫描软件", L"提示", MB_OK | MB_SYSTEMMODAL); + return; + } + if (startScan() == success()) { notifyXferReady(); } @@ -2251,7 +2243,7 @@ Twpp::Result HuagaoDs::startScan() #ifdef LANXUM scanner->open(0x31c9, 0x8200); #else - scanner->open(0x064B, 0x7823); + scanner->open(vid, pid); #endif if (!scanner->IsConnected()) return checkDeviceOnline(); diff --git a/huagao/huagaods.hpp b/huagao/huagaods.hpp index 3bc2bf90..c33d6e5e 100644 --- a/huagao/huagaods.hpp +++ b/huagao/huagaods.hpp @@ -125,6 +125,7 @@ private://field std::unique_ptr memoryinfo; bool m_memoryfalg = true; HANDLE hMutex; + int pid = 0, vid = 0; }; diff --git a/huagao/stdafx.h b/huagao/stdafx.h index a3c39314..a248c11e 100644 Binary files a/huagao/stdafx.h and b/huagao/stdafx.h differ diff --git a/twpp/datasource.hpp b/twpp/datasource.hpp index a58d24dd..d37596d3 100644 --- a/twpp/datasource.hpp +++ b/twpp/datasource.hpp @@ -625,7 +625,6 @@ namespace Twpp { if (!inState(DsState::Enabled, DsState::Xferring)) { return seqError(); } - return eventProcess(origin, data); } @@ -2151,6 +2150,7 @@ namespace Twpp { /// TWAIN entry, do not call from data source. static ReturnCode entry(Identity* origin, DataGroup dg, Dat dat, Msg msg, void* data) noexcept { auto src = find(origin); + //FileTools::write_log("D:\\1.txt", "call:datagroup-" + to_string((int)dg) + "dat-" + to_string(int(dat)) + "msg-" + to_string(int(msg))); try { auto rc = src == g_sources.end() ? staticControl(origin, dg, dat, msg, data) :