2023-05-04 06:55:26 +00:00
|
|
|
|
#include "device_user.h"
|
|
|
|
|
#include <QMessageBox>
|
2023-05-16 10:31:32 +00:00
|
|
|
|
#include "HGUIGlobal.h"
|
|
|
|
|
#include <thread>
|
2023-05-04 06:55:26 +00:00
|
|
|
|
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
DeviceUserMgr::DeviceUserMgr(QString password, QWidget *wnd)
|
2023-05-04 06:55:26 +00:00
|
|
|
|
{
|
2023-05-16 10:31:32 +00:00
|
|
|
|
m_password = password;
|
2023-05-04 06:55:26 +00:00
|
|
|
|
m_wnd = wnd;
|
|
|
|
|
m_twainDSM = nullptr;
|
|
|
|
|
HGTwain_CreateDSM((HWND)m_wnd->winId(), &m_twainDSM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUserMgr::~DeviceUserMgr()
|
|
|
|
|
{
|
|
|
|
|
HGTwain_DestroyDSM(m_twainDSM);
|
|
|
|
|
m_twainDSM = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
|
|
|
|
|
{
|
|
|
|
|
HGTwainDS ds = nullptr;
|
|
|
|
|
HGTwain_OpenSelectedDSEx(m_twainDSM, &ds);
|
|
|
|
|
if (nullptr == ds)
|
|
|
|
|
return nullptr;
|
2023-05-16 10:31:32 +00:00
|
|
|
|
return new DeviceUser(m_wnd, ds, m_password);
|
2023-05-04 06:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds, QString password)
|
2023-05-04 06:55:26 +00:00
|
|
|
|
{
|
|
|
|
|
m_wnd = wnd;
|
|
|
|
|
m_twainDS = ds;
|
2023-05-16 10:31:32 +00:00
|
|
|
|
m_password = password;
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(closeReq()), this, SLOT(on_closeReq()), Qt::QueuedConnection);
|
2023-05-04 06:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUser::~DeviceUser()
|
|
|
|
|
{
|
|
|
|
|
HGTwain_CloseDS(m_twainDS);
|
|
|
|
|
m_twainDS = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DeviceUser::GetName()
|
|
|
|
|
{
|
|
|
|
|
HGChar devName[256];
|
|
|
|
|
HGTwain_GetDSName(m_twainDS, devName, 256);
|
|
|
|
|
return QString(devName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::ShowSettingDlg()
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_EnableDSUIOnly(m_twainDS, (HWND)m_wnd->winId(), DSCloseReqFunc, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::StartScan()
|
|
|
|
|
{
|
2023-05-19 10:41:49 +00:00
|
|
|
|
return HGTwain_EnableDS(m_twainDS, HGFALSE, (HWND)m_wnd->winId(), DSCloseReqFunc, this, DSImageFunc, this);
|
2023-05-04 06:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
HGResult DeviceUser::StartSingleScan()
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_EnableDSWithSingleScan(m_twainDS, DSCloseReqFunc, this, DSImageFunc, this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
|
HGResult DeviceUser::StopScan()
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_DisableDS(m_twainDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info)
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_GetDSDeviceCustomInfo(m_twainDS, info);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 10:29:08 +00:00
|
|
|
|
QString DeviceUser::GetDriverLog()
|
2023-05-16 10:31:32 +00:00
|
|
|
|
{
|
2023-05-17 10:29:08 +00:00
|
|
|
|
HGChar driverLogPath[256] = { "D:\\123\\driver-log.txt" };
|
|
|
|
|
HGResult ret = HGTwain_GetDSDriverLog(m_twainDS, driverLogPath);
|
|
|
|
|
if (ret == HGBASE_ERR_OK)
|
|
|
|
|
return driverLogPath;
|
|
|
|
|
|
|
|
|
|
return "";
|
2023-05-16 10:31:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearDriverLog()
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_ClearDSDriverLog(m_twainDS);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 10:29:08 +00:00
|
|
|
|
QString DeviceUser::GetDeviceLog()
|
2023-05-16 10:31:32 +00:00
|
|
|
|
{
|
2023-05-17 10:29:08 +00:00
|
|
|
|
HGChar deviceLogPath[256] = { "D:\\123\\device-log.txt" };
|
|
|
|
|
HGResult ret = HGTwain_GetDSDeviceLog(m_twainDS, deviceLogPath);
|
|
|
|
|
if (ret == HGBASE_ERR_OK)
|
|
|
|
|
return deviceLogPath;
|
|
|
|
|
|
|
|
|
|
return "";
|
2023-05-16 10:31:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearDeviceLog()
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_ClearDSDeviceLog(m_twainDS);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
|
void HGAPI DeviceUser::DSCloseReqFunc(HGTwainDS ds, HGPointer param)
|
|
|
|
|
{
|
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
2023-05-17 09:39:26 +00:00
|
|
|
|
HGTwain_DisableDS(p->m_twainDS);
|
2023-05-04 06:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param)
|
|
|
|
|
{
|
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
|
|
|
|
HGImage image2 = nullptr;
|
|
|
|
|
HGBase_CloneImage(image, 0, 0, &image2);
|
|
|
|
|
if (nullptr != image2)
|
|
|
|
|
{
|
|
|
|
|
emit p->newImage(image2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
void DeviceUser::on_closeReq()
|
|
|
|
|
{
|
2023-05-17 09:39:26 +00:00
|
|
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
|
// HGTwain_DisableDS(m_twainDS);
|
2023-05-16 10:31:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
|
#else
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
DeviceUserMgr::DeviceUserMgr(QString password, QWidget *wnd)
|
2023-05-04 06:55:26 +00:00
|
|
|
|
{
|
|
|
|
|
m_wnd = wnd;
|
|
|
|
|
m_saneMgr = nullptr;
|
2023-05-16 10:31:32 +00:00
|
|
|
|
m_password = password;
|
2023-05-04 06:55:26 +00:00
|
|
|
|
HGSane_CreateManager(&m_saneMgr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUserMgr::~DeviceUserMgr()
|
|
|
|
|
{
|
|
|
|
|
HGSane_DestroyManager(m_saneMgr);
|
|
|
|
|
m_saneMgr = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
|
|
|
|
|
{
|
|
|
|
|
HGSaneSource source = nullptr;
|
|
|
|
|
HGSane_OpenSelectedSource(m_saneMgr, m_wnd, &source);
|
|
|
|
|
if (nullptr == source)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
HGUInt devCount = 0;
|
|
|
|
|
HGSane_GetDeviceCount(source, &devCount);
|
|
|
|
|
if (0 == devCount)
|
|
|
|
|
{
|
|
|
|
|
HGSane_CloseSource(source);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
else if (1 == devCount)
|
|
|
|
|
{
|
|
|
|
|
HGChar errInfo[256];
|
|
|
|
|
HGSaneDevice dev = nullptr;
|
|
|
|
|
HGSane_OpenDevice(source, 0, &dev, errInfo, 256);
|
|
|
|
|
if (nullptr == dev)
|
|
|
|
|
{
|
|
|
|
|
HGSane_CloseSource(source);
|
|
|
|
|
QMessageBox::information(m_wnd, tr("tips"), QString::fromUtf8(errInfo));
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
return new DeviceUser(m_wnd, source, dev, m_password);
|
2023-05-04 06:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGSaneDevice dev = nullptr;
|
|
|
|
|
HGSane_OpenSelectedDevice(source, m_wnd, &dev);
|
|
|
|
|
if (nullptr == dev)
|
|
|
|
|
{
|
|
|
|
|
HGSane_CloseSource(source);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
return new DeviceUser(m_wnd, source, dev, m_password);
|
2023-05-04 06:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
DeviceUser::DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev, QString password)
|
2023-05-04 06:55:26 +00:00
|
|
|
|
{
|
|
|
|
|
m_wnd = wnd;
|
|
|
|
|
m_source = source;
|
|
|
|
|
m_saneDev = dev;
|
2023-05-16 10:31:32 +00:00
|
|
|
|
m_password = password;
|
2023-05-04 06:55:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUser::~DeviceUser()
|
|
|
|
|
{
|
|
|
|
|
HGSane_CloseDevice(m_saneDev);
|
|
|
|
|
m_saneDev = nullptr;
|
|
|
|
|
HGSane_CloseSource(m_source);
|
|
|
|
|
m_source = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DeviceUser::GetName()
|
|
|
|
|
{
|
|
|
|
|
HGChar devName[256];
|
|
|
|
|
HGSane_GetSourceName(m_source, devName, 256);
|
|
|
|
|
return QString(devName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::ShowSettingDlg()
|
|
|
|
|
{
|
|
|
|
|
return HGSane_ShowDeviceSettingDlg(m_saneDev, m_wnd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::StartScan()
|
|
|
|
|
{
|
|
|
|
|
return HGSane_StartDeviceWithUI(m_saneDev, m_wnd, DeviceImageFunc, this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
HGResult DeviceUser::StartSingleScan();
|
|
|
|
|
{
|
|
|
|
|
return HGSane_StartDeviceWithSingleScan(m_saneDev, m_wnd, DeviceImageFunc, this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
|
HGResult DeviceUser::StopScan()
|
|
|
|
|
{
|
|
|
|
|
return HGSane_StopDevice(m_saneDev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::GetDeviceCustomInfo(HGSaneCustomInfo *info)
|
|
|
|
|
{
|
|
|
|
|
return HGSane_GetDeviceCustomInfo(m_saneDev, info);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
|
void HGAPI DeviceUser::DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param)
|
|
|
|
|
{
|
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
|
|
|
|
HGImage image2 = nullptr;
|
|
|
|
|
HGBase_CloneImage(image, 0, 0, &image2);
|
|
|
|
|
if (nullptr != image2)
|
|
|
|
|
{
|
|
|
|
|
emit p->newImage(image2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|