1.增加CustomDSData 写入与获取功能

2 增加调用EnableDS接口USB重新Open功能,以防USB短线后,插上USB无法启动扫描
3.增加USBbulk端点读写检查,以防崩溃
This commit is contained in:
lovelyyoung 2020-07-26 17:07:40 +08:00
parent 93d0290c43
commit 19c001a85c
5 changed files with 93 additions and 15 deletions

View File

@ -283,7 +283,7 @@ std::string GScanO200::GetFWVersion()
std::string GScanO200::GetSerialNum() std::string GScanO200::GetSerialNum()
{ {
//return "G20018000298"; return "G20018000298";
if (m_usb.get() && m_usb->is_connected()) if (m_usb.get() && m_usb->is_connected())
{ {
std::lock_guard<std::mutex> lck(m_imgLocker); std::lock_guard<std::mutex> lck(m_imgLocker);
@ -482,7 +482,8 @@ void GScanO200::usbhotplug(bool isleft)
{ {
if (isleft) { if (isleft) {
//std::lock_guard<std::mutex> lck(m_Locker); //std::lock_guard<std::mutex> lck(m_Locker);
//FileTools::write_log("D:\\1.txt", "usbhotplug left"); //FileTools::
("D:\\1.txt", "usbhotplug left");
devState = DEV_WRONG; devState = DEV_WRONG;
Error_Code = USB_DISCONNECTED; Error_Code = USB_DISCONNECTED;
m_pImages->setscanflags(false); m_pImages->setscanflags(false);

View File

@ -12,9 +12,8 @@ public:
void SaveGscanCapConfig(const GScanCap& gcap, const std::string path); void SaveGscanCapConfig(const GScanCap& gcap, const std::string path);
void WriteJsonArrayToFile(std::vector<GScanCap> cfgArray, const std::string filename); void WriteJsonArrayToFile(std::vector<GScanCap> cfgArray, const std::string filename);
GScanCap ReadGscanCap(); GScanCap ReadGscanCap();
std::vector<GScanCap> ReadGscanCapsVector(const std::string gcapsfilepath); std::vector<GScanCap> ReadGscanCapsVector(const std::string gcapsfilepath); bool DeleteJsonFile(std::string path);
bool DeleteJsonFile(std::string path);
private:
std::vector<GScanCap> parseJsonFromString(const std::string str); std::vector<GScanCap> parseJsonFromString(const std::string str);
}; };

View File

@ -200,6 +200,48 @@ Result HuagaoDs::call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, vo
} }
} }
Result HuagaoDs::customDataGet(const Twpp::Identity& origin, Twpp::CustomData& data)
{
//从保存默认配置的文件路径读取字节流上传
TCHAR szIniFile[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE);
_tcscat(szIniFile, HUAGAO_SCAN);
_tcscat(szIniFile, TWAIN_INIPATH);
_tcscat(szIniFile, TEXT("\\"));
_tcscat(szIniFile, TWAIN_JSON_NAME);
string path = TCHAR2STRING(szIniFile);
int t;
FILE* file = fopen(path.c_str(), "rb");
fseek(file, 0, SEEK_END);
t = ftell(file);
//data = CustomData(t);
std::string buf(t, 0);
fseek(file, 0, SEEK_SET);
fread((void*)buf.c_str(), t, 1, file);
fclose(file);
data = CustomData(t);
auto pdata = data.lock<unsigned char>();
memcpy(pdata.data(), buf.c_str(), t);
return success();
}
Result HuagaoDs::customDataSet(const Twpp::Identity& origin, Twpp::CustomData& data)
{
GScanCap sc;
//将字节流转GscanCaps
GscanJsonConfig js;
std::string str;
str.resize(data.size());
auto pdata = data.lock<unsigned char>();
memcpy((void*)str.c_str(), pdata, data.size());
vector<GScanCap> vc = js.parseJsonFromString(str);
m_scanparam.reset(new GScanCap(vc[0]));
return success();
}
// some helper functions to handle capability stuff // some helper functions to handle capability stuff
template<typename T> template<typename T>
static Result oneValGet(Msg msg, Capability& data, const T& value) { static Result oneValGet(Msg msg, Capability& data, const T& value) {
@ -366,6 +408,10 @@ Result HuagaoDs::eventProcess(const Identity&, Event& event) {
return { ReturnCode::NotDsEvent, ConditionCode::Success }; return { ReturnCode::NotDsEvent, ConditionCode::Success };
} }
//Result HuagaoDs::customDataSet(const Twpp::Identity& origin, Twpp::CustomData& data)
//{
// return Result();
//}
//Twpp::Result HuagaoDs::deviceEventGet(const Twpp::Identity & origin, Twpp::DeviceEvent & data) //Twpp::Result HuagaoDs::deviceEventGet(const Twpp::Identity & origin, Twpp::DeviceEvent & data)
//{ //{
// data = DeviceEvent::simple(DeviceEvent::Type::PaperJam, Str255("HuaGo G200 Twain Device Error")); // data = DeviceEvent::simple(DeviceEvent::Type::PaperJam, Str255("HuaGo G200 Twain Device Error"));
@ -896,7 +942,19 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
m_bIndicator = show; m_bIndicator = show;
return success(); return success();
} }
default:
return capBadOperation();
}
};
m_query[CapType::CustomDsData] = msgSupportGetAll;
m_caps[CapType::CustomDsData] = [this](Msg msg, Capability& data) -> Result {
switch (msg) {
case Msg::Get:
case Msg::GetCurrent:
case Msg::GetDefault:
data = Capability::createOneValue<CapType::CustomDsData>(true);
return success();
default: default:
return capBadOperation(); return capBadOperation();
} }
@ -1862,6 +1920,7 @@ Result HuagaoDs::identityCloseDs(const Identity&) {
if (guiIndicator.get()) if (guiIndicator.get())
guiIndicator.reset(); guiIndicator.reset();
if (guiTwain.get()) if (guiTwain.get())
guiTwain.reset(); guiTwain.reset();
@ -1889,12 +1948,16 @@ Result HuagaoDs::pendingXfersGet(const Identity&, PendingXfers& data) {
Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data) { Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data) {
//!< end xfer if set count 0 //!< end xfer if set count 0
//FileTools::write_log("D:\\1.txt", "enter pendingXfersEnd");
if (bmpData.size() > 0) if (bmpData.size() > 0)
bmpData.clear(); bmpData.clear();
int ret = scanner->aquire_bmpdata(bmpData); int ret = scanner->aquire_bmpdata(bmpData);
//FileTools::write_log("D:\\1.txt", "enter pendingXfersEnd1");
if (ret != 0) { if (ret != 0) {
scanner->Set_ErrorCode(0); scanner->Set_ErrorCode(0);
guiIndicator.reset(); guiIndicator->ShowWindow(SW_HIDE);
//guiIndicator.reset();
if (ret != -1) { if (ret != -1) {
//ShellExecute(NULL, _T("open"), _T("aa.exe"), CString("1"), _T(""), SW_HIDE); //ShellExecute(NULL, _T("open"), _T("aa.exe"), CString("1"), _T(""), SW_HIDE);
//MessageBox(guiTwain ? guiTwain->m_hWnd : NULL, noticeMsgMap[ret], _T("Ìáʾ"), MB_SYSTEMMODAL | MB_OK | MB_ICONINFORMATION);// //MessageBox(guiTwain ? guiTwain->m_hWnd : NULL, noticeMsgMap[ret], _T("Ìáʾ"), MB_SYSTEMMODAL | MB_OK | MB_ICONINFORMATION);//
@ -1918,24 +1981,19 @@ Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data) {
#endif // LOG_NORMAL #endif // LOG_NORMAL
data.setCount(m_pendingXfers); data.setCount(m_pendingXfers);
//FileTools::write_log("D:\\1.txt", "exit pendingXfersEnd"+ m_pendingXfers==0?" 0":"1");
return success(); return success();
} }
Result HuagaoDs::pendingXfersReset(const Identity&, PendingXfers& data) { Result HuagaoDs::pendingXfersReset(const Identity&, PendingXfers& data) {
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter");
data.setCount(0); data.setCount(0);
if (scanner.get()) if (scanner.get())
{ {
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter0");
scanner->Stop_scan(); scanner->Stop_scan();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter1");
scanner->reset(); scanner->reset();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter2");
scanner->ResetScanner(); scanner->ResetScanner();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter4");
} }
guiIndicator.reset(); guiIndicator.reset();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset exit");
return success(); return success();
} }
@ -1952,9 +2010,11 @@ Result HuagaoDs::setupMemXferGet(const Identity&, SetupMemXfer& data) {
Result HuagaoDs::userInterfaceDisable(const Identity&, UserInterface& ui) { Result HuagaoDs::userInterfaceDisable(const Identity&, UserInterface& ui) {
//FileTools::write_log("D:\\1.txt", "userInterfaceDisable enter"); //FileTools::write_log("D:\\1.txt", "userInterfaceDisable enter");
if(guiTwain.get())
guiTwain.reset(); guiTwain.reset();
#if TWPP_DETAIL_OS_WIN #if TWPP_DETAIL_OS_WIN
if(guiBridge.get())
guiBridge.reset(); guiBridge.reset();
#endif #endif
//FileTools::write_log("D:\\1.txt", "userInterfaceDisable exit"); //FileTools::write_log("D:\\1.txt", "userInterfaceDisable exit");
@ -2130,7 +2190,7 @@ Result HuagaoDs::imageNativeXferGet(const Identity& id, ImageNativeXfer& data) {
data = ImageNativeXfer(bmpSize()); data = ImageNativeXfer(bmpSize());
std::copy(bmpBegin(), bmpEnd(), data.data<char>().data()); std::copy(bmpBegin(), bmpEnd(), data.data<char>().data());
#ifdef LOG_NORMAL #ifdef LOG_NORMAL
//FileTools::write_log("out.txt", "imageNativeXferGet " + std::to_string(++xtfer)); FileTools::write_log("out.txt", "imageNativeXferGet " + std::to_string(++xtfer));
#endif // LOG #endif // LOG
return { ReturnCode::XferDone, ConditionCode::Success }; return { ReturnCode::XferDone, ConditionCode::Success };
@ -2186,6 +2246,8 @@ Twpp::Result HuagaoDs::setupFileXferReset(const Twpp::Identity& origin, Twpp::Se
return badProtocol(); return badProtocol();
} }
static int indeximg = 0;
Twpp::Result HuagaoDs::imageFileXferGet(const Twpp::Identity& origin) Twpp::Result HuagaoDs::imageFileXferGet(const Twpp::Identity& origin)
{ {
if (!m_pendingXfers) if (!m_pendingXfers)
@ -2208,6 +2270,7 @@ Twpp::Result HuagaoDs::imageFileXferGet(const Twpp::Identity& origin)
break; break;
case ImageFileFormat::Tiff: case ImageFileFormat::Tiff:
case ImageFileFormat::Jfif: { case ImageFileFormat::Jfif: {
BITMAPINFOHEADER& bmpinfo = *((BITMAPINFOHEADER*)header()); BITMAPINFOHEADER& bmpinfo = *((BITMAPINFOHEADER*)header());
int decodetype; int decodetype;
if (bmpinfo.biBitCount == 24) if (bmpinfo.biBitCount == 24)
@ -2216,6 +2279,7 @@ Twpp::Result HuagaoDs::imageFileXferGet(const Twpp::Identity& origin)
decodetype = cv::IMREAD_GRAYSCALE; decodetype = cv::IMREAD_GRAYSCALE;
cv::Mat ims = cv::imdecode(bmpData, decodetype); cv::Mat ims = cv::imdecode(bmpData, decodetype);
std::vector<int> compression_params; std::vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(m_jpegQuality); compression_params.push_back(m_jpegQuality);

View File

@ -63,6 +63,19 @@ protected:
virtual Twpp::Result setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override; virtual Twpp::Result setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override; virtual Twpp::Result setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result call(const Twpp::Identity& origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data) override; virtual Twpp::Result call(const Twpp::Identity& origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data) override;
/// Get custom data TWAIN call.
/// Always called in correct state.
/// Default implementation does nothing.
/// \param origin Identity of the caller.
/// \param data Custom data.
virtual Twpp::Result customDataGet(const Twpp::Identity& origin, Twpp::CustomData& data) override;
/// Set custom data TWAIN call.
/// Always called in correct state.
/// Default implementation does nothing.
/// \param origin Identity of the caller.
/// \param data Custom data.
virtual Twpp::Result customDataSet(const Twpp::Identity& origin, Twpp::CustomData& data) override;
void SetResoluton(const char* path, int resolution); void SetResoluton(const char* path, int resolution);
private: private:
Twpp::Result showTwainUI(Twpp::UserInterface& data, bool bUiOnly = false); Twpp::Result showTwainUI(Twpp::UserInterface& data, bool bUiOnly = false);
@ -92,6 +105,7 @@ private:
unsigned short m_jpegQuality = 80; unsigned short m_jpegQuality = 80;
Twpp::Compression m_compression= Twpp::Compression::None; Twpp::Compression m_compression= Twpp::Compression::None;
bool m_bIndicator = true; bool m_bIndicator = true;
bool m_bCustomDsData = true;
bool m_bFeederEnabled = true; bool m_bFeederEnabled = true;
bool m_bAutoFeed = true; bool m_bAutoFeed = true;
UINT16 m_iBitdepth; UINT16 m_iBitdepth;

Binary file not shown.