添加扫描休眠状态判断,修复部分崩溃问题。

This commit is contained in:
masayume 2021-07-29 19:34:42 +08:00
parent 6a8302a066
commit 72f7212930
5 changed files with 96 additions and 45 deletions

View File

@ -85,6 +85,8 @@ typedef enum tagUsbSupported {
V4L2_AQULRE_ERROR = 79, V4L2_AQULRE_ERROR = 79,
//扫描仪内部图片丢失 //扫描仪内部图片丢失
V4L2_IMAGE_EMPTY = 80, V4L2_IMAGE_EMPTY = 80,
//处于休眠中
SLEEPING = 81,
//USB 未连接 //USB 未连接
USB_DISCONNECTED = 200, USB_DISCONNECTED = 200,
//用户点击停止 //用户点击停止
@ -116,6 +118,7 @@ static map<UsbSupported, string> msgs = {
{UsbSupported::USB_BULK_ERROR,"USB数据读取错误"}, {UsbSupported::USB_BULK_ERROR,"USB数据读取错误"},
{UsbSupported::V4L2_AQULRE_ERROR,"扫描仪取图失败!"}, {UsbSupported::V4L2_AQULRE_ERROR,"扫描仪取图失败!"},
{UsbSupported::V4L2_IMAGE_EMPTY,"扫描仪图像处理异常!"}, {UsbSupported::V4L2_IMAGE_EMPTY,"扫描仪图像处理异常!"},
{UsbSupported::SLEEPING,"设备处于休眠模式,请唤醒休眠后再扫描!"},
}; };
enum tagEventIndex enum tagEventIndex

View File

@ -10,9 +10,9 @@ static std::mutex mx_ctrl;
static int scanner_read_reg(std::shared_ptr<IUsb>& usb, int addr) 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()) { if (usb.get() && usb->is_connected()) {
int val = 0; int val = 0;
std::lock_guard<std::mutex> lck(mx_ctrl);
usb->control_msg(0xc0, USB_REQ_GET_DEV_REGS, addr, 0, 4, &val); usb->control_msg(0xc0, USB_REQ_GET_DEV_REGS, addr, 0, 4, &val);
return 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) 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()) 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); usb->control_msg(0x40, USB_REQ_SET_DEV_REGS, addr, 0, 4, &val);
} }
} }
static void scanner_cmd(std::shared_ptr<IUsb>& usb, int cmd) 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) ,m_imgprocthread(1)
{ {
im_data.reset(new std::vector<char>()); im_data.reset(new std::vector<char>());
open(0, 0); //open(0x3072, 0x139);
if (!m_usbthread.get()) { if (!m_usbthread.get()) {
b_usbthread = true; b_usbthread = true;
m_usbthread.reset(new thread(&GScanO1003399::usb_run, this)); 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()) if (m_usb.get()&&m_usb->is_connected())
return; return;
//auto lsusb = CyUsbList::find_all(); //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()) if (!lsusb.empty())
{ {
m_usb = *lsusb.begin(); m_usb = *lsusb.begin();
@ -323,6 +322,13 @@ void GScanO1003399::Scanner_StartScan(UINT16 count)
keeplastimg = true; keeplastimg = true;
reset(); reset();
devState = DEV_ISRUNNING; 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()) if (scan_mode())
{ {
devState = DEV_WRONG; devState = DEV_WRONG;
@ -497,7 +503,7 @@ int GScanO1003399::scan_mode()
int GScanO1003399::count() 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() void GScanO1003399::abort_dev_tx()
@ -599,7 +605,8 @@ int GScanO1003399::read_data(void* data, int length, int timeout)
void GScanO1003399::pop_dev_im() 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() int GScanO1003399::front_datasize()

View File

@ -27,17 +27,17 @@ static std::map<PaperStatus, unsigned int> SupPaperTyps = {
{{TwSS::USLedger,PaperAlign::Rot0},12}, {{TwSS::USLedger,PaperAlign::Rot0},12},
{{TwSS::USLegal,PaperAlign::Rot0},13}, {{TwSS::USLegal,PaperAlign::Rot0},13},
{{TwSS::None,PaperAlign::Rot0},0}, {{TwSS::None,PaperAlign::Rot0},0},
#ifdef G1003399 //#ifdef G1003399
{{TwSS::USLetter,PaperAlign::Rot270},14}, // {{TwSS::USLetter,PaperAlign::Rot270},14},
{{TwSS::USStatement,PaperAlign::Rot0},17}, // {{TwSS::USStatement,PaperAlign::Rot0},17},
{{TwSS::MaxSize,PaperAlign::Rot0},19}, // {{TwSS::MaxSize,PaperAlign::Rot0},19},
{{TwSS::Trigeminy,PaperAlign::Rot0},17} // {{TwSS::Trigeminy,PaperAlign::Rot0},17}
#else //#else
{ {TwSS::USLetter,PaperAlign::Rot270},15}, { {TwSS::USLetter,PaperAlign::Rot270},15},
{{TwSS::USStatement,PaperAlign::Rot0},16}, {{TwSS::USStatement,PaperAlign::Rot0},16},
{{TwSS::MaxSize,PaperAlign::Rot0},16}, {{TwSS::MaxSize,PaperAlign::Rot0},16},
{{TwSS::Trigeminy,PaperAlign::Rot0},16} {{TwSS::Trigeminy,PaperAlign::Rot0},16}
#endif //#endif
#else #else
{{TwSS::A3,PaperAlign::Rot0},0}, {{TwSS::A3,PaperAlign::Rot0},0},
{{TwSS::A4,PaperAlign::Rot0},1}, {{TwSS::A4,PaperAlign::Rot0},1},
@ -164,12 +164,33 @@ enum Scanner_Reg_Defs
SR_SET_SERIALNUM, SR_SET_SERIALNUM,
SR_CONFIF_IMGPROCPARAM, SR_CONFIF_IMGPROCPARAM,
SC_AUTOCORRECT, 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_START = 0x100,
SR_UPDATA_STAUTUS = 0x101, SR_UPDATA_STAUTUS = 0x101,
SR_UPDATA_MD5_RELUST = 0x102, SR_UPDATA_MD5_RELUST = 0x102,
SR_UPDATA_RECOVERY = 0x103, SR_UPDATA_RECOVERY = 0x103,
SR_UPDATA_REBOOT = 0x104, SR_UPDATA_REBOOT = 0x104,
SR_POWEROFF = 0x105,
SR_REBOOT = 0x106
}; };
enum Scanner_Cmd_Defs enum Scanner_Cmd_Defs
@ -251,7 +272,8 @@ typedef union HG_ScanConfig
unsigned int stable_enbale : 1; unsigned int stable_enbale : 1;
unsigned int screw_detect_enable : 1; unsigned int screw_detect_enable : 1;
unsigned int screw_detect_level : 3;//µÚÊ®ËÄλ 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 pc_correct : 1;
unsigned int enable_sizecheck : 1; unsigned int enable_sizecheck : 1;
unsigned int enabledsp_cache : 1; unsigned int enabledsp_cache : 1;

View File

@ -98,7 +98,7 @@ static constexpr const Identity srcIdent(
#endif #endif
#ifdef G200 #ifdef G200
#if defined (ISG100) || defined (G1003399) #if defined (ISG100)
#ifdef LANXUM #ifdef LANXUM
"G62S Series", "G62S Series",
#else // ISG100 #else // ISG100
@ -128,7 +128,7 @@ static constexpr const Identity srcIdent(
#endif #endif
#ifdef G200 #ifdef G200
#if defined (ISG100) || defined (G1003399) #if defined (ISG100)
#ifdef MAKEHUAGAO #ifdef MAKEHUAGAO
"HUAGOSCAN G100 TWAIN" "HUAGOSCAN G100 TWAIN"
#elif defined LANXUM //!LANXUM #elif defined LANXUM //!LANXUM
@ -241,9 +241,15 @@ static map<unsigned int, DeviceEvent::Type> mapDeviceEvent = {
{DOG_EAR,(DeviceEvent::Type)(DeviceEventType::Dev_DogEar)} {DOG_EAR,(DeviceEvent::Type)(DeviceEventType::Dev_DogEar)}
}; };
struct Vid_pid
{
WORD vid;
WORD pid;
};
#ifdef LANXUM #ifdef LANXUM
static std::map<WORD, WORD> DeviceID{ static std::vector<Vid_pid> DeviceID{
{0x31c9,0x8200}, {0x31c9,0x8200},
#ifdef G200 #ifdef G200
#ifdef ISG100 #ifdef ISG100
@ -260,12 +266,14 @@ static std::map<WORD, WORD> DeviceID{
}; };
#else #else
static std::map<WORD, WORD> DeviceID{ static std::vector<Vid_pid> DeviceID{
{0x64B,0x7823}, {0x64B,0x7823},
#ifdef G200 #ifdef G200
#ifdef ISG100 #ifdef ISG100
{0x3072,0x100}, {0x3072,0x100},
{0x3072,0x139},
#else #else
{0x3072,0x239},
{0x3072,0x200}, {0x3072,0x200},
#endif // ISG100 #endif // ISG100
#elif defined G300 #elif defined G300
@ -274,6 +282,7 @@ static std::map<WORD, WORD> DeviceID{
{0x3072,0x400}, {0x3072,0x400},
#endif // ISG100 #endif // ISG100
}; };
#endif #endif
static void DeleteWnd(CDialog* pWnd) { static void DeleteWnd(CDialog* pWnd) {
@ -346,22 +355,22 @@ void HuagaoDs::showmsg(std::string caption, std::string text, int retcode)
{ {
if (scanner.get()) { 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); 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); int readnum =scanner->get_scannum()* (m_scanparam->is_duplex ? 2 : 1) / (m_scanparam->en_fold ? 2 : 1);
#else //#else
int readnum = scanner->get_scannum(); // int readnum = scanner->get_scannum();
#endif // G1003399 //#endif // G1003399
if (!(m_scanparam->is_autodiscradblank_normal || m_scanparam->is_autodiscradblank_vince)) if (!(m_scanparam->is_autodiscradblank_normal || m_scanparam->is_autodiscradblank_vince))
{ {
if ((retcode == 64 || retcode == 8 || retcode == 16)) { 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); 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); int readnum = (scanner->get_scannum() -1)* (m_scanparam->is_duplex ? 2 : 1) / (m_scanparam->en_fold ? 2 : 1);
#else //#else
int readnum = scanner->get_scannum()-1; // int readnum = scanner->get_scannum()-1;
#endif // G1003399 //#endif // G1003399
if (((num - scanner->get_imgTransfered()) > 0)||((readnum-scanner->get_imgnReaded())>0)) { if (((num - scanner->get_imgTransfered()) > 0)||((readnum-scanner->get_imgnReaded())>0)) {
text += "进纸" + to_string(scanner->get_scannum()-1) + text += "进纸" + to_string(scanner->get_scannum()-1) +
",扫描" + to_string(scanner->get_imgnReaded()) + ",上传" + to_string(scanner->get_imgTransfered()) + ",扫描" + to_string(scanner->get_imgnReaded()) + ",上传" + to_string(scanner->get_imgTransfered()) +
@ -793,23 +802,29 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
showmsg("警告", msgs[(UsbSupported)202]); showmsg("警告", msgs[(UsbSupported)202]);
return { ReturnCode::Failure, ConditionCode::CapBadOperation }; return { ReturnCode::Failure, ConditionCode::CapBadOperation };
} }
#ifndef G1003399
auto usblist = UsbScan_List::find_all_usb(); auto usblist = UsbScan_List::find_all_usb();
if (!usblist.empty()) if (!usblist.empty())
{ {
for each (auto & usb in usblist) 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; if (DeviceID[x].vid ==usb.vid && DeviceID[x].pid ==usb.pid)
pid = usb.pid; {
if (!scanner.get()) { vid = usb.vid;
pid = usb.pid;
if (!scanner.get()) {
#ifdef G200 #ifdef G200
scanner.reset(new GScanO200()); if (pid == 0x139 || pid == 0x239)
scanner.reset(new GScanO1003399());
else
scanner.reset(new GScanO200());
#else #else
scanner.reset(new GScanO400()); scanner.reset(new GScanO400());
#endif // G400 #endif // G400
break; break;
}
} }
} }
} }
@ -828,9 +843,6 @@ Result HuagaoDs::identityOpenDs(const Identity&) {
return checkDeviceOnline(); return checkDeviceOnline();
} }
scanner->open(vid, pid); scanner->open(vid, pid);
#else
scanner.reset(new GScanO1003399());
#endif // G1003399
if (!scanner->IsConnected()) { if (!scanner->IsConnected()) {
@ -2032,7 +2044,14 @@ Result HuagaoDs::userInterfaceEnable(const Identity&, UserInterface& ui) {
} }
#endif // !G200 #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(); auto ret = startScan();
//if (ret.status().condition() == Twpp::CC::NoMedia) //if (ret.status().condition() == Twpp::CC::NoMedia)
// return ret; // return ret;
@ -2346,7 +2365,7 @@ Twpp::Result HuagaoDs::showTwainUI(Twpp::UserInterface& ui, bool bUiOnly)
m_pendingXfers = 1; m_pendingXfers = 1;
m_scanparam.reset(new GScanCap(caps)); m_scanparam.reset(new GScanCap(caps));
saveGscanCapSetting(); saveGscanCapSetting();
if (scanner->get_ErrorCode() == USB_DISCONNECTED) if (!scanner->IsConnected())
{ {
MessageBox(NULL, L"USB连接异常,请连接USB后重新打开扫描软件", L"提示", MB_OK | MB_SYSTEMMODAL); MessageBox(NULL, L"USB连接异常,请连接USB后重新打开扫描软件", L"提示", MB_OK | MB_SYSTEMMODAL);
return; return;

Binary file not shown.