增加extral twain协议,disableDS前延时100ms

This commit is contained in:
yangjiaxuan 2023-05-16 18:31:32 +08:00
parent 2486288684
commit da1c7a31d4
5 changed files with 205 additions and 75 deletions

View File

@ -1,10 +1,13 @@
#include "device_user.h"
#include <QMessageBox>
#include "HGUIGlobal.h"
#include <thread>
#if defined(HG_CMP_MSC)
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
DeviceUserMgr::DeviceUserMgr(QString password, QWidget *wnd)
{
m_password = password;
m_wnd = wnd;
m_twainDSM = nullptr;
HGTwain_CreateDSM((HWND)m_wnd->winId(), &m_twainDSM);
@ -22,13 +25,16 @@ class DeviceUser* DeviceUserMgr::OpenDeviceUser()
HGTwain_OpenSelectedDSEx(m_twainDSM, &ds);
if (nullptr == ds)
return nullptr;
return new DeviceUser(m_wnd, ds);
return new DeviceUser(m_wnd, ds, m_password);
}
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds)
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds, QString password)
{
m_wnd = wnd;
m_twainDS = ds;
m_password = password;
connect(this, SIGNAL(closeReq()), this, SLOT(on_closeReq()), Qt::QueuedConnection);
}
DeviceUser::~DeviceUser()
@ -54,6 +60,11 @@ HGResult DeviceUser::StartScan()
return HGTwain_EnableDS(m_twainDS, HGFALSE, nullptr, DSCloseReqFunc, this, DSImageFunc, this);
}
HGResult DeviceUser::StartSingleScan()
{
return HGTwain_EnableDSWithSingleScan(m_twainDS, DSCloseReqFunc, this, DSImageFunc, this);
}
HGResult DeviceUser::StopScan()
{
return HGTwain_DisableDS(m_twainDS);
@ -64,11 +75,49 @@ HGResult DeviceUser::GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info)
return HGTwain_GetDSDeviceCustomInfo(m_twainDS, info);
}
HGResult DeviceUser::Login()
{
return HGTwain_LoginDS(m_twainDS, "user", getStdString(m_password).c_str());
}
HGResult DeviceUser::Logout()
{
return HGTwain_LogoutDS(m_twainDS);
}
HGResult DeviceUser::ClearRollerCount()
{
return HGTwain_ClearDSRollerCount(m_twainDS);
}
QString DeviceUser::GetDriverLogPath()
{
HGChar driverLogPath[256];
HGTwain_GetDSDriverLogPath(m_twainDS, driverLogPath, 256);
return getStdFileName(driverLogPath);
}
HGResult DeviceUser::ClearDriverLog()
{
return HGTwain_ClearDSDriverLog(m_twainDS);
}
QString DeviceUser::GetDeviceLogPath()
{
HGChar deviceLogPath[256];
HGTwain_GetDSDriverLogPath(m_twainDS, deviceLogPath, 256);
return getStdFileName(deviceLogPath);
}
HGResult DeviceUser::ClearDeviceLog()
{
return HGTwain_ClearDSDeviceLog(m_twainDS);
}
void HGAPI DeviceUser::DSCloseReqFunc(HGTwainDS ds, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;
HGTwain_DisableDS(p->m_twainDS);
emit p->finishScan();
emit p->closeReq();
}
void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param)
@ -82,12 +131,19 @@ void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param)
}
}
void DeviceUser::on_closeReq()
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
HGTwain_DisableDS(m_twainDS);
}
#else
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
DeviceUserMgr::DeviceUserMgr(QString password, QWidget *wnd)
{
m_wnd = wnd;
m_saneMgr = nullptr;
m_password = password;
HGSane_CreateManager(&m_saneMgr);
}
@ -123,7 +179,7 @@ class DeviceUser* DeviceUserMgr::OpenDeviceUser()
return nullptr;
}
return new DeviceUser(m_wnd, source, dev);
return new DeviceUser(m_wnd, source, dev, m_password);
}
HGSaneDevice dev = nullptr;
@ -134,14 +190,15 @@ class DeviceUser* DeviceUserMgr::OpenDeviceUser()
return nullptr;
}
return new DeviceUser(m_wnd, source, dev);
return new DeviceUser(m_wnd, source, dev, m_password);
}
DeviceUser::DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev)
DeviceUser::DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev, QString password)
{
m_wnd = wnd;
m_source = source;
m_saneDev = dev;
m_password = password;
}
DeviceUser::~DeviceUser()
@ -169,6 +226,11 @@ HGResult DeviceUser::StartScan()
return HGSane_StartDeviceWithUI(m_saneDev, m_wnd, DeviceImageFunc, this);
}
HGResult DeviceUser::StartSingleScan();
{
return HGSane_StartDeviceWithSingleScan(m_saneDev, m_wnd, DeviceImageFunc, this);
}
HGResult DeviceUser::StopScan()
{
return HGSane_StopDevice(m_saneDev);
@ -179,6 +241,45 @@ HGResult DeviceUser::GetDeviceCustomInfo(HGSaneCustomInfo *info)
return HGSane_GetDeviceCustomInfo(m_saneDev, info);
}
HGResult DeviceUser::Login()
{
return HGSane_Login(m_saneDev, "user", getStdString(m_password).c_str());
}
HGResult DeviceUser::Logout()
{
return HGSane_Logout(m_saneDev);
}
HGResult DeviceUser::ClearRollerCount()
{
return HGSane_ClearRollerCount(m_saneDev);
}
QString DeviceUser::GetDriverLogPath()
{
HGChar driverLogPath[256];
HGSane_GetDriverLogPath(m_saneDev, driverLogPath, 256);
return getStdFileName(driverLogPath);
}
HGResult DeviceUser::ClearDriverLog()
{
return HGSane_ClearDriverLog(m_saneDev);
}
QString DeviceUser::GetDeviceLogPath()
{
HGChar deviceLogPath[256];
HGSane_GetDeviceLogPath(m_saneDev, deviceLogPath, 256);
return getStdFileName(deviceLogPath);
}
HGResult DeviceUser::ClearDeviceLog()
{
return HGSane_ClearDeviceLog(m_saneDev);
}
void HGAPI DeviceUser::DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param)
{
DeviceUser* p = (DeviceUser*)param;

View File

@ -4,7 +4,7 @@
#include "base/HGDef.h"
#include <QDialog>
#if defined(HG_CMP_MSC)
#if defined (HG_CMP_MSC)
#include "twain_user/HGTwain.h"
class DeviceUserMgr : public QObject
@ -12,7 +12,7 @@ class DeviceUserMgr : public QObject
Q_OBJECT
public:
DeviceUserMgr(QWidget *wnd);
DeviceUserMgr(QString password, QWidget *wnd);
~DeviceUserMgr();
// 弹出设备选择对话框选择twain源
@ -21,6 +21,7 @@ public:
private:
QWidget *m_wnd;
HGTwainDSM m_twainDSM;
QString m_password;
};
class DeviceUser : public QObject
@ -28,7 +29,7 @@ class DeviceUser : public QObject
Q_OBJECT
friend class DeviceUserMgr;
DeviceUser(QWidget *wnd, HGTwainDS ds);
DeviceUser(QWidget *wnd, HGTwainDS ds, QString password);
public:
~DeviceUser();
@ -38,8 +39,16 @@ public:
HGResult ShowSettingDlg();
// 弹出扫描对话框
HGResult StartScan();
HGResult StartSingleScan();
HGResult StopScan();
HGResult GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info);
HGResult Login();
HGResult Logout();
HGResult ClearRollerCount();
QString GetDriverLogPath();
HGResult ClearDriverLog();
QString GetDeviceLogPath();
HGResult ClearDeviceLog();
private:
static void HGAPI DSCloseReqFunc(HGTwainDS ds, HGPointer param);
@ -47,11 +56,15 @@ private:
signals:
void newImage(void *image);
void finishScan();
void closeReq();
private slots:
void on_closeReq();
private:
QWidget *m_wnd;
HGTwainDS m_twainDS;
QString m_password;
};
#else
@ -62,7 +75,7 @@ class DeviceUserMgr : public QObject
Q_OBJECT
public:
DeviceUserMgr(QWidget *wnd);
DeviceUserMgr(QString password, QWidget *wnd);
~DeviceUserMgr();
// 弹出设备选择对话框,选择设备
@ -70,6 +83,7 @@ public:
private:
QWidget *m_wnd;
QString m_password;
HGSaneManager m_saneMgr;
};
@ -78,7 +92,7 @@ class DeviceUser : public QObject
Q_OBJECT
friend class DeviceUserMgr;
DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev);
DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev, QString password);
public:
~DeviceUser();
@ -88,20 +102,28 @@ public:
HGResult ShowSettingDlg();
// 弹出扫描对话框
HGResult StartScan();
HGResult StartSingleScan();
HGResult StopScan();
HGResult GetDeviceCustomInfo(HGSaneCustomInfo *info);
HGResult Login();
HGResult Logout();
HGResult ClearRollerCount();
QString GetDriverLogPath();
HGResult ClearDriverLog();
QString GetDeviceLogPath();
HGResult ClearDeviceLog();
private:
static void HGAPI DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param);
signals:
void newImage(void *image);
void finishScan();
private:
QWidget *m_wnd;
HGSaneSource m_source;
HGSaneDevice m_saneDev;
QString m_password;
};
#endif

View File

@ -85,9 +85,6 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
{
ui->setupUi(this);
m_devUserMgr = new DeviceUserMgr(this);
m_devUser = nullptr;
m_versionDll = new VersionDll;
HGBase_RegisterCrashFunc(CrashFunc, this);
@ -356,6 +353,9 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
else
m_password = passwordDecrypt(password);
m_devUserMgr = new DeviceUserMgr(m_password, this);
m_devUser = nullptr;
m_dlgFullScreen = nullptr;
ui->act_autoSave->setChecked(getCfgValue("save", "autoSave", false));
@ -1141,12 +1141,6 @@ void MainWindow::on_newImage(void *image)
}
}
void MainWindow::on_finishScan()
{
m_isScanning = false;
updateActionStatus();
}
void MainWindow::on_wrong_image_decide(dialog_wrong_img* dlg, bool save)
{
int i = 0;
@ -2571,7 +2565,13 @@ void MainWindow::on_act_signIn_triggered()
m_admin_loggedIn = dlg.exec();
updateActionStatus();
if (m_admin_loggedIn)
{
if (m_devUser != nullptr)
{
m_devUser->Login();
}
m_versionDll->PostUserLoginInfo(HGVERSION_APPNAME_SCANNER, m_oemName);
}
}
void MainWindow::on_act_passwordChange_triggered()
@ -2596,6 +2596,11 @@ void MainWindow::on_act_signOut_triggered()
return;
}
if (m_devUser != nullptr)
{
m_devUser->Logout();
}
QMessageBox msg(QMessageBox::Question, tr("Question"),
tr("Sure to sign out administrator account?"), QMessageBox::Yes | QMessageBox::No);
msg.exec();
@ -2648,23 +2653,24 @@ void MainWindow::on_act_clearRoller_triggered()
return;
}
// QMessageBox msg(QMessageBox::Question, tr("confirm operation"),
// tr("are you sure to clear the roller count?"),
// QMessageBox::Yes | QMessageBox::No, this);
// msg.exec();
// if(msg.clickedButton() != msg.button(QMessageBox::Yes))
// return;
QMessageBox msg(QMessageBox::Question, tr("confirm operation"),
tr("are you sure to clear the roller count?"),
QMessageBox::Yes | QMessageBox::No, this);
msg.exec();
if(msg.clickedButton() != msg.button(QMessageBox::Yes))
return;
// unsigned int count = 0;
// int ret = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT, nullptr, &count);
// if(ret == SANE_STATUS_GOOD)
// {
// QMessageBox::information(this, tr("hint"), tr("Roller scanned count has been set to 0."));
// m_versionDll->PostDeviceClearRollerInfo(m_currDeviceName.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str());
// }
// else
// QMessageBox::information(this, tr("hint"), tr("Roller scanned count reset failed."));
if (m_devUser != nullptr)
{
HGResult ret = m_devUser->ClearRollerCount();
if(ret == HGBASE_ERR_OK)
{
QMessageBox::information(this, tr("tips"), tr("Roller scanned count has been set to 0."));
// m_versionDll->PostDeviceClearRollerInfo();
}
else
QMessageBox::information(this, tr("tips"), tr("Roller scanned count reset failed."));
}
}
void MainWindow::on_act_help_triggered()
@ -2823,7 +2829,6 @@ void MainWindow::on_act_acquire_triggered()
}
else
{
m_isScanning = true;
m_thumb->setAcceptDrops(false);
updateActionStatus();
}
@ -2859,7 +2864,7 @@ void MainWindow::on_act_acquireSingle_triggered()
HGResult ret = HGBASE_ERR_FAIL;
if (nullptr != m_devUser)
{
ret = m_devUser->StartScan();
ret = m_devUser->StartSingleScan();
}
if (ret != HGBASE_ERR_OK)
@ -3639,39 +3644,34 @@ void MainWindow::on_act_feedback_triggered()
void MainWindow::on_act_driver_log_triggered()
{
// char log_file_path[260] = {0};
// unsigned int type = SANE_LogFileType::LOG_FILE_DRIVER;
// SANE_Status statu = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_LOG_FILE, log_file_path, &type);
// if(statu == SANE_STATUS_GOOD)
// {
// if(log_file_path[0])
// QDesktopServices::openUrl(QUrl::fromLocalFile(log_file_path));
// }
// else {
// if(statu == SANE_STATUS_UNSUPPORTED) // 鐠佹儳顦稉宥嗘暜閹镐浇顕氶幙宥勭稊
// QMessageBox::information(this, windowTitle(), tr("The device does not support this operation"));
// else
// QMessageBox::information(this, windowTitle(), tr("IO error")); // IO闁挎瑨顕?
// }
if (m_devUser != nullptr)
{
QString driverLogPath = m_devUser->GetDriverLogPath();
if (!driverLogPath.isEmpty())
{
QDesktopServices::openUrl(QUrl::fromLocalFile(driverLogPath));
}
else
{
QMessageBox::information(this, tr("tips"), tr("The device does not support this operation"));
}
}
}
void MainWindow::on_act_device_log_triggered()
{
// char log_file_path[260] = {0};
// unsigned int type = SANE_LogFileType::LOG_FILE_DEVICE;
// SANE_Status statu = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_LOG_FILE, log_file_path, &type);
// if(statu == SANE_STATUS_GOOD)
// {
// if(log_file_path[0])
// QDesktopServices::openUrl(QUrl::fromLocalFile(log_file_path));
// }
// else {
// if(statu == SANE_STATUS_UNSUPPORTED)
// QMessageBox::information(this, windowTitle(), tr("The device does not support this operation"));
// else
// QMessageBox::information(this, windowTitle(), tr("IO error"));
// }
if (m_devUser != nullptr)
{
QString deviceLogPath = m_devUser->GetDeviceLogPath();
if (!deviceLogPath.isEmpty())
{
QDesktopServices::openUrl(QUrl::fromLocalFile(deviceLogPath));
}
else
{
QMessageBox::information(this, tr("tips"), tr("The device does not support this operation"));
}
}
}
void MainWindow::on_act_simpCN_triggered()
@ -3759,7 +3759,6 @@ void MainWindow::on_act_selectDevice_triggered()
if (nullptr != m_devUser)
{
disconnect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)));
disconnect(m_devUser, SIGNAL(finishScan()), this, SLOT(on_finishScan()));
delete m_devUser;
m_devUser = nullptr;
}

View File

@ -114,7 +114,6 @@ private slots:
void on_multiPageLineEditFinished();
void on_clearCache();
void on_newImage(void *image);
void on_finishScan();
void on_wrong_image_decide(dialog_wrong_img* dlg, bool save);
void on_m_pbtn_push_clicked();
void on_dialog_sideBar_applyToImage(HGImage img, int brightness, int contrast, double gamma, bool enhanceText);

View File

@ -436,12 +436,15 @@ HGResult HGTwainDSImpl::GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info)
return HGBASE_ERR_OK;
}
#pragma pack(push)
#pragma pack(1)
struct LoginType
{
TW_UINT16 ItemType;
TW_UINT32 NumItems;
TW_STR32 Value[2];
};
#pragma pack(pop)
HGResult HGTwainDSImpl::Login(const HGChar *user, const HGChar *pwd)
{
@ -621,11 +624,14 @@ HGResult HGTwainDSImpl::Disable()
return HGBASE_ERR_OK;
}
#pragma pack(push)
#pragma pack(1)
struct CapInt32Type
{
TW_UINT16 ItemType;
TW_INT32 Value;
};
#pragma pack(pop)
HGResult HGTwainDSImpl::SetCapInt32(HGUInt cap, HGInt value)
{
@ -701,11 +707,14 @@ HGResult HGTwainDSImpl::GetCapInt32(HGUInt cap, HGInt* value)
return ret;
}
#pragma pack(push)
#pragma pack(1)
struct CapStr255Type
{
TW_UINT16 ItemType;
TW_STR255 Value;
};
#pragma pack(pop)
HGResult HGTwainDSImpl::SetCapStr255(HGUInt cap, const HGChar *value)
{