1.修复USB拔插回调Bug

2.增加条件编译以支持智本版本
3.增加通信必要判断条件
This commit is contained in:
lovelyyoung 2020-07-20 10:29:10 +08:00
parent bbb5c44a6e
commit a778e653c7
12 changed files with 205 additions and 158 deletions

View File

@ -49,6 +49,12 @@ BOOL CAboutDlg::OnInitDialog()
SetDlgItemText(IDC_LBSERIALNUMVALUE, serialnum);
SetDlgItemText(IDC_LBDERIVERVERSON, HG_VERSION_INFO);
SetDlgItemText(IDC_LBCOMPANY, LIMIT_INFO);
#ifndef MAKEHUAGAO
GetDlgItem(IDC_PICABOUTHUAGO)->ShowWindow(FALSE);
#endif
SetDlgItemText(IDC_LBDESIGNERVALUE, COMPANY_NAME);
SetDlgItemText(IDC_LBCOMPANYADDRESS, COMPANY_ADDRESS);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}

View File

@ -46,7 +46,7 @@ BOOL CTwainUI::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Setup the tab control
int nPageID = 0;
this->SetWindowText(TWAIN_NAME);
auto dataChangeFunction = [this]() {
m_pageImageProc->ImageProcPageUpdate(m_pageBasic->m_cmBoxColorMode->GetCurSel());
@ -56,6 +56,7 @@ BOOL CTwainUI::OnInitDialog()
UpdateUi();
};
int nPageID = 0;
m_pageBasic.reset(new CBasicPage(dataChangeFunction));
m_pageBasic->Create(IDD_PAGEBASIC, this);
m_pageBasic->SetScannerInfo(m_hardwareVersion, m_serialnum);

View File

@ -14,8 +14,6 @@ class CBasicPage;
class CFeedPaperPage;
class CBrightnessPage;
/*帮助文档存储路径*/
#define DOCHELPPATH "C:/Windows/twain_32/HuagaoT/HuaGoScan TWAIN_Cs.chm"
/*配置文件默认索引号*/
#define SUPPORTRESNUMS 5
static int Resolutions[SUPPORTRESNUMS] = {100,150,200,240,300};

View File

@ -103,19 +103,6 @@ public:
void DoEvents() {
MSG msg;
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
//if (msg.message != WM_LBUTTONUP)
//{
// DispatchMessage(&msg);
// TranslateMessage(&msg);
//}
//else
//{
// if (!((msg.pt.x >= 240 && msg.pt.x <= 340) && (msg.pt.y >= 170 && msg.pt.y <= 240)))
// {
// DispatchMessage(&msg);
// TranslateMessage(&msg);
// }
//}
if (msg.message != WM_LBUTTONUP && bFilterMsg)
{
bFilterMsg = false;
@ -123,7 +110,6 @@ public:
}
DispatchMessage(&msg);
TranslateMessage(&msg);
}
}
protected:

View File

@ -154,8 +154,9 @@ GScanO200::~GScanO200()
devState = DEV_STOP;
m_threadUsb->join();
m_threadUsb.reset();
//writelog("~GScanO200");
}
if(m_usb.get())
m_usb.reset();
}
@ -339,7 +340,6 @@ void GScanO200::config_params(GScanCap& params)
void GScanO200::Scanner_StartScan(UINT16 count)
{
if (m_usb.get() && m_usb->is_connected()) {
std::lock_guard<std::mutex> lck(m_imgLocker);
if (m_threadUsb && m_threadUsb->joinable()) {
devState = DEV_STOP;
@ -347,7 +347,10 @@ void GScanO200::Scanner_StartScan(UINT16 count)
}
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));
switch (status.u32_Data)
@ -372,7 +375,9 @@ void GScanO200::Scanner_StartScan(UINT16 count)
#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);
@ -385,27 +390,24 @@ void GScanO200::Scanner_StartScan(UINT16 count)
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();
}
else
{
devState = DEV_WRONG;
Set_ErrorCode(USB_DISCONNECTED);
}
}
void GScanO200::Stop_scan()
{
if (m_usb.get() && !m_usb->is_connected()) {
return;
}
std::lock_guard<std::mutex> lck(m_imgLocker);
USBCB usbcb = { STOP ,0,0 };
if (m_usb.get() && m_usb->is_connected())
m_usb->write_bulk(&usbcb, sizeof(usbcb));
#ifdef G200
//m_pImages->setscanflags(false);
//devState = DEV_STOP;
@ -419,6 +421,7 @@ void GScanO200::ResetScanner()
std::lock_guard<std::mutex> lck(m_imgLocker);
USBCB usbcb = { INIT_HARDWARE_SYS ,0,0 };
if(m_usb.get() && m_usb->is_connected())
m_usb->write_bulk(&usbcb, sizeof(usbcb));
}
@ -450,23 +453,20 @@ void GScanO200::Set_ErrorCode(UINT32 value)
int GScanO200::get_scanned_num()
{
if (m_usb.get() && !m_usb->is_connected())
return -1;
std::lock_guard<std::mutex> lck(m_imgLocker);
USBCB usbcb = { GET_SCANN_NUM ,0,0 };
if (m_usb.get() && m_usb->is_connected())
m_usb->write_bulk(&usbcb, sizeof(usbcb));
return usbcb.u32_Count;
}
void GScanO200::clear_hwerror()
{
#ifndef G200
if (m_usb.get() && !m_usb->is_connected())
return;
std::lock_guard<std::mutex> lck(m_imgLocker);
USBCB usbcb = { CLEAR_HWERROR ,0,0 };
if (m_usb.get() && m_usb->is_connected())
m_usb->write_bulk(&usbcb, sizeof(usbcb));
#endif // !G200
@ -481,9 +481,12 @@ void GScanO200::usbhotplug_callback(bool isconnect, void* userdata)
void GScanO200::usbhotplug(bool isleft)
{
if (isleft) {
//std::lock_guard<std::mutex> lck(m_Locker);
//FileTools::write_log("D:\\1.txt", "usbhotplug left");
devState = DEV_WRONG;
Error_Code = USB_DISCONNECTED;
m_pImages->setscanflags(false);
if (m_usb.get())
m_usb.reset();
}
}
@ -511,11 +514,16 @@ void GScanO200::usbmain()
std::shared_ptr<std::vector<char>> imgData;
devState = DEV_ISRUNNING;
bool haveError = false;
////FileTools::write_log("D:\\1.txt", "thread usb start");
try
{
while (devState == DEV_ISRUNNING) {
if ((m_usb.get() && !m_usb->is_connected())) {
this_thread::sleep_for(chrono::milliseconds(200));
continue;
//FileTools::write_log("D:\\1.txt", "thread usb loop disconnect");
break;
}
////FileTools::write_log("D:\\1.txt", "thread usb start1");
//if (gcap.resolution_dst == 300.0f && gcap.en_fold) {
// if (m_pImages->orginimgcount() > 1)
@ -552,7 +560,7 @@ void GScanO200::usbmain()
//writelog("origin rawbuffer index " + std::to_string(++rawdataindex));
#ifdef LOG_NORMAL
static int rawdataindex = 0;
FileTools::write_log("out.txt", "Enquque rawbuffer index " + std::to_string(++rawdataindex));
//FileTools::write_log("out.txt", "Enquque rawbuffer index " + std::to_string(++rawdataindex));
#endif // LOG
m_usb->set_timeout(200);
Pop_Image();
@ -592,9 +600,17 @@ void GScanO200::usbmain()
default:
break;
}
this_thread::sleep_for(chrono::milliseconds(20));
this_thread::sleep_for(chrono::milliseconds(10));
}
}
catch (const std::exception& e)
{
writelog(e.what());
}
////FileTools::write_log("D:\\1.txt", "thread usb exit");
}
///////////////////////////////////////////////////////////////////////////
USBCB GScanO200::Get_Scanner_Status()
@ -602,9 +618,14 @@ USBCB GScanO200::Get_Scanner_Status()
if (m_usb.get() && !m_usb->is_connected()) {
return { NO_COMMAND ,PC_SCAN_BUSY_or_ERROR ,0 };
}
USBCB usbcb = { GET_DSP_STATUS ,0,0 };
if (m_usb.get() && m_usb->is_connected())
m_usb->write_bulk(&usbcb, sizeof(usbcb));
if (m_usb.get() && m_usb->is_connected())
m_usb->read_bulk(&usbcb, sizeof(usbcb));
return usbcb;
}

View File

@ -67,11 +67,6 @@ int ImageMatQueue::orginimgcount()
return atm_orgin_image_remains;
}
float ImageMatQueue::getdpi()
{
return scanParam.resolution_dst;
}
void ImageMatQueue::updatefixratio(float& hratio, float& vratio)
{
if (hratio > 0.80f && hratio < 1.2f && vratio >0.80f && vratio < 1.2f) {
@ -294,7 +289,7 @@ void ImageMatQueue::proc()
mat.release();
#else // G200
//resize(mat, mat, cv::Size(), 1.001, 1.0070);//用于修正与佳能机器幅面大小不匹配问题 此系数请勿轻易动
//cv::imwrite("D:\\org"+to_string(index)+".jpg", mat);
//cv::imwrite("D:\\org"+to_string(++index)+".jpg", mat);
Mat front = mat(Rect(0, 0, mat.cols / 2, mat.rows));
Mat back = mat(Rect(mat.cols / 2, 0, mat.cols / 2, mat.rows));
if (scanParam.imageRotateDegree != 0.0&&scanParam.imageRotateDegree!=180.0) {

View File

@ -163,7 +163,6 @@ public:
void run();
int orginimgcount();
void setscanflags(const bool flags) { is_scanning = flags; }
float getdpi();
void updatefixratio(float& hratio, float& vratio);
private:
void proc();

View File

@ -49,6 +49,7 @@ bool UsbScanEx::open()
&cbRet, NULL);
if (b_ret && m_usbscan_config.NumberOfPipes > 0) {
for (int by_i = 0x00; (ULONG)by_i < m_usbscan_config.NumberOfPipes; by_i++) {
TCHAR szPipePath[MAX_PATH] = { 0 };
_stprintf(szPipePath, TEXT("\\\\.\\Usbscan%d\\%d"), m_h_index, by_i);
m_usb_pipes[by_i].pipe_info = m_usbscan_config.PipeInfo[by_i];

View File

@ -64,9 +64,14 @@ using namespace std::placeholders;
TWPP_ENTRY_MFC(HuagaoDs)
static constexpr const Identity srcIdent(
Version(3, 3, Language::English, Country::China, "v3.3.2.3"),
Version(3, 3, Language::English, Country::China, "v3.3.2.4"),
DataGroup::Image,
#ifdef MAKEHUAGAO
"HUAGO",
#else // MAKEHUAGAO
"ZHIBEN",
#endif
#ifdef G200
#ifdef ISG100
"G100 Series",
@ -81,15 +86,32 @@ static constexpr const Identity srcIdent(
#ifdef G200
#ifdef ISG100
#ifndef MAKEHUAGAO
"ZhibenScan G100 TWAIN"
#else // !MAKEHUAGAO
"HUAGOSCAN G100 TWAIN"
#endif
#else // ISG100
#ifndef MAKEHUAGAO
"ZhibenScan G200 TWAIN"
#else // !MAKEHUAGAO
"HUAGOSCAN G200 TWAIN"
#endif
#endif
#elif defined(G300) // G200
#ifndef MAKEHUAGAO
"ZhibenScan G300 TWAIN"
#else // !MAKEHUAGAO
"HUAGOSCAN G300 TWAIN"
#endif
#elif defined(G400) // G200
#ifndef MAKEHUAGAO
"ZhibenScan G400 TWAIN"
#else // !MAKEHUAGAO
"HUAGOSCAN G400 TWAIN"
#endif
#endif
#if defined(_MSC_VER)
""
#elif defined(__GNUC__)
@ -144,9 +166,6 @@ static std::unique_ptr<IScanner> scanner(new GScanO200());
#else
static std::unique_ptr<IScanner> scanner(new GScanVirtual());
#endif
HuagaoDs::HuagaoDs()
: m_scanparam(new GScanCap)
, hMutex(NULL)
@ -162,6 +181,8 @@ HuagaoDs::HuagaoDs()
HuagaoDs::~HuagaoDs()
{
if(scanner.get())
scanner.reset();
}
const Identity& HuagaoDs::defaultIdentity() noexcept {
@ -1837,6 +1858,7 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
Result HuagaoDs::identityCloseDs(const Identity&) {
// no need to explicitly release any resources if using RAII
// TWPP will free the whole source on its own after this method
//FileTools::write_log("D:\\1.txt", "identityCloseDs enter");
if (guiIndicator.get())
guiIndicator.reset();
@ -1845,8 +1867,10 @@ Result HuagaoDs::identityCloseDs(const Identity&) {
if (guiBridge.get())
guiBridge.reset();
//FileTools::write_log("D:\\1.txt", "identityCloseDs enter1");
scanner.reset();
//FileTools::write_log("D:\\1.txt", "identityCloseDs enter2");
if (hMutex)
{
@ -1854,6 +1878,7 @@ Result HuagaoDs::identityCloseDs(const Identity&) {
CloseHandle(hMutex);
}
//saveGscanCapSetting();
//FileTools::write_log("D:\\1.txt", "identityCloseDs exit");
return success();
}
@ -1897,11 +1922,20 @@ Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data) {
}
Result HuagaoDs::pendingXfersReset(const Identity&, PendingXfers& data) {
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter");
data.setCount(0);
if (scanner.get())
{
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter0");
scanner->Stop_scan();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter1");
scanner->reset();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter2");
scanner->ResetScanner();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset enter4");
}
guiIndicator.reset();
//FileTools::write_log("D:\\1.txt", "pendingXfersReset exit");
return success();
}
@ -1916,11 +1950,15 @@ Result HuagaoDs::setupMemXferGet(const Identity&, SetupMemXfer& data) {
}
Result HuagaoDs::userInterfaceDisable(const Identity&, UserInterface& ui) {
//FileTools::write_log("D:\\1.txt", "userInterfaceDisable enter");
guiTwain.reset();
#if TWPP_DETAIL_OS_WIN
guiBridge.reset();
#endif
//FileTools::write_log("D:\\1.txt", "userInterfaceDisable exit");
return success();
}
Result HuagaoDs::userInterfaceEnable(const Identity&, UserInterface& ui) {
@ -2092,7 +2130,7 @@ Result HuagaoDs::imageNativeXferGet(const Identity& id, ImageNativeXfer& data) {
data = ImageNativeXfer(bmpSize());
std::copy(bmpBegin(), bmpEnd(), data.data<char>().data());
#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
return { ReturnCode::XferDone, ConditionCode::Success };
@ -2100,6 +2138,7 @@ Result HuagaoDs::imageNativeXferGet(const Identity& id, ImageNativeXfer& data) {
Twpp::Result HuagaoDs::pendingXfersStopFeeder(const Identity& origin, PendingXfers& data)
{
//FileTools::write_log("D:\\1.txt", "pendingXfersStopFeeder enter");
if (!scanner.get())
return seqError();
if (scanner->IsConnected()) {
@ -2107,6 +2146,7 @@ Twpp::Result HuagaoDs::pendingXfersStopFeeder(const Identity& origin, PendingXfe
}
data.setCount(scanner->Get_IsImageQueueEmpty() ? 0 : 1);
//FileTools::write_log("D:\\1.txt", "pendingXfersStopFeeder exit");
return success();
}

Binary file not shown.

Binary file not shown.

Binary file not shown.