1)增加usb连接异常log

This commit is contained in:
masayume 2021-01-22 15:37:46 +08:00
parent d053ab534b
commit 2ac13fdcc5
7 changed files with 422 additions and 48 deletions

View File

@ -137,6 +137,7 @@ BOOL CBasicPage::OnInitDialog()
((CButton*)GetDlgItem(IDC_CKBSIZEDETECT))->ShowWindow(SW_HIDE); ((CButton*)GetDlgItem(IDC_CKBSIZEDETECT))->ShowWindow(SW_HIDE);
#endif // ISG100 #endif // ISG100
m_cmBoxColorMode = (CComboBox*)GetDlgItem(IDC_CMBCOLORTYPE); m_cmBoxColorMode = (CComboBox*)GetDlgItem(IDC_CMBCOLORTYPE);
m_cmBoxSS = (CComboBox*)GetDlgItem(IDC_CMBSS); m_cmBoxSS = (CComboBox*)GetDlgItem(IDC_CMBSS);
m_cmBoxResultion = (CComboBox*)GetDlgItem(IDC_CMBRESLUTION); m_cmBoxResultion = (CComboBox*)GetDlgItem(IDC_CMBRESLUTION);
@ -271,16 +272,14 @@ void CBasicPage::updateCmbDuplex(BOOL insert)
} }
#ifdef G200 #ifdef G200
#ifndef ISG100 #ifndef ISG100
if (tmp_paperindex == 16 || tmp_paperindex == 17) if (tmp_paperindex == 16 || tmp_paperindex == 17){
{
(((CButton*)GetDlgItem(IDC_CKBSIZEDETECT)))->SetCheck(false); (((CButton*)GetDlgItem(IDC_CKBSIZEDETECT)))->SetCheck(false);
GetDlgItem(IDC_CKBSIZEDETECT)->EnableWindow(false); GetDlgItem(IDC_CKBSIZEDETECT)->EnableWindow(false);
} }
else else{
{
GetDlgItem(IDC_CKBSIZEDETECT)->EnableWindow(true); GetDlgItem(IDC_CKBSIZEDETECT)->EnableWindow(true);
} }
#endif #endif // !ISG100
#endif // G200 #endif // G200
} }

View File

@ -185,6 +185,7 @@ void CTwainUI::UpdateUI()
m_pageImageProc->m_edit_hole.EnableWindow(settings->fillhole.is_fillhole == TRUE ? TRUE : FALSE); m_pageImageProc->m_edit_hole.EnableWindow(settings->fillhole.is_fillhole == TRUE ? TRUE : FALSE);
m_pageImageProc->m_ckbDetachNoise = settings->detachnoise.is_detachnoise == TRUE ? TRUE : FALSE;//黑白降噪是否启用 m_pageImageProc->m_ckbDetachNoise = settings->detachnoise.is_detachnoise == TRUE ? TRUE : FALSE;//黑白降噪是否启用
((CButton*)m_pageImageProc->GetDlgItem(IDC_CHECKDETACHNOISE))->SetCheck(m_pageImageProc->m_ckbDetachNoise); ((CButton*)m_pageImageProc->GetDlgItem(IDC_CHECKDETACHNOISE))->SetCheck(m_pageImageProc->m_ckbDetachNoise);
((CButton*)m_pageImageProc->GetDlgItem(IDC_CHECKDETACHNOISE))->EnableWindow(settings->pixtype != 2);
m_pageImageProc->m_edit_detachnoise.SetValue(settings->detachnoise.detachnoise); m_pageImageProc->m_edit_detachnoise.SetValue(settings->detachnoise.detachnoise);
m_pageImageProc->m_slider_detachnoise.EnableWindow(settings->detachnoise.is_detachnoise == TRUE ? TRUE : FALSE); m_pageImageProc->m_slider_detachnoise.EnableWindow(settings->detachnoise.is_detachnoise == TRUE ? TRUE : FALSE);
if (settings->pixtype == 2) if (settings->pixtype == 2)

View File

@ -5,6 +5,8 @@
#include <sstream> #include <sstream>
#include "Device/CJsonObject.hpp" #include "Device/CJsonObject.hpp"
GscanJsonConfig::GscanJsonConfig() GscanJsonConfig::GscanJsonConfig()
{ {
} }
@ -45,7 +47,7 @@ GScanCap GscanJsonConfig::GetDefaultGscancapValue()
gcap.autodescrew = TRUE;//自动纠偏 可用 gcap.autodescrew = TRUE;//自动纠偏 可用
gcap.enhance_color = EnchaceColor::Enhance_None;//默认不进行颜色增强 gcap.enhance_color = EnchaceColor::Enhance_None;//默认不进行颜色增强
gcap.en_fold = FALSE;//默认不对折 gcap.en_fold = FALSE;//默认不对折
gcap.fillbackground = TRUE;//ĬÈϲ»ÌîºÚ¿ò gcap.fillbackground = true;//ĬÈϲ»ÌîºÚ¿ò
gcap.fillhole.is_fillhole = FALSE; gcap.fillhole.is_fillhole = FALSE;
gcap.fillhole.fillholeratio = 10; gcap.fillhole.fillholeratio = 10;
gcap.detachnoise.detachnoise = 30; gcap.detachnoise.detachnoise = 30;
@ -266,27 +268,34 @@ GScanCap GscanJsonConfig::ReadGscanCap()
_tcscat(szIniFile, TWAIN_INIPATH); _tcscat(szIniFile, TWAIN_INIPATH);
_tcscat(szIniFile, TEXT("\\")); _tcscat(szIniFile, TEXT("\\"));
std::string dirpath = TCHAR2STRING(szIniFile); std::string dirpath = TCHAR2STRING(szIniFile);
bool is_exist = isFolderExist((char*)dirpath.c_str()); bool is_exist = isFileExist(dirpath+ TCHAR2STRING(TWAIN_JSON_NAME));
if (!is_exist) { if (is_exist)
createDirectory((char*)dirpath.c_str()); return JsonToGscancap(Readjson(dirpath + TCHAR2STRING(TWAIN_JSON_NAME)));
else{
_tcscat(szIniFile, TWAIN_JSON_NAME); createDirectory((char*)dirpath.c_str());
std::string dstpath = TCHAR2STRING(szIniFile); SaveGscancapJson(JsonToGscancap(GetDefaultJson()), dirpath + TCHAR2STRING(TWAIN_JSON_NAME));
vector<GScanCap> vc; return JsonToGscancap(Readjson(dirpath + TCHAR2STRING(TWAIN_JSON_NAME)));
vc.push_back(GetDefaultGscancapValue());
WriteJsonArrayToFile(vc, dstpath);
return vc[0];
} }
_tcscat(szIniFile, TWAIN_JSON_NAME); //if (!is_exist) {
std::string s_default = TCHAR2STRING(szIniFile); // createDirectory((char*)dirpath.c_str());
vector<GScanCap> vc; // _tcscat(szIniFile, TWAIN_JSON_NAME);
vc = ReadGscanCapsVector(s_default.c_str()); // std::string dstpath = TCHAR2STRING(szIniFile);
if (vc.size() != 0) // vector<GScanCap> vc;
{ // vc.push_back(GetDefaultGscancapValue());
return vc[0]; // WriteJsonArrayToFile(vc, dstpath);
} // return vc[0];
return GetDefaultGscancapValue(); //}
//_tcscat(szIniFile, TWAIN_JSON_NAME);
//std::string s_default = TCHAR2STRING(szIniFile);
//vector<GScanCap> vc;
//vc = ReadGscanCapsVector(s_default.c_str());
//if (vc.size() != 0)
//{
// return vc[0];
//}
//return GetDefaultGscancapValue();
} }
std::vector<GScanCap> GscanJsonConfig::ReadGscanCapsVector(const std::string gcapsfilepath) std::vector<GScanCap> GscanJsonConfig::ReadGscanCapsVector(const std::string gcapsfilepath)
@ -657,3 +666,190 @@ std::vector<GScanCap> GscanJsonConfig::parseJsonFromString(const std::string str
} }
return vcConfig; return vcConfig;
} }
void GscanJsonConfig::SaveGscancapJson(GScanCap cap, std::string path)
{
json js = GscancapToJson(cap);
std::ofstream of;
try {
of.open(path, std::ios::out);
of.write(js.dump().c_str(), js.dump().size());
of.close();
}
catch (...) {
if (of.is_open())
of.close();
}
}
json GscanJsonConfig::GscancapToJson(GScanCap& cap)
{
auto js = GetDefaultJson();
js[CONFIG][PIXTYPE] = cap.pixtype;
js[CONFIG][AUTOMATICCOLOR] = cap.automaticcolor;
js[CONFIG][AUTOMATICCOLORTYPR] = cap.automaticcolortype;
js[CONFIG][PAPARSIZE] = cap.papertype;
js[CONFIG][PAPERALIGN] = cap.paperAlign;
js[CONFIG][ENSIZECHECK] = cap.en_sizecheck;
js[CONFIG][AUTOCROP] = cap.is_autocrop;
js[CONFIG][RESOLUTION] = cap.resolution_dst;
js[CONFIG][DUPLEX] = cap.is_duplex;
js[CONFIG][DISCARBLANK] = cap.is_autodiscradblank_normal;
js[CONFIG][DISCARBLANKVINCE] = cap.is_autodiscradblank_vince;
js[CONFIG][DISCARBLANK_VALUE] = cap.discardblank_percent;
js[CONFIG][FLOD] = cap.en_fold;
js[CONFIG][SWITCHFRONTBACK] = cap.is_switchfrontback;
js[CONFIG][DETACHNOISE] = cap.detachnoise.is_detachnoise;
js[CONFIG][DETACHNOISEVALUE] = cap.detachnoise.detachnoise;
js[CONFIG][BRIGHTNESS] = cap.brightness;
js[CONFIG][AUTOCONTRAST] = cap.is_autocontrast;
js[CONFIG][CONTRAST] = cap.contrast;
js[CONFIG][GAMMA_] = cap.gamma;
js[CONFIG][FILTERTYPE] = cap.filter;
js[CONFIG][ENHANCECOLOR] = cap.enhance_color;
js[CONFIG][SHARPENTYPE] = cap.sharpen;
js[CONFIG][AUTODESCREW] = cap.autodescrew;
js[CONFIG][FILLBLACK] = cap.fillbackground;
js[CONFIG][MULTIOUTPUT] = cap.multi_output_red;
js[CONFIG][OUTHOLE] = cap.fillhole.is_fillhole;
js[CONFIG][OUTHOLERATIO] = cap.fillhole.fillholeratio;
js[CONFIG][HSVCORRECT] = cap.hsvcorrect;
js[CONFIG][ULTRADETECT] = cap.hardwarecaps.en_doublefeed;
js[CONFIG][BINDINGDETECT] = cap.hardwarecaps.en_stapledetect;
js[CONFIG][SCANCOUNT] = cap.scannum;
js[CONFIG][DOCORIENTATION] = cap.imageRotateDegree;
js[CONFIG][AUTO_TEXT] = cap.is_autotext;
js[CONFIG][BACKROTATE180] = cap.is_backrotate180;
js[CONFIG][DOGEAR_DETECTION] = cap.is_dogeardetection;
js[CONFIG][SCREWDETECT] = cap.hardwarecaps.en_skrewdetect;
js[CONFIG][SCREWLEVEL] = cap.hardwarecaps.skrewdetectlevel;
js[CONFIG][NOISE] = cap.noise;
js[CONFIG][INDENT] = cap.indent;
js[CONFIG][AUTOCROP_THRESHOLD] = cap.indent;
js[CONFIG][ISCONVEX] = cap.is_convex;
js[CONFIG][ITEMCAPTION] = cap.Caption;
js[CONFIG][SAVEPATH] = cap.SavePath;
return js;
}
GScanCap GscanJsonConfig::JsonToGscancap(json& js)
{
if (!js.is_object())
js = GetDefaultJson();
GScanCap cap{ 0 };
cap.pixtype = json_cast(js[CONFIG][PIXTYPE]).to_int();
cap.automaticcolor = json_cast(js[CONFIG][AUTOMATICCOLOR]).to_int();
cap.automaticcolortype = json_cast(js[CONFIG][AUTOMATICCOLORTYPR]).to_int();
cap.papertype = json_cast(js[CONFIG][PAPARSIZE]).to_int();
cap.paperAlign = static_cast<PaperAlign>(json_cast(js[CONFIG][PAPERALIGN]).to_uint8());
cap.en_sizecheck = json_cast(js[CONFIG][ENSIZECHECK]).to_int();
cap.is_autocrop = json_cast(js[CONFIG][AUTOCROP]).to_int();
cap.resolution_dst = json_cast(js[CONFIG][RESOLUTION]).to_float();
cap.is_duplex = json_cast(js[CONFIG][DUPLEX]).to_int();
cap.is_autodiscradblank_normal = json_cast(js[CONFIG][DISCARBLANK]).to_int();
cap.is_autodiscradblank_vince = json_cast(js[CONFIG][DISCARBLANKVINCE]).to_int();
cap.discardblank_percent = json_cast(js[CONFIG][DISCARBLANK_VALUE]).to_int();
cap.en_fold = json_cast(js[CONFIG][FLOD]).to_int();
cap.is_switchfrontback = json_cast(js[CONFIG][SWITCHFRONTBACK]).to_int();
cap.detachnoise.is_detachnoise = json_cast(js[CONFIG][DETACHNOISE]).to_int();
cap.detachnoise.detachnoise = json_cast(js[CONFIG][DETACHNOISEVALUE]).to_int();
cap.brightness = json_cast(js[CONFIG][BRIGHTNESS]).to_float();
cap.is_autocontrast = json_cast(js[CONFIG][AUTOCONTRAST]).to_int();
cap.contrast = json_cast(js[CONFIG][CONTRAST]).to_float();
cap.gamma = json_cast(js[CONFIG][GAMMA_]).to_float();
cap.filter = json_cast(js[CONFIG][FILTERTYPE]).to_int();
cap.enhance_color = json_cast(js[CONFIG][ENHANCECOLOR]).to_int();
cap.sharpen = json_cast(js[CONFIG][SHARPENTYPE]).to_int();
cap.autodescrew = json_cast(js[CONFIG][AUTODESCREW]).to_int();
cap.fillbackground = json_cast(js[CONFIG][FILLBLACK]).to_int();
cap.multi_output_red = json_cast(js[CONFIG][MULTIOUTPUT]).to_int();
cap.fillhole.is_fillhole = json_cast(js[CONFIG][OUTHOLE]).to_int();
cap.fillhole.fillholeratio = json_cast(js[CONFIG][OUTHOLERATIO]).to_int();
cap.hsvcorrect = json_cast(js[CONFIG][HSVCORRECT]).to_int();
cap.hardwarecaps.en_doublefeed = json_cast(js[CONFIG][ULTRADETECT]).to_int();
cap.hardwarecaps.en_stapledetect = json_cast(js[CONFIG][BINDINGDETECT]).to_int();
cap.scannum = json_cast(js[CONFIG][SCANCOUNT]).to_int();
cap.imageRotateDegree = json_cast(js[CONFIG][DOCORIENTATION]).to_int();
cap.is_autotext = json_cast(js[CONFIG][AUTO_TEXT]).to_int();
cap.is_backrotate180 = json_cast(js[CONFIG][BACKROTATE180]).to_int();
cap.is_dogeardetection = json_cast(js[CONFIG][DOGEAR_DETECTION]).to_int();
cap.hardwarecaps.en_skrewdetect = json_cast(js[CONFIG][SCREWDETECT]).to_int();
cap.hardwarecaps.skrewdetectlevel = json_cast(js[CONFIG][SCREWLEVEL]).to_int();
cap.noise = json_cast(js[CONFIG][NOISE]).to_int();
cap.indent = json_cast(js[CONFIG][INDENT]).to_int();
cap.AutoCrop_threshold = json_cast(js[CONFIG][AUTOCROP_THRESHOLD]).to_int();
cap.is_convex = json_cast(js[CONFIG][ISCONVEX]).to_int();
cap.Caption = json_cast(js[CONFIG][ITEMCAPTION]).to_string();
cap.SavePath = json_cast(js[CONFIG][SAVEPATH]).to_string();
return cap;
}
json GscanJsonConfig::GetDefaultJson()
{
return json::parse(R"({
"Config": {
"iPixType": 2 ,
"iautomaticcolor": false ,
"iautomaticcolortype": 1 ,
"iPaparSize": 0 ,
"iPaperAlign": 0 ,
"iEnSizeCheck": false ,
"bAuotCrop": true ,
"iResolution": 200 ,
"iDuplex": true ,
"bDiscardBlank": false ,
"bDiscardBlankVince": false ,
"discardblank_percent": 20 ,
"bFlod": false ,
"bSwitchFrontBack": false ,
"detachnoise": false ,
"detachnoisevalue": 30 ,
"iBrightness": 0 ,
"bAutoContrast": false ,
"iContrast": 0 ,
"dGamma": 1 ,
"iFilter": 3 ,
"iEnhance": 0 ,
"iSharpen": 0 ,
"bAutoDescrew": true ,
"bFillBlcak": true ,
"iMultiOutPut": false ,
"bOutHole": false ,
"iOutHoleRatio": 10 ,
"bHsvCorrect": false ,
"bUltrasonicDetect": true ,
"bBindingDetect": false ,
"ScanCount": 65535 ,
"bOrientation": 0 ,
"bAutoText": false ,
"iBackRotate180": false ,
"dogeardetection": false ,
"bScrewDetect": true ,
"iScrewLevel": 3 ,
"Noise": 40 ,
"Indent": 5 ,
"AutoCrop_Threshold": 40 ,
"isConvex": true ,
"Caption": "" ,
"SavePath": ""
}
})");
}
json GscanJsonConfig::Readjson(std::string path)
{
std::ifstream f;
f.open(path, std::ios::in);
json js;
try {
f.is_open() ? (js = json::parse(std::string((std::ostringstream()<<f.rdbuf()).str())),f.close()) : js="";
return js.is_object() ? throw std::exception("js pares error") : "";
}
catch (...)
{
f.is_open() ? f.close() : void();
return GetDefaultJson();
}
}

View File

@ -1,7 +1,81 @@
#pragma once #pragma once
#include "Device/PublicFunc.h" #include "Device/PublicFunc.h"
#include <vector> #include <vector>
#include <Device/json.hpp>
using json = nlohmann::json;
struct json_cast
{
json_cast(json s) :m_json(s) { if (s.is_null()) throw std::bad_alloc(); }
operator std::int16_t() {
return oper<std::int16_t>();
}
operator std::int64_t() {
return oper<std::int64_t>();
}
operator std::int8_t() {
return oper<std::int8_t>();
}
operator int() {
return oper<int>();
}
operator bool() {
if (m_json.is_boolean() or m_json.is_number() or m_json.is_number_unsigned() or m_json.is_number_float())
if (isbool())
return m_json.get<bool>();
else
return (int)m_json;
else
throw std::bad_typeid();
}
operator std::uint16_t() {
return oper<std::uint16_t>();
}
operator std::uint32_t() {
return oper<std::uint32_t>();
}
operator std::uint8_t() {
return oper<std::uint8_t>();
}
operator float() {
return oper<float>();
}
operator std::string() {
if (m_json.is_string())
return m_json;
else
return m_json.dump();
}
operator double() {
return oper<double>();
}
int to_int() { return operator int(); }
std::uint32_t to_uint32() { return operator std::uint32_t(); }
std::uint16_t to_uint16() { return operator std::uint16_t(); }
std::uint8_t to_uint8() { return operator std::uint8_t(); }
std::int16_t to_int16() { return operator std::int16_t(); }
std::int32_t to_int32() { return operator std::int32_t(); }
std::int8_t to_int8() { return operator std::int8_t(); }
bool to_bool() { return operator bool(); }
float to_float() { return operator float(); }
double to_double() { return operator double(); }
std::string to_string() { return operator std::string(); }
bool isbool() { return m_json.is_boolean() ? 1 : 0; }
template<typename T>
auto oper()->T {
if (m_json.is_boolean() or m_json.is_number() or m_json.is_number_unsigned() or m_json.is_number_float())
if (isbool())
return (T)m_json.get<bool>();
else
return T(m_json);
else
throw std::bad_typeid();
}
private:
json m_json;
};
class GscanJsonConfig class GscanJsonConfig
{ {
public: public:
@ -15,5 +89,12 @@ public:
std::vector<GScanCap> ReadGscanCapsVector(const std::string gcapsfilepath); bool DeleteJsonFile(std::string path); std::vector<GScanCap> ReadGscanCapsVector(const std::string gcapsfilepath); bool DeleteJsonFile(std::string path);
std::vector<GScanCap> parseJsonFromString(const std::string str); std::vector<GScanCap> parseJsonFromString(const std::string str);
json GscancapToJson(GScanCap& cap);
json GetDefaultJson();
json Readjson(std::string path);
void SaveGscancapJson(GScanCap cap, std::string path);
GScanCap JsonToGscancap(json& js);
}; };

View File

@ -14,6 +14,7 @@
#include "CIndicatorDlg.h" #include "CIndicatorDlg.h"
#include "Device/PublicFunc.h" #include "Device/PublicFunc.h"
#include "Device/GScanO200.h" #include "Device/GScanO200.h"
#include "Device/GScanO400.h"
#include "Device/filetools.h" #include "Device/filetools.h"
#include "Device/GScanVirtual.h" #include "Device/GScanVirtual.h"
#include <list> #include <list>
@ -21,6 +22,11 @@
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include "GscanJsonConfig.h" #include "GscanJsonConfig.h"
#include "G4Tiff.h" #include "G4Tiff.h"
#include "Device/UsbScanEx.h"
#ifdef WIN32
#include <Psapi.h>
#endif // WIN32
//custom define caps enum //custom define caps enum
enum class CapTypeEx : unsigned short { enum class CapTypeEx : unsigned short {
@ -225,6 +231,12 @@ static std::unique_ptr<IScanner> scanner; //(new GScanO200());
#else #else
static std::unique_ptr<IScanner> scanner(new GScanVirtual()); static std::unique_ptr<IScanner> scanner(new GScanVirtual());
#endif #endif
//long __stdcall callback(_EXCEPTION_POINTERS* excp)
//{
// MessageBox(0, L"Error", L"error", MB_OK);
// return EXCEPTION_CONTINUE_SEARCH;
//}
HuagaoDs::HuagaoDs() HuagaoDs::HuagaoDs()
: m_scanparam(new GScanCap) : m_scanparam(new GScanCap)
,bmpData(new std::vector<unsigned char>) ,bmpData(new std::vector<unsigned char>)
@ -237,10 +249,36 @@ HuagaoDs::HuagaoDs()
DWORD dwNum; DWORD dwNum;
CString aas[10]; CString aas[10];
GetDiskInfo(dwNum,aas);*/ GetDiskInfo(dwNum,aas);*/
//SetUnhandledExceptionFilter(callback);
//memoryinfo.reset(new std::thread([this]() {
// PROCESS_MEMORY_COUNTERS pmc;
// GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
// while (pmc.PeakPagefileUsage < 0x40000000&&m_memoryfalg){
// GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
// std::this_thread::sleep_for(std::chrono::milliseconds(10));
// }
// if (scanner.get()){
// scanner->Stop_scan();
// scanner->reset();
// scanner->ResetScanner();
// }
// //guiIndicator.reset();
// if (!m_memoryfalg)
// return;
// MessageBox(NULL, L"内存不足", L"警告", MB_OK| MB_SYSTEMMODAL);
//}));
} }
HuagaoDs::~HuagaoDs() HuagaoDs::~HuagaoDs()
{ {
if (memoryinfo.get()){
m_memoryfalg = false;
if (memoryinfo->joinable())
memoryinfo->join();
}
if(scanner.get()) if(scanner.get())
scanner.reset(); scanner.reset();
} }
@ -297,8 +335,10 @@ Result HuagaoDs::customDataSet(const Twpp::Identity& origin, Twpp::CustomData& d
str.resize(data.size()); str.resize(data.size());
auto pdata = data.lock<unsigned char>(); auto pdata = data.lock<unsigned char>();
memcpy((void*)str.c_str(), pdata, data.size()); memcpy((void*)str.c_str(), pdata, data.size());
vector<GScanCap> vc = js.parseJsonFromString(str); //vector<GScanCap> vc = js.parseJsonFromString(str);
m_scanparam.reset(new GScanCap(vc[0])); //m_scanparam.reset(new GScanCap(vc[0]));
GScanCap *cap = new GScanCap(js.JsonToGscancap(json::parse(str)));
m_scanparam.reset(cap);
return success(); return success();
} }
@ -632,8 +672,53 @@ void HuagaoDs::dogear_callback(int indexpaper)
Result HuagaoDs::identityOpenDs(const Identity&) { Result HuagaoDs::identityOpenDs(const Identity&) {
//writelog("identityOpenDs"); //writelog("identityOpenDs");
if(!scanner.get()) auto usblist= UsbScan_List::find_all_usb();
scanner.reset(new GScanO200()); int pid,vid;
if (!usblist.empty())
{
for each (auto &usb in usblist)
{
if (usb.vid == 0x064b && usb.pid == 0x7823){
if (!scanner.get()) {
#ifdef G100
scanner.reset(new GScanO200());
#endif //
#ifdef G200
scanner.reset(new GScanO200());
#endif // G200
#ifdef G300
scanner.reset(new GScanO400());
#endif // G300
#ifdef G400
scanner.reset(new GScanO400());
#endif // G400
vid = 0x064b; pid = 0x7823;
break;
}
}
#ifdef G100
if(usb.pid == 0x3072 && usb.vid == 0x100)
#endif //
#ifdef G200
if (usb.pid == 0x3072 && usb.vid == 0x200)
#endif // G200
#ifdef G300
if (usb.pid == 0x3072 && usb.vid == 0x300)
#endif // G300
#ifdef G400
if (usb.pid == 0x3072 && usb.vid == 0x400)
#endif // G400
{
pid = usb.pid; vid = usb.vid;
if(pid<=200&& (!scanner.get()))
scanner.reset(new GScanO200());
else
scanner.reset(new GScanO400());
break;
}
}
}
m_haveError = false; m_haveError = false;
updataGscanCap(); updataGscanCap();
bmpData->resize(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)); bmpData->resize(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));
@ -645,7 +730,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
#ifdef LANXUM #ifdef LANXUM
scanner->open(0x31c9, 0x8200); scanner->open(0x31c9, 0x8200);
#else #else
scanner->open(0x064B, 0x7823); scanner->open(vid, pid);
#endif #endif
if (!scanner->IsConnected()) { if (!scanner->IsConnected()) {
@ -663,7 +748,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
ShellExecute(NULL, TEXT("open"), GetHidedlgPath(), CString("202"), NULL, SW_HIDE); ShellExecute(NULL, TEXT("open"), GetHidedlgPath(), CString("202"), NULL, SW_HIDE);
return seqError(); return seqError();
} }
//MessageBox(NULL, L"2", L"", 0);
// init caps // init caps
// there are caps a minimal source must support // there are caps a minimal source must support
// query -> says which operations a cap supports // query -> says which operations a cap supports
@ -685,11 +770,13 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
}; };
m_query[CapType::UiControllable] = msgSupportGetAll; m_query[CapType::UiControllable] = msgSupportGetAll;
m_caps[CapType::UiControllable] = std::bind(enmGet<Bool>, _1, _2, Bool(true)); m_caps[CapType::UiControllable] = std::bind(oneValGet<Bool>, _1, _2, Bool(true));
m_query[CapType::DeviceOnline] = msgSupportGetAll; m_query[CapType::DeviceOnline] = msgSupportGetAll;
m_caps[CapType::DeviceOnline] = std::bind(enmGet<Bool>, _1, _2, Bool(scanner->IsConnected())); m_caps[CapType::DeviceOnline] = std::bind(enmGet<Bool>, _1, _2, Bool(scanner->IsConnected()));
m_query[CapType::XferCount] = msgSupportGetAllSetReset; m_query[CapType::XferCount] = msgSupportGetAllSetReset;
m_caps[CapType::XferCount] = [this](Msg msg, Capability& data) -> Result { m_caps[CapType::XferCount] = [this](Msg msg, Capability& data) -> Result {
if (msg == Msg::Set) { if (msg == Msg::Set) {
@ -729,9 +816,8 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
m_caps[CapType::IBitDepth] = [this](Msg msg, Capability& data) -> Result { m_caps[CapType::IBitDepth] = [this](Msg msg, Capability& data) -> Result {
if( Msg::Set==msg) { if( Msg::Set==msg) {
auto mech = data.currentItem<CapType::IBitDepth>(); auto mech = data.currentItem<CapType::IBitDepth>();
if (mech == 1 || mech == 8 || mech == 24){ if (((mech == 1) && (m_scanparam->pixtype == 0))|| ((mech == 8) && (m_scanparam->pixtype == 1)) || ((mech == 24) && (m_scanparam->pixtype == 2))) {
m_iBitdepth = (UINT16)mech; m_iBitdepth = (UINT16)mech;
m_scanparam->pixtype = m_iBitdepth == 1 ? (int)PixelType::BlackWhite : (m_iBitdepth == 8 ? (int)PixelType::Gray : (int)PixelType::Rgb);
return success(); return success();
} }
return badValue(); return badValue();
@ -740,7 +826,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
}; };
m_query[CapType::IBitOrder] = msgSupportGetAllSetReset; m_query[CapType::IBitOrder] = msgSupportGetAllSetReset;
m_caps[CapType::IBitOrder] = std::bind(enmGetSetConst<BitOrder>, _1, _2, BitOrder::MsbFirst); m_caps[CapType::IBitOrder] = std::bind(oneValGetSetConst<BitOrder>, _1, _2, BitOrder::MsbFirst);
m_query[CapType::IPlanarChunky] = msgSupportGetAllSetReset; m_query[CapType::IPlanarChunky] = msgSupportGetAllSetReset;
m_caps[CapType::IPlanarChunky] = std::bind(enmGetSetConst<PlanarChunky>, _1, _2, PlanarChunky::Chunky); m_caps[CapType::IPlanarChunky] = std::bind(enmGetSetConst<PlanarChunky>, _1, _2, PlanarChunky::Chunky);
@ -912,7 +998,8 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
#endif #endif
#endif // #endif //
},m_scanparam->papertype, PaperSize::A3, },m_scanparam->papertype, PaperSize::A3,
std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), m_scanparam->papertype)) == paperSizeList.size() ? 0 : std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), m_scanparam->papertype)), std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), m_scanparam->papertype)) == paperSizeList.size() ? 0 : std::distance(paperSizeList.begin(),
std::find(paperSizeList.begin(), paperSizeList.end(), m_scanparam->papertype)),
std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), 11))); std::distance(paperSizeList.begin(), std::find(paperSizeList.begin(), paperSizeList.end(), 11)));
}; };
@ -1005,7 +1092,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
m_caps[CapType::EnableDsUiOnly] = std::bind(enmGet<Bool>, _1, _2, Bool(true)); m_caps[CapType::EnableDsUiOnly] = std::bind(enmGet<Bool>, _1, _2, Bool(true));
m_query[CapType::PaperDetectable] = msgSupportGetAll; m_query[CapType::PaperDetectable] = msgSupportGetAll;
m_caps[CapType::PaperDetectable] = std::bind(enmGet<Bool>, _1, _2, Bool(true)); m_caps[CapType::PaperDetectable] = std::bind(oneValGet<Bool>, _1, _2, Bool(true));
m_query[CapType::FeederEnabled] = msgSupportGetAllSetReset; m_query[CapType::FeederEnabled] = msgSupportGetAllSetReset;
m_caps[CapType::FeederEnabled] = [this](Msg msg, Capability& data) -> Result { m_caps[CapType::FeederEnabled] = [this](Msg msg, Capability& data) -> Result {
@ -1040,7 +1127,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
m_bAutoFeed = mech; m_bAutoFeed = mech;
return success(); return success();
} }
return CapSupGetAllReset<bool, bool, CapType::AutoFeed>(msg, data, m_bAutoFeed, true); return CapSupGetAllReset<bool, Bool, CapType::AutoFeed>(msg, data, { false,true }, m_bAutoFeed, true, m_bAutoFeed ? 1 : 0, 1);
}; };
m_query[CapType::IImageFileFormat] = msgSupportGetAllSetReset; m_query[CapType::IImageFileFormat] = msgSupportGetAllSetReset;
m_caps[CapType::IImageFileFormat] = [this](Msg msg, Capability& data) -> Result { m_caps[CapType::IImageFileFormat] = [this](Msg msg, Capability& data) -> Result {
@ -1151,7 +1238,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
m_autoboarderdetcet = autodetectborder; m_autoboarderdetcet = autodetectborder;
return success(); return success();
} }
return CapSupGetAllReset<Bool, Bool, CapType::IAutomaticBorderDetection>(msg, data, m_autoboarderdetcet, false); return CapSupGetAllReset<Bool, Bool, CapType::IAutomaticBorderDetection>(msg, data, { false,true }, m_autoboarderdetcet, false, m_autoboarderdetcet ? 1 : 0, 0);
}; };
m_query[CapType::IImageMerge] = msgSupportGetAllSetReset; m_query[CapType::IImageMerge] = msgSupportGetAllSetReset;
@ -1546,7 +1633,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
m_scanparam->hardwarecaps.en_skrewdetect = mech; m_scanparam->hardwarecaps.en_skrewdetect = mech;
return success(); return success();
} }
return CapSupGetAllResetEx<byte, Bool, (CapType)CapTypeEx::TwEx_ScrewDetectEnable>(msg, data, { FALSE,TRUE }, m_scanparam->sharpen, FALSE, m_scanparam->hardwarecaps.en_skrewdetect ? 1 : 0, 0); return CapSupGetAllResetEx<byte, Bool, (CapType)CapTypeEx::TwEx_ScrewDetectEnable>(msg, data, { FALSE,TRUE }, m_scanparam->sharpen, TRUE, m_scanparam->hardwarecaps.en_skrewdetect ? 1 : 0, 0);
}; };
m_query[(CapType)(CapTypeEx::TwEx_ScrewLevel)] = msgSupportGetAllSetReset; m_query[(CapType)(CapTypeEx::TwEx_ScrewLevel)] = msgSupportGetAllSetReset;
@ -1589,7 +1676,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
m_scanparam->hardwarecaps.en_doublefeed = mech; m_scanparam->hardwarecaps.en_doublefeed = mech;
return success(); return success();
} }
return CapSupGetAllResetEx<byte, Bool, CapType::DoubleFeedDetection>(msg, data, m_scanparam->hardwarecaps.en_doublefeed, FALSE); return CapSupGetAllResetEx<byte, Bool, CapType::DoubleFeedDetection>(msg, data, m_scanparam->hardwarecaps.en_doublefeed, TRUE);
}; };
return success(); return success();
} }
@ -1723,11 +1810,14 @@ Result HuagaoDs::userInterfaceEnable(const Identity&, UserInterface& ui) {
if (!ui.showUi()) { if (!ui.showUi()) {
// this is an exception when we want to set state explicitly, notifyXferReady can be called only in enabled state // this is an exception when we want to set state explicitly, notifyXferReady can be called only in enabled state
// with hidden UI, the usual workflow DsState::Enabled -> notifyXferReady() -> DsState::XferReady is a single step // with hidden UI, the usual workflow DsState::Enabled -> notifyXferReady() -> DsState::XferReady is a single step
#ifndef G200
while (!scanner->Get_Scanner_PaperOn()) while (!scanner->Get_Scanner_PaperOn())
{ {
if (MessageBox(NULL, L"检测到无纸,请添加纸张", L"提示", MB_YESNO) == IDNO) if (MessageBox(NULL, L"检测到无纸,请添加纸张", L"提示", MB_YESNO | MB_SYSTEMMODAL) == IDNO)
return seqError(); return seqError();
} }
#endif // !G200
setState(DsState::Enabled); setState(DsState::Enabled);
auto ret = startScan(); auto ret = startScan();
//if (ret.status().condition() == Twpp::CC::NoMedia) //if (ret.status().condition() == Twpp::CC::NoMedia)
@ -1753,7 +1843,7 @@ Result HuagaoDs::userInterfaceEnableUiOnly(const Identity&, UserInterface& ui) {
Result HuagaoDs::imageInfoGet(const Identity&, ImageInfo& data) { Result HuagaoDs::imageInfoGet(const Identity&, ImageInfo& data) {
// our image does not change // our image does not change
if (m_pendingXfers == 0) if (m_pendingXfers == 0|| bmpData->size()==0)
return success(); return success();
auto dib = header(); auto dib = header();
data.setBitsPerPixel(static_cast<Int16>(dib->biBitCount)); data.setBitsPerPixel(static_cast<Int16>(dib->biBitCount));
@ -2045,13 +2135,15 @@ Twpp::Result HuagaoDs::showTwainUI(Twpp::UserInterface& ui, bool bUiOnly)
//!< show ui to scan button push //!< show ui to scan button push
auto scanFunction = [this](const GScanCap& caps) { auto scanFunction = [this](const GScanCap& caps) {
#ifndef G200
while (!scanner->Get_Scanner_PaperOn()) while (!scanner->Get_Scanner_PaperOn())
{ {
if (MessageBox(guiTwain.get()->GetSafeHwnd(), L"检测到无纸,请添加纸张", L"提示", MB_YESNO) == IDNO){ if (MessageBox(NULL, L"检测到无纸,请添加纸张", L"提示", MB_YESNO | MB_SYSTEMMODAL) == IDNO) {
m_pendingXfers = 0; m_pendingXfers = 0;
return; return;
} }
} }
#endif // !G200
m_pendingXfers = 1; m_pendingXfers = 1;
m_scanparam.reset(new GScanCap(caps)); m_scanparam.reset(new GScanCap(caps));
saveGscanCapSetting(); saveGscanCapSetting();
@ -2089,6 +2181,8 @@ Twpp::Result HuagaoDs::showTwainUI(Twpp::UserInterface& ui, bool bUiOnly)
guiTwain->Create(IDD_TWAINUI, parent); guiTwain->Create(IDD_TWAINUI, parent);
CRect newRect; CRect newRect;
::GetWindowRect(static_cast<HWND>(ui.parent().raw()), &newRect); ::GetWindowRect(static_cast<HWND>(ui.parent().raw()), &newRect);
if (newRect.top <= 0 || newRect.left <= 0)
newRect.top = newRect.left = 20;
SetWindowPos(guiTwain->m_hWnd, HWND_TOPMOST, newRect.left + 20, newRect.top + 100, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); SetWindowPos(guiTwain->m_hWnd, HWND_TOPMOST, newRect.left + 20, newRect.top + 100, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOACTIVATE);
guiTwain->ShowWindow(SW_SHOWNORMAL); guiTwain->ShowWindow(SW_SHOWNORMAL);
return success(); return success();
@ -2292,8 +2386,9 @@ void HuagaoDs::saveGscanCapSetting()
_tcscat(szIniFile, TEXT("\\")); _tcscat(szIniFile, TEXT("\\"));
_tcscat(szIniFile, TWAIN_JSON_NAME); _tcscat(szIniFile, TWAIN_JSON_NAME);
GscanJsonConfig js; GscanJsonConfig js;
vector<GScanCap> vc; //vector<GScanCap> vc;
vc.push_back(*m_scanparam); //vc.push_back(*m_scanparam);
std::string savepath = TCHAR2STRING(szIniFile); std::string savepath = TCHAR2STRING(szIniFile);
js.WriteJsonArrayToFile(vc, savepath); js.SaveGscancapJson(*m_scanparam, savepath);
//js.WriteJsonArrayToFile(vc, savepath);
} }

View File

@ -122,6 +122,8 @@ private://field
std::queue<Twpp::DeviceEvent> devEvent; std::queue<Twpp::DeviceEvent> devEvent;
std::unique_ptr < std::vector<unsigned char>> bmpData; std::unique_ptr < std::vector<unsigned char>> bmpData;
std::unique_ptr<GScanCap> m_scanparam; std::unique_ptr<GScanCap> m_scanparam;
std::unique_ptr<std::thread> memoryinfo;
bool m_memoryfalg = true;
HANDLE hMutex; HANDLE hMutex;
}; };

Binary file not shown.