diff --git a/huagao/Device/GScan.h b/huagao/Device/GScan.h index a3ce9455..40c98e28 100644 --- a/huagao/Device/GScan.h +++ b/huagao/Device/GScan.h @@ -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 msgs = { {UsbSupported::USB_BULK_ERROR,"USB数据读取错误!"}, {UsbSupported::V4L2_AQULRE_ERROR,"扫描仪取图失败!"}, {UsbSupported::V4L2_IMAGE_EMPTY,"扫描仪图像处理异常!"}, + {UsbSupported::SLEEPING,"设备处于休眠模式,请唤醒休眠后再扫描!"}, }; enum tagEventIndex diff --git a/huagao/Device/GScanO1003399.cpp b/huagao/Device/GScanO1003399.cpp index 3d49af0d..4309dd3f 100644 --- a/huagao/Device/GScanO1003399.cpp +++ b/huagao/Device/GScanO1003399.cpp @@ -10,9 +10,9 @@ static std::mutex mx_ctrl; static int scanner_read_reg(std::shared_ptr& usb, int addr) { + std::lock_guard lck(mx_ctrl); if (usb.get() && usb->is_connected()) { int val = 0; - std::lock_guard 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& usb, int addr) static void scanner_write_reg(std::shared_ptr& usb, int addr, int val) { + std::lock_guard lck(mx_ctrl); if (usb.get() && usb->is_connected()) - { - std::lock_guard lck(mx_ctrl); + { usb->control_msg(0x40, USB_REQ_SET_DEV_REGS, addr, 0, 4, &val); } } static void scanner_cmd(std::shared_ptr& 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()); - 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; @@ -448,7 +454,7 @@ void GScanO1003399::usb_run() if (info.Code == 0x10 || info.Code == 0x20 || info.Code == 0x40) { while (scanner_read_reg(m_usb, SR_STATUS) & 0x1) - this_thread::sleep_for(chrono::microseconds(10)); + this_thread::sleep_for(chrono::microseconds(10)); if (m_param.is_duplex) pop_dev_im(); pop_dev_im(); @@ -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() diff --git a/huagao/Device/IConfig.h b/huagao/Device/IConfig.h index 25962d0c..47afcd3b 100644 --- a/huagao/Device/IConfig.h +++ b/huagao/Device/IConfig.h @@ -27,17 +27,17 @@ static std::map 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; diff --git a/huagao/huagaods.cpp b/huagao/huagaods.cpp index c6a0108b..9d9588b7 100644 --- a/huagao/huagaods.cpp +++ b/huagao/huagaods.cpp @@ -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 mapDeviceEvent = { {DOG_EAR,(DeviceEvent::Type)(DeviceEventType::Dev_DogEar)} }; +struct Vid_pid +{ + WORD vid; + WORD pid; +}; + #ifdef LANXUM -static std::map DeviceID{ +static std::vector DeviceID{ {0x31c9,0x8200}, #ifdef G200 #ifdef ISG100 @@ -260,12 +266,14 @@ static std::map DeviceID{ }; #else -static std::map DeviceID{ +static std::vector 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 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,25 +802,31 @@ 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;xopen(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; diff --git a/huagao/stdafx.h b/huagao/stdafx.h index 90a6d6c1..e2d49214 100644 Binary files a/huagao/stdafx.h and b/huagao/stdafx.h differ