mirror of http://192.168.1.51:8099/lmh188/twain3.0
添加扫描休眠状态判断,修复部分崩溃问题。
This commit is contained in:
parent
6a8302a066
commit
72f7212930
|
@ -85,6 +85,8 @@ typedef enum tagUsbSupported {
|
|||
V4L2_AQULRE_ERROR = 79,
|
||||
//扫描仪内部图片丢失
|
||||
V4L2_IMAGE_EMPTY = 80,
|
||||
//处于休眠中
|
||||
SLEEPING = 81,
|
||||
//USB 未连接
|
||||
USB_DISCONNECTED = 200,
|
||||
//用户点击停止
|
||||
|
@ -116,6 +118,7 @@ static map<UsbSupported, string> msgs = {
|
|||
{UsbSupported::USB_BULK_ERROR,"USB数据读取错误!"},
|
||||
{UsbSupported::V4L2_AQULRE_ERROR,"扫描仪取图失败!"},
|
||||
{UsbSupported::V4L2_IMAGE_EMPTY,"扫描仪图像处理异常!"},
|
||||
{UsbSupported::SLEEPING,"设备处于休眠模式,请唤醒休眠后再扫描!"},
|
||||
};
|
||||
|
||||
enum tagEventIndex
|
||||
|
|
|
@ -10,9 +10,9 @@ static std::mutex mx_ctrl;
|
|||
|
||||
static int scanner_read_reg(std::shared_ptr<IUsb>& usb, int addr)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mx_ctrl);
|
||||
if (usb.get() && usb->is_connected()) {
|
||||
int val = 0;
|
||||
std::lock_guard<std::mutex> lck(mx_ctrl);
|
||||
usb->control_msg(0xc0, USB_REQ_GET_DEV_REGS, addr, 0, 4, &val);
|
||||
return val;
|
||||
}
|
||||
|
@ -21,17 +21,16 @@ static int scanner_read_reg(std::shared_ptr<IUsb>& usb, int addr)
|
|||
|
||||
static void scanner_write_reg(std::shared_ptr<IUsb>& usb, int addr, int val)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mx_ctrl);
|
||||
if (usb.get() && usb->is_connected())
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mx_ctrl);
|
||||
usb->control_msg(0x40, USB_REQ_SET_DEV_REGS, addr, 0, 4, &val);
|
||||
}
|
||||
}
|
||||
|
||||
static void scanner_cmd(std::shared_ptr<IUsb>& usb, int cmd)
|
||||
{
|
||||
if (usb.get() && usb->is_connected())
|
||||
scanner_write_reg(usb, 0, cmd);
|
||||
scanner_write_reg(usb, 0, cmd);
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,7 +40,7 @@ GScanO1003399::GScanO1003399():
|
|||
,m_imgprocthread(1)
|
||||
{
|
||||
im_data.reset(new std::vector<char>());
|
||||
open(0, 0);
|
||||
//open(0x3072, 0x139);
|
||||
if (!m_usbthread.get()) {
|
||||
b_usbthread = true;
|
||||
m_usbthread.reset(new thread(&GScanO1003399::usb_run, this));
|
||||
|
@ -72,7 +71,7 @@ void GScanO1003399::open(int vid, int pid)
|
|||
if (m_usb.get()&&m_usb->is_connected())
|
||||
return;
|
||||
//auto lsusb = CyUsbList::find_all();
|
||||
auto lsusb = UsbScan_List::find_vid_pid(0x3072, 0x0139);
|
||||
auto lsusb = UsbScan_List::find_vid_pid(vid, pid);
|
||||
if (!lsusb.empty())
|
||||
{
|
||||
m_usb = *lsusb.begin();
|
||||
|
@ -323,6 +322,13 @@ void GScanO1003399::Scanner_StartScan(UINT16 count)
|
|||
keeplastimg = true;
|
||||
reset();
|
||||
devState = DEV_ISRUNNING;
|
||||
if (scanner_read_reg(m_usb, SR_GET_SLEEP_STAUTUS) != 1)
|
||||
{
|
||||
devState = DEV_WRONG;
|
||||
Set_ErrorCode(SLEEPING);
|
||||
scanflag = false;
|
||||
return;
|
||||
}
|
||||
if (scan_mode())
|
||||
{
|
||||
devState = DEV_WRONG;
|
||||
|
@ -497,7 +503,7 @@ int GScanO1003399::scan_mode()
|
|||
|
||||
int GScanO1003399::count()
|
||||
{
|
||||
return scanner_read_reg(m_usb, SR_SCAN_COUNT);
|
||||
return scanner_read_reg(m_usb, SR_GET_ROLLER_NUM);
|
||||
}
|
||||
|
||||
void GScanO1003399::abort_dev_tx()
|
||||
|
@ -599,7 +605,8 @@ int GScanO1003399::read_data(void* data, int length, int timeout)
|
|||
|
||||
void GScanO1003399::pop_dev_im()
|
||||
{
|
||||
scanner_write_reg(m_usb, SR_IM_POP, 1); //!< to-list
|
||||
if(im_dev_count()>0)
|
||||
scanner_write_reg(m_usb, SR_IM_POP, 1); //!< to-list
|
||||
}
|
||||
|
||||
int GScanO1003399::front_datasize()
|
||||
|
|
|
@ -27,17 +27,17 @@ static std::map<PaperStatus, unsigned int> SupPaperTyps = {
|
|||
{{TwSS::USLedger,PaperAlign::Rot0},12},
|
||||
{{TwSS::USLegal,PaperAlign::Rot0},13},
|
||||
{{TwSS::None,PaperAlign::Rot0},0},
|
||||
#ifdef G1003399
|
||||
{{TwSS::USLetter,PaperAlign::Rot270},14},
|
||||
{{TwSS::USStatement,PaperAlign::Rot0},17},
|
||||
{{TwSS::MaxSize,PaperAlign::Rot0},19},
|
||||
{{TwSS::Trigeminy,PaperAlign::Rot0},17}
|
||||
#else
|
||||
//#ifdef G1003399
|
||||
// {{TwSS::USLetter,PaperAlign::Rot270},14},
|
||||
// {{TwSS::USStatement,PaperAlign::Rot0},17},
|
||||
// {{TwSS::MaxSize,PaperAlign::Rot0},19},
|
||||
// {{TwSS::Trigeminy,PaperAlign::Rot0},17}
|
||||
//#else
|
||||
{ {TwSS::USLetter,PaperAlign::Rot270},15},
|
||||
{{TwSS::USStatement,PaperAlign::Rot0},16},
|
||||
{{TwSS::MaxSize,PaperAlign::Rot0},16},
|
||||
{{TwSS::Trigeminy,PaperAlign::Rot0},16}
|
||||
#endif
|
||||
//#endif
|
||||
#else
|
||||
{{TwSS::A3,PaperAlign::Rot0},0},
|
||||
{{TwSS::A4,PaperAlign::Rot0},1},
|
||||
|
@ -164,12 +164,33 @@ enum Scanner_Reg_Defs
|
|||
SR_SET_SERIALNUM,
|
||||
SR_CONFIF_IMGPROCPARAM,
|
||||
SC_AUTOCORRECT,
|
||||
SR_KEEP_LAST_IMG,
|
||||
SC_GET_CORRECT_PARAM,
|
||||
SC_SET_CORRECT_PARAM,
|
||||
SR_GET_H_RATIO,
|
||||
SR_SET_H_RATIO,
|
||||
SR_GET_V_RATIO,
|
||||
SR_SET_V_RATIO,
|
||||
SR_GET_SERIAL_LEN,
|
||||
SR_GET_GRAY_SP,
|
||||
SR_GET_COLOR_SP,
|
||||
SR_SET_GRAY_SP,
|
||||
SR_SET_COLOR_SP,
|
||||
SR_SET_SLEEPTIME,
|
||||
SR_GET_SLEEPTIME,
|
||||
SR_GET_SLEEP_STAUTUS,
|
||||
SR_GET_CUO_ERROR = 0x50,
|
||||
SR_GET_DOU_ERROR,
|
||||
SR_GET_JAM_ERROR,
|
||||
SR_GET_SCANN_NUM,
|
||||
SR_CLR_ROLLER_NUM,
|
||||
SR_GET_ROLLER_NUM,
|
||||
SR_UPDATA_START = 0x100,
|
||||
SR_UPDATA_STAUTUS = 0x101,
|
||||
SR_UPDATA_MD5_RELUST = 0x102,
|
||||
SR_UPDATA_RECOVERY = 0x103,
|
||||
SR_UPDATA_REBOOT = 0x104,
|
||||
SR_POWEROFF = 0x105,
|
||||
SR_REBOOT = 0x106
|
||||
};
|
||||
|
||||
enum Scanner_Cmd_Defs
|
||||
|
@ -251,7 +272,8 @@ typedef union HG_ScanConfig
|
|||
unsigned int stable_enbale : 1;
|
||||
unsigned int screw_detect_enable : 1;
|
||||
unsigned int screw_detect_level : 3;//µÚÊ®ËÄλ
|
||||
unsigned int unused_one : 6;
|
||||
unsigned int iscorrect_mod : 1;
|
||||
unsigned int unused_one : 5;
|
||||
unsigned int pc_correct : 1;
|
||||
unsigned int enable_sizecheck : 1;
|
||||
unsigned int enabledsp_cache : 1;
|
||||
|
|
|
@ -98,7 +98,7 @@ static constexpr const Identity srcIdent(
|
|||
#endif
|
||||
|
||||
#ifdef G200
|
||||
#if defined (ISG100) || defined (G1003399)
|
||||
#if defined (ISG100)
|
||||
#ifdef LANXUM
|
||||
"G62S Series",
|
||||
#else // ISG100
|
||||
|
@ -128,7 +128,7 @@ static constexpr const Identity srcIdent(
|
|||
#endif
|
||||
|
||||
#ifdef G200
|
||||
#if defined (ISG100) || defined (G1003399)
|
||||
#if defined (ISG100)
|
||||
#ifdef MAKEHUAGAO
|
||||
"HUAGOSCAN G100 TWAIN"
|
||||
#elif defined LANXUM //!LANXUM
|
||||
|
@ -241,9 +241,15 @@ static map<unsigned int, DeviceEvent::Type> mapDeviceEvent = {
|
|||
{DOG_EAR,(DeviceEvent::Type)(DeviceEventType::Dev_DogEar)}
|
||||
};
|
||||
|
||||
struct Vid_pid
|
||||
{
|
||||
WORD vid;
|
||||
WORD pid;
|
||||
};
|
||||
|
||||
#ifdef LANXUM
|
||||
|
||||
static std::map<WORD, WORD> DeviceID{
|
||||
static std::vector<Vid_pid> DeviceID{
|
||||
{0x31c9,0x8200},
|
||||
#ifdef G200
|
||||
#ifdef ISG100
|
||||
|
@ -260,12 +266,14 @@ static std::map<WORD, WORD> DeviceID{
|
|||
};
|
||||
|
||||
#else
|
||||
static std::map<WORD, WORD> DeviceID{
|
||||
static std::vector<Vid_pid> DeviceID{
|
||||
{0x64B,0x7823},
|
||||
#ifdef G200
|
||||
#ifdef ISG100
|
||||
{0x3072,0x100},
|
||||
{0x3072,0x139},
|
||||
#else
|
||||
{0x3072,0x239},
|
||||
{0x3072,0x200},
|
||||
#endif // ISG100
|
||||
#elif defined G300
|
||||
|
@ -274,6 +282,7 @@ static std::map<WORD, WORD> DeviceID{
|
|||
{0x3072,0x400},
|
||||
#endif // ISG100
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static void DeleteWnd(CDialog* pWnd) {
|
||||
|
@ -346,22 +355,22 @@ void HuagaoDs::showmsg(std::string caption, std::string text, int retcode)
|
|||
{
|
||||
if (scanner.get()) {
|
||||
int num = scanner->get_scannum() * (m_scanparam->is_duplex ? 2 : 1) * (m_scanparam->multi_output_red ? 2 : 1) / (m_scanparam->en_fold ? 2 : 1);
|
||||
#ifdef G1003399
|
||||
//#ifdef G1003399
|
||||
int readnum =scanner->get_scannum()* (m_scanparam->is_duplex ? 2 : 1) / (m_scanparam->en_fold ? 2 : 1);
|
||||
#else
|
||||
int readnum = scanner->get_scannum();
|
||||
#endif // G1003399
|
||||
//#else
|
||||
// int readnum = scanner->get_scannum();
|
||||
//#endif // G1003399
|
||||
|
||||
|
||||
if (!(m_scanparam->is_autodiscradblank_normal || m_scanparam->is_autodiscradblank_vince))
|
||||
{
|
||||
if ((retcode == 64 || retcode == 8 || retcode == 16)) {
|
||||
num = (scanner->get_scannum()-1) * (m_scanparam->is_duplex ? 2 : 1) * (m_scanparam->multi_output_red ? 2 : 1) / (m_scanparam->en_fold ? 2 : 1);
|
||||
#ifdef G1003399
|
||||
//#ifdef G1003399
|
||||
int readnum = (scanner->get_scannum() -1)* (m_scanparam->is_duplex ? 2 : 1) / (m_scanparam->en_fold ? 2 : 1);
|
||||
#else
|
||||
int readnum = scanner->get_scannum()-1;
|
||||
#endif // G1003399
|
||||
//#else
|
||||
// int readnum = scanner->get_scannum()-1;
|
||||
//#endif // G1003399
|
||||
if (((num - scanner->get_imgTransfered()) > 0)||((readnum-scanner->get_imgnReaded())>0)) {
|
||||
text += "进纸" + to_string(scanner->get_scannum()-1) +
|
||||
",扫描" + to_string(scanner->get_imgnReaded()) + ",上传" + to_string(scanner->get_imgTransfered()) +
|
||||
|
@ -793,23 +802,29 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
|
|||
showmsg("警告", msgs[(UsbSupported)202]);
|
||||
return { ReturnCode::Failure, ConditionCode::CapBadOperation };
|
||||
}
|
||||
#ifndef G1003399
|
||||
|
||||
auto usblist = UsbScan_List::find_all_usb();
|
||||
if (!usblist.empty())
|
||||
{
|
||||
for each (auto & usb in usblist)
|
||||
{
|
||||
if (DeviceID.find(usb.vid) != DeviceID.end() && DeviceID.find(usb.vid)->second == usb.pid)
|
||||
for(int x=0;x<DeviceID.size();x++)
|
||||
{
|
||||
vid = usb.vid;
|
||||
pid = usb.pid;
|
||||
if (!scanner.get()) {
|
||||
if (DeviceID[x].vid ==usb.vid && DeviceID[x].pid ==usb.pid)
|
||||
{
|
||||
vid = usb.vid;
|
||||
pid = usb.pid;
|
||||
if (!scanner.get()) {
|
||||
#ifdef G200
|
||||
scanner.reset(new GScanO200());
|
||||
if (pid == 0x139 || pid == 0x239)
|
||||
scanner.reset(new GScanO1003399());
|
||||
else
|
||||
scanner.reset(new GScanO200());
|
||||
#else
|
||||
scanner.reset(new GScanO400());
|
||||
scanner.reset(new GScanO400());
|
||||
#endif // G400
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -828,9 +843,6 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
|
|||
return checkDeviceOnline();
|
||||
}
|
||||
scanner->open(vid, pid);
|
||||
#else
|
||||
scanner.reset(new GScanO1003399());
|
||||
#endif // G1003399
|
||||
|
||||
|
||||
if (!scanner->IsConnected()) {
|
||||
|
@ -2032,7 +2044,14 @@ Result HuagaoDs::userInterfaceEnable(const Identity&, UserInterface& ui) {
|
|||
}
|
||||
#endif // !G200
|
||||
|
||||
|
||||
if (!scanner->IsConnected())
|
||||
scanner->open(vid, pid);
|
||||
if (!scanner->IsConnected())
|
||||
{
|
||||
MessageBox(NULL, L"USB连接异常,请连接USB后重新打开扫描软件", L"提示", MB_OK | MB_SYSTEMMODAL);
|
||||
return seqError();
|
||||
}
|
||||
this_thread::sleep_for(chrono::milliseconds(100)); //扫描前增加延迟 防止usb缓存中的消息未读取清空 误报扫描错误
|
||||
auto ret = startScan();
|
||||
//if (ret.status().condition() == Twpp::CC::NoMedia)
|
||||
// return ret;
|
||||
|
@ -2346,7 +2365,7 @@ Twpp::Result HuagaoDs::showTwainUI(Twpp::UserInterface& ui, bool bUiOnly)
|
|||
m_pendingXfers = 1;
|
||||
m_scanparam.reset(new GScanCap(caps));
|
||||
saveGscanCapSetting();
|
||||
if (scanner->get_ErrorCode() == USB_DISCONNECTED)
|
||||
if (!scanner->IsConnected())
|
||||
{
|
||||
MessageBox(NULL, L"USB连接异常,请连接USB后重新打开扫描软件", L"提示", MB_OK | MB_SYSTEMMODAL);
|
||||
return;
|
||||
|
|
BIN
huagao/stdafx.h
BIN
huagao/stdafx.h
Binary file not shown.
Loading…
Reference in New Issue