diff --git a/CTWAINDS_FreeImage.cpp b/CTWAINDS_FreeImage.cpp index f2b112a..9e46a19 100644 --- a/CTWAINDS_FreeImage.cpp +++ b/CTWAINDS_FreeImage.cpp @@ -1267,12 +1267,11 @@ TW_INT16 CTWAINDS_FreeImage::closeDS() if (dsState_Open != m_CurrentState) { setConditionCode(TWCC_SEQERROR); - //FileTools::write_log("1.txt", "~CTWAINDS_FreeImage closeDS dsState_Open != m_CurrentState"); return TWRC_FAILURE; } + memset(&m_App, 0, sizeof(m_App)); - //FileTools::write_log("D:/1.txt"," Close DS "); XdPrint(" CloseDS !\n"); return TWRC_SUCCESS; } @@ -1654,7 +1653,6 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers) if (rs) { m_Xfers.Count = 0; - XdPrint("m_Scanner.isImageQueueEmpty() \n"); } //if (m_bCanceled) @@ -1690,7 +1688,6 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers) if (_pXfers == 0) { - //FileTools::write_log("D:/1.txt"," (_pXfers: m_Xfers.Count==0"); setConditionCode(TWCC_BADVALUE); // Did everyting but return the currect count. return TWRC_CHECKSTATUS; @@ -1702,11 +1699,7 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers) } else { - if (bIndicators) - { - //FileTools::write_log("D:/1.txt"," (bIndicators: HIDDEN"); - m_pGUI->UpdateProgress(false, '0', 0, "0"); - } + m_pGUI->DestroyIndicators(); } return twrc; } @@ -1773,7 +1766,6 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig) CTWAINContainerFix32 *pfCap = 0; CTWAINContainerFix32Range *pfRCap = 0; DWORD index = -1; - //FileTools::write_log("D:/1.txt",) if (0 == (pnCap = dynamic_cast(findCapability(ICAP_PIXELTYPE)))) { cerr << "Could not get ICAP_PIXELTYPE" << endl; @@ -2792,16 +2784,14 @@ bool CTWAINDS_FreeImage::StartScanning(bool showUI) setConditionCode(TWCC_BADVALUE); return false; } - if (bIndicators) - { - m_pGUI->UpdateProgress(true, '0', 0, "0"); - } + + m_pGUI->ShowIndicators(); bool ret = m_Scanner.acquireImage(); if (bIndicators) { if (!ret) { - m_pGUI->UpdateProgress(false, '0', 0, "0"); + m_pGUI->DestroyIndicators(); } } return ret; diff --git a/GDevice.cpp b/GDevice.cpp new file mode 100644 index 0000000..b4d88d5 --- /dev/null +++ b/GDevice.cpp @@ -0,0 +1,505 @@ +#include "stdafx.h" +#include "GDevice.h" +#include "IUsb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "StopWatch.h" +#include "device_common.h" +#ifndef WIN32 + #include +#endif + + +#define DSP_CODE_ADDR 0 +#define USER_ADDR 0x4000 + +using namespace std; + +GDevice::GDevice(std::shared_ptr usb) +{ + m_bScan = false; + m_bListen = false; + m_usb = usb; + event_call = NULL; + image_call = NULL; + m_imagecall_userdata = NULL; + m_eventcall_userdata = NULL; + m_threadInt = NULL; + m_threadrecv = NULL; +} + +GDevice::~GDevice() +{ + close(); +} + +bool GDevice::open() +{ + if (is_open()) + return true; + + if (m_usb && m_usb->open()) { + m_usb->set_timeout(1000); + init_cam(); + m_bListen = true; + m_bScan = true; + + if (m_threadInt) { + m_bListen = false; + m_threadInt->join(); + } + + if (m_threadrecv) { + m_bScan = false; + m_threadrecv->join(); + } + m_bListen = true; + m_bScan = true; + m_threadInt = std::shared_ptr(new std::thread(&GDevice::Int_main, this)); + m_threadrecv = std::shared_ptr(new std::thread(&GDevice::recv_main, this)); + return true; + } + return false; +} + +void GDevice::close() +{ + if (m_usb.get() && m_usb->is_open()) { + m_usb->set_timeout(100); + stop(); + + if (m_threadInt && m_threadInt->joinable()) { + m_bListen = false; + this_thread::sleep_for(std::chrono::milliseconds(100)); + m_threadInt->join(); + m_threadInt = NULL; + } + + if (m_threadrecv && m_threadrecv->joinable()) { + m_bScan = false; + image_indexs.ShutDown(); + m_threadrecv->join(); + m_threadrecv = NULL; + } + m_usb->close(); + } +} + +bool GDevice::is_open() +{ + if (m_usb.get()) + return m_usb->is_open(); + return false; +} + +bool GDevice::start(image_callback callfunc, void* userdata) +{ + if (is_run()) + return false; + + image_call = callfunc; + m_imagecall_userdata = userdata; + MotorSetting ms; + ms.value = read_reg(MOTOR_BOARD, 0x00); + ms.scan_enable = 0; + write_reg(MOTOR_BOARD, 0x00, ms.value); + ms.scan_enable = 1; + write_reg(MOTOR_BOARD, 0x00, ms.value); + return true; +} + +void GDevice::set_event_call(event_callback callfunc, void* userdata) +{ + m_eventcall_userdata = userdata; + event_call = callfunc; +} + +void GDevice::stop() +{ + + set_option(Cam_Options::scanner_stop_motor, 0); +} + +int GDevice::is_run() +{ + return image_indexs.Size() != 0; +} + +void GDevice::reset() +{ + +} + +static std::string read_all_from(std::string path) +{ + int t; + FILE* file = fopen(path.c_str(), "rb"); + fseek(file, 0, SEEK_END); + t = ftell(file); + std::string buf(t, 0); + fseek(file, 0, SEEK_SET); + fread((void*)buf.c_str(), t, 1, file); + fclose(file); + return buf; +} + +void GDevice::write_dsp_fw(std::string path) +{ + std::string buf = read_all_from(path); + write_flash(DSP_CODE_ADDR, (void*)buf.c_str(), buf.size()); +} + +void GDevice::write_pid(unsigned short pid) +{ + write_flash(PID_ADDR, &pid, sizeof(pid)); +} + +unsigned short GDevice::read_pid() +{ + unsigned short pid; + read_flash(PID_ADDR, &pid, sizeof(pid)); + return pid; +} + + +void GDevice::write_devname(std::string name) +{ + if (name.size() > 64) + return; + + write_flash(DEVNAME_ADDR, (void*)name.c_str(), name.size()); +} + +std::string GDevice::read_devname() +{ + char devname[65] = {0}; + read_flash(DEVNAME_ADDR, devname, sizeof(devname) - 1); + return devname; +} + +bool GDevice::write_flash(unsigned int addr, void* data, int size) +{ + unsigned int writeAddr = addr; + int writed = 0; + int writing = 0; + while (writed < size) { + writing = min(crtlBufferSize, size - writed); + writeAddr = addr + writed; + { + std::lock_guard lck(m_mtxCtrl); + m_usb->control_msg(to_device, flash_access, ((Reg2Short*)&writeAddr)->short2, ((Reg2Short*)&writeAddr)->short1, writing, (unsigned char*)data + writed); + } + writed += writing; + } + return true; +} + +bool GDevice::read_flash(unsigned int addr, void* data, int size) +{ + unsigned int readAddr = addr; + int readed = 0; + int reading = 0; + while (readed < size) { + reading = min(crtlBufferSize, size - readed); + readAddr = addr + readed; + { + std::lock_guard lck(m_mtxCtrl); + m_usb->control_msg(from_device, flash_access, ((Reg2Short*)&readAddr)->short2, ((Reg2Short*)&readAddr)->short1, reading, (unsigned char*)data + readed); + } + readed += reading; + } + return true; +} + +const int int_buffer_size = 1024; +int index_count = 0; +#include +static void write_log(std::string fullname, std::string log) +{ + std::string savepath; + savepath = fullname; + std::ofstream ofs(savepath, std::ios::app); + + SYSTEMTIME sys; + GetLocalTime(&sys); + ofs << sys.wYear << "/" << sys.wMonth << "/" << sys.wDay << " " << sys.wHour << ":" << sys.wMinute << ":" << sys.wSecond << ":" << sys.wMilliseconds << " " << log << std::endl; +} +int image_index_c = 0; +void GDevice::recv_main() +{ + const double timeout_ratio = (1000.0 / (15.0 * 1024 * 1024)); //!< s / Mbyte + int image_index = 0; + int buffer_size = 0; + int b_buffer_size = 0; + int f_buffer_size = 0; + unsigned char* bbuf = 0; + unsigned char* fbuf = 0; + unsigned char* buf; + int buffer_reading = 0; + int buffer_readed = 0; + const int read_timeout = 5000; + std::vector image_data; + StopWatch sw; + while (m_bScan) { + image_index = image_indexs.Take(); + if (!image_indexs.IsShutDown() && image_index >= 0) + { + buffer_reading = 0; + buffer_readed = 0; + buffer_size = frame_size(image_index); + image_data.resize(buffer_size * 2 + int_buffer_size); + buf = image_data.data() + int_buffer_size; + + sw.reset(); + while (sw.elapsed_ms() < read_timeout) { + while (DataOn() && sw.elapsed_ms() < read_timeout); + read_frame(image_index, buffer_readed); + buffer_reading = max(0, buffer_size - buffer_readed); + buffer_reading = read_data(buf + buffer_readed, buffer_reading, (int)(buffer_reading * timeout_ratio)); + if (buffer_reading > 0) + buffer_readed += buffer_reading; + + if (buffer_readed >= buffer_size) { + write_log("d:\\1.txt", std::to_string(image_index_c) + " time1 = " + std::to_string(sw.elapsed_ms())); + break; + } + } + + image_index_c++; + if (buffer_readed != buffer_size) + { + write_log("d:\\1.txt", std::to_string(image_index_c) + " error readed:" + std::to_string(buffer_readed) + " per read:" + std::to_string(buffer_size) + " time = " + std::to_string(sw.elapsed_ms())); + } + else { + write_log("d:\\1.txt", std::to_string(image_index_c) + " get" + " time = " + std::to_string(sw.elapsed_ms())); + } + + b_buffer_size = 0; + f_buffer_size = 0; + bbuf = buf - int_buffer_size; + fbuf = buf + buffer_size; + for (int i = 0; i < (buffer_size / int_buffer_size); i++) + { + if (buf[(i + 1) * int_buffer_size - 1] == 0) + { + memcpy(bbuf + b_buffer_size, buf + i * int_buffer_size, int_buffer_size - 1); + b_buffer_size += (int_buffer_size - 1); + } + else if (buf[(i + 1) * int_buffer_size - 1] == 255) + { + memcpy(fbuf + f_buffer_size, buf + i * int_buffer_size, int_buffer_size - 1); + f_buffer_size += (int_buffer_size - 1); + } + } + + FILE* pfile = fopen((("d:\\") + std::to_string(image_index_c)+"b.jpg").c_str(), "wb"); + fwrite(bbuf, 1, b_buffer_size, pfile); + fclose(pfile); + pfile = fopen((("d:\\") + std::to_string(image_index_c) + "f.jpg").c_str(), "wb"); + fwrite(fbuf, 1, f_buffer_size, pfile); + fclose(pfile); + } + } +} + +void GDevice::Int_main() +{ + unsigned int int_buffer[4]; + int size = 0; + while (m_bListen) { + size = m_usb->read_int(int_buffer, sizeof(int_buffer)); + if (size >= 16) + { + if (int_buffer[2] != 0) + { + image_indexs.Put(int_buffer[1]); + } + if (((MotorStatus*)int_buffer)->motor_status == 1) + { + if (event_call) { + event_call(0, m_eventcall_userdata); + } + } + } + } +} + +void GDevice::init_cam() +{ +} + +int GDevice::read_data(void* data, int length, int timeout) +{ + int readed = 0; + int reading = 0; + StopWatch sw; + while (readed < length && sw.elapsed_ms() < timeout) { + reading = max(0, min(length - readed, buffer_size)); + reading = m_usb->read_bulk((unsigned char*)data + readed, reading); + if (reading > 0) { + readed += reading; + } + } + return readed; +} + +void GDevice::read_frame(int index, int offset) +{ + write_reg(3, index, offset); +} + +int GDevice::frame_size(int index) +{ + return read_reg(3, index); +} + +int GDevice::read_reg(int type, int addr) +{ + int value; + std::lock_guard lck(m_mtxCtrl); + m_usb->control_msg(from_device, regs_access, type, addr, sizeof(value), &value); + return value; +} + + +void GDevice::write_reg(int type, int addr, int value) +{ + std::lock_guard lck(m_mtxCtrl); + m_usb->control_msg(to_device, regs_access, type, addr, sizeof(value), &value); +} + +void GDevice::set_option(Cam_Options option, unsigned int value) +{ + unsigned int val = 0; + switch (option) + { + case scanner_config: + write_reg(USERDEFINE, ModeParam, value); + break; + case scanner_scan_skrew: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->skew_enable = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + case scanner_stample_enable: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->staple_enable = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + case scanner_doublePape_enable: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->double_paper = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + case scanner_stop_motor: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->scan_enable = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + case scanner_error_clean: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->error_clean = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + case scanner_Init_Status: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->status_init = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + case scanner_IIC_Config: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->iic_config = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + case scanner_Speed_Config: + val = read_reg(MOTOR_BOARD, 0x00); + ((MotorSetting*)& val)->speed_set_enable = value; + write_reg(MOTOR_BOARD, 0x00, val); + break; + default: + break; + } +} + +int GDevice::get_option(Cam_Options option) +{ + int value = 0; + switch (option) + { + case scanner_cover_status: + value = read_reg(1, 0x01); + value = ((MotorStatus*)& value)->open_machine; + break; + case scanner_pick_paper_stauts: + value = read_reg(1, 0x01); + value = ((MotorStatus*)& value)->pick_failed; + break; + case scanner_jam_stauts: + value = read_reg(1, 0x01); + value = ((MotorStatus*)& value)->stop_jam; + break; + case scanner_paper_count: + value = read_reg(1, 0x02); + value = ((MotorMode*)& value)->scan_num; + break; + case scanner_double_paper: + value = read_reg(1, 0x01); + value= ((MotorStatus*)& value)->double_paper; + break; + case scanner_staple_state: + value = read_reg(1, 0x01); + value = ((MotorStatus*)& value)->staple; + break; + case scanner_skrew_state: + value = read_reg(1, 0x01); + value = ((MotorStatus*)& value)->papertilted; + break; + case scanner_paper_have: + value = read_reg(MOTOR_BOARD, 0x02); + value = ((Motor_Mode*)& value)->feeding_paper_ready; + break; + default: + break; + } + return value; +} + +std::vector GDevice::support_options() +{ + std::set options; + options.insert(Cam_Options::scanner_exposure_blue); + options.insert(Cam_Options::scanner_exposure_gray); + options.insert(Cam_Options::scanner_exposure_red); + + return std::vector(options.begin(), options.end()); +} + +void GDevice::pick_paper(void) +{ + MotorSetting ms; + ms.value = read_reg(MOTOR_BOARD, 0x00); + ms.pick_paper = 0; + write_reg(MOTOR_BOARD, 0x00, ms.value); + ms.pick_paper = 1; + write_reg(MOTOR_BOARD, 0x00, ms.value); +} + +void GDevice::trigger_scan(void) +{ + ScanTriger st; + st.value = 0; + write_reg(MAIN_BOARD, 0x02, st.value); + st.triger = 1; + write_reg(MAIN_BOARD, 0x02, st.value); +} + +bool GDevice::DataOn() +{ + return read_reg(0x02, 0x03); +} diff --git a/GDevice.h b/GDevice.h new file mode 100644 index 0000000..d3b8c28 --- /dev/null +++ b/GDevice.h @@ -0,0 +1,87 @@ +#pragma once +#include "IGDevice.h" +#include +#include +#include +#include "BlockingQueue.h" +#include + +class IUsb; +class GDevice : public IGDevice +{ +public: + GDevice(std::shared_ptr usb); + virtual ~GDevice(); + // 通过 IGDevice 继承 + virtual bool open() override; + virtual void close() override; + virtual bool is_open() override; + bool start(image_callback callfunc, void* userdata); + void set_event_call(event_callback event_callfunc, void* userdata); + virtual void stop() override; + virtual int is_run() override; + virtual void reset() override; + + void write_dsp_fw(std::string path); + + void write_devname(std::string name); + std::string read_devname(); + + void write_reg(int type, int addr, int value); + int read_reg(int type, int addr); + + bool write_flash(unsigned int addr, void* data, int size); + bool read_flash(unsigned int addr, void* data, int size); + + void trigger_scan(void); + + void write_pid(unsigned short pid); + unsigned short read_pid(); + +private: + void recv_main(); + void Int_main(); + + void init_cam(); + + int read_data(void* data, int lenght, int timeout); + void read_frame(int index, int offset); + int frame_size(int index); + + + + + void pick_paper(void); + + bool DataOn(); + + std::shared_ptr m_usb; + const int buffer_size = 1204 * 1024; + const int crtlBufferSize = 512; + volatile bool m_bScan; + volatile bool m_bListen; + + std::shared_ptr m_threadInt; + std::shared_ptr m_threadrecv; + std::mutex m_mtxInt; + std::mutex m_mtxCtrl; + image_callback image_call; + event_callback event_call; + const int to_device = 0x40; + const int from_device = 0xc0; + const int regs_access = 0x0c; + const int flash_access = 0x04; + + const int regs_req = 0x0c; + + BlockingQueue image_indexs; + + void* m_imagecall_userdata; + void* m_eventcall_userdata; + + + // 通过 IGDevice 继承 + virtual void set_option(Cam_Options option,unsigned int value) override; + virtual int get_option(Cam_Options option) override; + virtual std::vector support_options() override; +}; diff --git a/GDeviceLists.cpp b/GDeviceLists.cpp new file mode 100644 index 0000000..4e07457 --- /dev/null +++ b/GDeviceLists.cpp @@ -0,0 +1,19 @@ +#include "stdafx.h" +#include "GDeviceLists.h" +#include "UsbScanEx.h" +#include "GDevice.h" + + + std::list> HGDeviceLists::FindAll() + { + std::list> cameraLists; + + // std::list> usbs = CyUsbList::find_vid_pid(0x04b4, 0x1004); + std::list> usbs = UsbScan_List::find_vid_pid(0x064b, 0x7823); + + + for (auto i = usbs.begin(); i != usbs.end(); i++) + cameraLists.push_back(std::shared_ptr(new GDevice(*i))); + + return cameraLists; + } diff --git a/GDeviceLists.h b/GDeviceLists.h new file mode 100644 index 0000000..8d19ad9 --- /dev/null +++ b/GDeviceLists.h @@ -0,0 +1,12 @@ +#pragma once +#include +#include + + +class IGDevice; + +class HGDeviceLists +{ +public: + static std::list> FindAll(); +}; diff --git a/IGDevice.h b/IGDevice.h new file mode 100644 index 0000000..2278cf0 --- /dev/null +++ b/IGDevice.h @@ -0,0 +1,54 @@ +#pragma once +#include + + +typedef void(*image_callback)(void*, int, int, int, void*); +typedef void(*event_callback)(int, void*); + +enum Cam_Options { + scanner_config, //!< color, gray + scanner_exposure_gray, + scanner_exposure_green, + scanner_exposure_blue, + scanner_exposure_red, + scanner_status, + scanner_ad_gain, + scanner_ad_offset, + scanner_cover_status, //是否关闭盖子 + scanner_pick_paper_stauts, //是否搓纸失败 + scanner_jam_stauts, //是否卡纸 + scanner_paper_count, //扫描计数值 + scanner_trigger_scan, //触发扫描 + scanner_staple_state, //有无订书钉 + scanner_skrew_state, //歪斜状态 + scanner_paper_have, //有无纸张 + scanner_double_paper, //双张检测 + scanner_scan_triger,//扫描状态,1停止扫描,0正在扫描 + scanner_scan_skrew, //歪斜检测开关,1开,0关 + scanner_stample_enable, //订书钉检测使能,0:default;1:订书钉检测使能 + scanner_doublePape_enable,//双张检测使能 + scanner_stop_motor, //停止电机 + scanner_error_clean ,//异常清除 + scanner_Init_Status, //状态初始化使能 + scanner_IIC_Config, //IIC配置使能 + scanner_Speed_Config //速度配置使能 + +}; + +class IGDevice +{ +public: + virtual ~IGDevice() {} + virtual bool open() = 0; + virtual void close() = 0; + virtual bool is_open() = 0; + virtual bool start(image_callback imagecall= NULL, void* userdata = NULL) = 0; + virtual void stop() = 0; + virtual int is_run() = 0; + virtual void reset() = 0; + virtual void set_event_call(event_callback event_callfunc, void* userdata) = 0; + virtual void set_option(Cam_Options option, unsigned int value) = 0; + virtual int get_option(Cam_Options option) = 0; + virtual std::vector support_options() = 0; +}; + diff --git a/IUsb.h b/IUsb.h new file mode 100644 index 0000000..a7c3265 --- /dev/null +++ b/IUsb.h @@ -0,0 +1,15 @@ +#pragma once +class IUsb +{ +public: + virtual ~IUsb() {} + virtual bool open() = 0; + virtual bool close() = 0; + virtual bool is_open() = 0; + virtual bool is_connected() = 0; + virtual void set_timeout(int timeout) = 0; + virtual int read_bulk(void* data, int len) = 0; + virtual int write_bulk(void* data, int len) = 0; + virtual int read_int(void* data, int len) = 0; + virtual int control_msg(int rtype, int req, int value, int index, int len, void* data) = 0; +}; \ No newline at end of file diff --git a/IndicatorDlg.cpp b/IndicatorDlg.cpp index b2b66e3..9854f24 100644 Binary files a/IndicatorDlg.cpp and b/IndicatorDlg.cpp differ diff --git a/MFC_UI.cpp b/MFC_UI.cpp index e21ce9d..96814a9 100644 --- a/MFC_UI.cpp +++ b/MFC_UI.cpp @@ -7,13 +7,21 @@ extern ChugaotwaindsApp theApp; +void DeleteWnd(CDialog* pWnd) +{ + if (pWnd && pWnd->GetSafeHwnd()) + { + pWnd->DestroyWindow(); + delete pWnd; + } +} + MFC_UI::MFC_UI(CTWAINDS_FreeImage *pDS) : CTWAIN_UI(pDS) + , m_pChildWnd(0, DeleteWnd) + , m_pDlg(0, DeleteWnd) + , m_pIndicator(0, DeleteWnd) { - m_pDlg = NULL; - m_pChildWnd = NULL; - indicator = NULL; - indicatorCreated = false; } @@ -42,123 +50,47 @@ TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndic if (Data.hParent) { - if (m_pChildWnd == NULL) - { - CDialog* dlg = new CDialog(); - dlg->Create(IDD_DIALOGBACK); - m_pChildWnd = dlg; - theApp.m_pMainWnd = m_pChildWnd; - - //long ll = GetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE); - //SetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE, WS_CHILD | ll); - SetParent(m_pChildWnd->GetSafeHwnd(), (HWND)Data.hParent); - //dlg->ShowWindow(SW_SHOWNORMAL); - } + m_pChildWnd = std::unique_ptr(new CDialog(), DeleteWnd); + m_pChildWnd->Create(IDD_DIALOGBACK, CWnd::FromHandle((HWND)Data.hParent)); + long ll = GetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE); + SetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE, WS_CHILD | ll); + SetParent(m_pChildWnd->GetSafeHwnd(), (HWND)Data.hParent); } if (Data.ShowUI) { - if (m_pDlg == NULL) - { - m_pDlg = new TwainUIDlg(this, m_pChildWnd); - m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd); - } - if (!bSetup) - { - m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("扫描")); - } - else - { - m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("确定")); - } + m_pDlg.reset(new TwainUIDlg(this, m_pChildWnd.get())); + m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd.get()); + m_pDlg->SetDlgItemText(IDC_CONFIRM,bSetup ? _T("确定") : _T("扫描")); - - if (m_pDlg) - { + if (m_pDlg) { m_pDlg->ShowWindow(SW_SHOWNORMAL); - SetWindowPos(m_pDlg->m_hWnd, HWND_TOPMOST, 500, 500, 0, 0, SWP_NOSIZE | SWP_NOMOVE); } - else - { + else { ret = TWRC_FAILURE; } } - - if (bIndicators) - { - if (indicator == NULL) - { - indicator = new IndicatorDlg(this, Data.ShowUI ? m_pDlg : m_pChildWnd); - } - showUI = Data.ShowUI; - } - return ret; } void MFC_UI::DestroyTWAINGUI() { + m_pIndicator.reset(); + m_pDlg.reset(); + m_pChildWnd.reset(); + CTWAIN_UI::DestroyTWAINGUI(); - if (indicator != NULL) - { - indicator->DestroyWindow(); - delete indicator; - indicator = NULL; - indicatorCreated = false; - } - - if (m_pDlg != NULL) - { - m_pDlg->DestroyWindow(); - delete m_pDlg; - m_pDlg = NULL; - } - - if (m_pChildWnd != NULL) - { - m_pChildWnd->DestroyWindow(); - delete m_pChildWnd; - m_pChildWnd = NULL; - } } void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle) { - if (indicator == NULL) - { - indicator = new IndicatorDlg(this, NULL); - } - - if (!indicatorCreated) - { - indicator->Create(IDD_DIALOG_INDICATOR, m_pChildWnd);//m_pChildWnd - indicatorCreated = true; - } - - if (bShow) - { - indicator->ShowWindow(SW_SHOWNORMAL); - } - else - { - indicator->DestroyWindow(); - delete indicator; - indicator = NULL; - indicatorCreated = false; - } - //indicator->ShowWindow(bShow?SW_SHOWNORMAL:SW_HIDE); - if (m_pDlg) - { - m_pDlg->EnableWindow(bShow ? FALSE : TRUE); - } } unsigned int MFC_UI::MyMessageBox(string strMessage, string strTitle, unsigned int unIconID) { - //QMessageBox msgBox(QMessageBox::NoIcon, strTitle.c_str(), strMessage.c_str()); if (m_pChildWnd != NULL) { return ::MessageBox(m_pChildWnd->m_hWnd, strMessage.c_str(), strTitle.c_str(), unIconID); @@ -173,9 +105,22 @@ bool MFC_UI::processEvent(pTW_EVENT _pEvent) if (IsDialogMessage(m_pDlg->m_hWnd, (LPMSG)(((pTW_EVENT)_pEvent)->pEvent))) { m_pDlg->SendMessage(_pEvent->TWMessage); - //XdPrint("_pEvent->TWMessage %d\n",_pEvent->TWMessage); return TRUE; } } return FALSE; } + +void MFC_UI::ShowIndicators() +{ + if (m_bIndicators) { + m_pIndicator.reset(new IndicatorDlg(this)); + m_pIndicator->Create(IDD_DIALOG_INDICATOR,m_pDlg ? m_pDlg.get() : m_pChildWnd.get()); + m_pIndicator->ShowWindow(SW_SHOWNORMAL); + } +} + +void MFC_UI::DestroyIndicators() +{ + m_pIndicator.reset(); +} diff --git a/MFC_UI.h b/MFC_UI.h index 4ee2d87..b613fb7 100644 --- a/MFC_UI.h +++ b/MFC_UI.h @@ -1,6 +1,7 @@ #pragma once #include "CTWAINDS_FreeImage.h" #include "TWAIN_UI.h" +#include class TwainUIDlg; class CWnd; class IndicatorDlg; @@ -29,11 +30,13 @@ public: bool processEvent(pTW_EVENT _pEvent); private: - TwainUIDlg* m_pDlg; - CWnd* m_pChildWnd; - IndicatorDlg* indicator; - bool indicatorCreated; - bool showUI; + std::unique_ptr m_pChildWnd; + std::unique_ptr m_pDlg; + std::unique_ptr m_pIndicator; ChugaotwaindsApp* m_app; + + // 通过 CTWAIN_UI 继承 + virtual void ShowIndicators() override; + virtual void DestroyIndicators() override; }; diff --git a/StopWatch.h b/StopWatch.h new file mode 100644 index 0000000..afa4ee9 --- /dev/null +++ b/StopWatch.h @@ -0,0 +1,34 @@ +#pragma once +#include + +class StopWatch +{ +public: + StopWatch() { + _start = std::chrono::steady_clock::now(); + } + + void reset() { + _start = std::chrono::steady_clock::now(); + } + + double elapsed_s() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_ms() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_us() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + + double elapsed_ns() { + return std::chrono::duration(std::chrono::steady_clock::now() - _start).count(); + } + +private: + std::chrono::steady_clock::time_point _start; +}; + diff --git a/TWAIN_UI.cpp b/TWAIN_UI.cpp index 9e89995..5f237e7 100644 --- a/TWAIN_UI.cpp +++ b/TWAIN_UI.cpp @@ -194,6 +194,7 @@ void CTWAIN_UI::DestroyTWAINGUI() { m_bScanning=false; memset(&m_EnableDSdata,0,sizeof(TW_USERINTERFACE)); + } void CTWAIN_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle) { diff --git a/TWAIN_UI.h b/TWAIN_UI.h index 06e5647..d5748fb 100644 --- a/TWAIN_UI.h +++ b/TWAIN_UI.h @@ -73,6 +73,8 @@ public: * Close the user interface for TWAIN */ virtual void DestroyTWAINGUI(); + virtual void ShowIndicators() = 0; + virtual void DestroyIndicators() = 0; virtual void UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle); virtual void Scan(); virtual void Cancel(); diff --git a/TwainUIDlg.cpp b/TwainUIDlg.cpp index 7d5e3b4..8e0a387 100644 Binary files a/TwainUIDlg.cpp and b/TwainUIDlg.cpp differ diff --git a/UsbScanEx.cpp b/UsbScanEx.cpp new file mode 100644 index 0000000..788b210 --- /dev/null +++ b/UsbScanEx.cpp @@ -0,0 +1,335 @@ +#include "stdafx.h" +#include "UsbScanEx.h" +#include +#include + +UsbScanEx::UsbScanEx(int index) +{ + m_h_dev = INVALID_HANDLE_VALUE; + timeout = 100; + m_h_index = index; + memset(ov, 0, sizeof(ov)); + CTRL_IN_OUT = 3; + for (int i = 0; i < (sizeof(ov) / sizeof(ov[0])); i++) + ov[i].hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); +} + +UsbScanEx::~UsbScanEx() +{ + if (m_h_dev != INVALID_HANDLE_VALUE) + close(); + + for (int i = 0; i < (sizeof(ov) / sizeof(ov[0])); i++) + CloseHandle(ov[i].hEvent); +} + +bool UsbScanEx::open() +{ + BOOL b_ret = FALSE; + TCHAR szDevPath[MAX_PATH] = { 0 }; + DWORD cbRet = 0; + + USBSCAN_TIMEOUT ut; + ut.TimeoutEvent = 1; + ut.TimeoutRead = 1; + ut.TimeoutWrite = 1; + + _stprintf(szDevPath, TEXT("\\\\.\\Usbscan%d"), m_h_index); + m_h_dev = CreateFile(szDevPath, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + if (m_h_dev != INVALID_HANDLE_VALUE) { + m_b_is_connected = TRUE; + b_ret = DeviceIoControl(m_h_dev, (DWORD)IOCTL_GET_PIPE_CONFIGURATION, + NULL, 0, &m_usbscan_config, sizeof(USBSCAN_PIPE_CONFIGURATION), + &cbRet, NULL); + if (b_ret && m_usbscan_config.NumberOfPipes > 0) { + for (int by_i = 0x00; (ULONG)by_i < m_usbscan_config.NumberOfPipes; by_i++) { + TCHAR szPipePath[MAX_PATH] = { 0 }; + _stprintf(szPipePath, TEXT("\\\\.\\Usbscan%d\\%d"), m_h_index, by_i); + m_usb_pipes[by_i].pipe_info = m_usbscan_config.PipeInfo[by_i]; + m_usb_pipes[by_i].h_pipe = CreateFile(szPipePath, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + if (m_usbscan_config.PipeInfo[by_i].PipeType == USBSCAN_PIPE_INTERRUPT) { + INT_IN = by_i; + } + else { + if (m_usbscan_config.PipeInfo[by_i].EndpointAddress & 0x80) { + BULK_IN = by_i; + } + else { + BULK_OUT = by_i; + } + } + b_ret = DeviceIoControl(m_usb_pipes[by_i].h_pipe, IOCTL_SET_TIMEOUT, &ut, sizeof(ut), NULL, 0, &cbRet, NULL); + } + } + } + else { + CloseHandle(m_h_dev); + m_h_dev = INVALID_HANDLE_VALUE; + } + return m_h_dev; +} + +bool UsbScanEx::close() +{ + BOOL b_ret = FALSE; + BYTE by_i = 0x00; + + if (m_h_dev != INVALID_HANDLE_VALUE) { + BOOL bState = FALSE; + DWORD cbRet = 0; + OVERLAPPED overlapped; + PIPE_TYPE pipeType = ALL_PIPE; + + memset(&overlapped, 0, sizeof(OVERLAPPED)); + overlapped.hEvent = + CreateEvent(NULL, // pointer to security attributes + FALSE, // automatic reset + FALSE, // initialize to nosignaled + NULL); // pointer to the event-object name + bState = + DeviceIoControl(m_h_dev, + (DWORD)IOCTL_CANCEL_IO, + (LPVOID)&pipeType, + sizeof(PIPE_TYPE), + NULL, + 0, + &cbRet, + &overlapped); + WaitForSingleObject(overlapped.hEvent, 1000); + CloseHandle(overlapped.hEvent); + + for (by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) { + CancelIo(m_usb_pipes[by_i].h_pipe); + CloseHandle(m_usb_pipes[by_i].h_pipe); + m_usb_pipes[by_i].h_pipe = INVALID_HANDLE_VALUE; + } + + CancelIo(m_h_dev); + b_ret = CloseHandle(m_h_dev); + if (b_ret) { + m_h_dev = INVALID_HANDLE_VALUE; + b_ret = TRUE; + } + } + m_b_is_connected = FALSE; + return b_ret; +} + +void UsbScanEx::set_timeout(int timeout) +{ + this->timeout = timeout; +} + +int UsbScanEx::read_bulk(void* data, int len) +{ + BOOL b_ret = FALSE; + HANDLE h_pipe = m_usb_pipes[BULK_IN].h_pipe; + unsigned long pdw_ret = len; + LPOVERLAPPED lp_overlap = ov+BULK_IN; + lp_overlap->Internal = 0; + lp_overlap->InternalHigh = 0; + lp_overlap->Offset = 0; + lp_overlap->OffsetHigh = 0; + lp_overlap->Pointer = 0; + + if (m_h_dev != NULL) { + b_ret = ReadFile(h_pipe, data, len, &pdw_ret, lp_overlap); + + if (b_ret) { + return pdw_ret; + } + else { + switch (GetLastError()) + { + case ERROR_IO_PENDING: + GetOverlappedResult(h_pipe, lp_overlap, &pdw_ret, TRUE); + return pdw_ret; + + case ERROR_FILE_NOT_FOUND: + m_b_is_connected = false; + break; + default: + int a = 0; + break; + } + } + } + return 0; +} + +int UsbScanEx::write_bulk(void* data, int len) +{ + BOOL b_ret = FALSE; + HANDLE h_pipe = m_usb_pipes[BULK_OUT].h_pipe; + void* p_data = data; + unsigned long dw_size = len; + + LPOVERLAPPED lp_overlap = ov + BULK_OUT; + + if (m_h_dev == INVALID_HANDLE_VALUE) + return TRUE; + + b_ret = WriteFile(h_pipe, p_data, dw_size, &dw_size, lp_overlap); + if (b_ret) { + return dw_size; + } + else { + switch (GetLastError()) + { + case ERROR_IO_PENDING: + GetOverlappedResult(h_pipe, lp_overlap, &dw_size, TRUE); + return dw_size; + + case ERROR_FILE_NOT_FOUND: + m_b_is_connected = false; + break; + default: + int a = 0; + break; + } + } + return 0; +} + +int UsbScanEx::control_msg(int rtype, int req, int value, int index, int len, void* data) +{ + BOOL b_ret = FALSE; + _IO_BLOCK_EX irp; + DWORD dw_ret; + + if (m_h_dev == INVALID_HANDLE_VALUE) + return TRUE; + irp.uOffset = value; + irp.uLength = len; + irp.uIndex = index; + irp.pbyData = (LPBYTE)data; + irp.fTransferDirectionIn = (rtype >> 7); + irp.bRequest = req; + irp.bmRequestType = (rtype >> 5) & 0x03; + + LPOVERLAPPED lp_overlap = ov + CTRL_IN_OUT; + b_ret = DeviceIoControl(m_h_dev, IOCTL_SEND_USB_REQUEST, &irp, sizeof(irp), data, len, &dw_ret, lp_overlap); + + if (!b_ret) + b_ret = WaitForSingleObject(lp_overlap->hEvent, timeout) == WAIT_OBJECT_0; + + return b_ret; +} + +bool UsbScanEx::is_open() +{ + return m_h_dev != INVALID_HANDLE_VALUE; +} + +bool UsbScanEx::is_connected() +{ + return is_open();//m_b_is_connected; +} + +int UsbScanEx::read_int(void* data, int len) +{ + BOOL b_ret = FALSE; + DWORD dw_ret = 0L; + HANDLE h_pipe = m_usb_pipes[INT_IN].h_pipe; + LPOVERLAPPED lp_overlap = ov + INT_IN; + + if (m_h_dev == INVALID_HANDLE_VALUE) + return FALSE; + + b_ret = DeviceIoControl(h_pipe, (DWORD)IOCTL_WAIT_ON_DEVICE_EVENT, NULL, 0, + data, len, &dw_ret, lp_overlap); + + if (b_ret) { + return dw_ret; + } + else { + switch (GetLastError()) + { + case ERROR_IO_PENDING: + GetOverlappedResult(h_pipe, lp_overlap, &dw_ret, TRUE); + return dw_ret; + + case ERROR_FILE_NOT_FOUND: + m_b_is_connected = false; + break; + default: + break; + } + } + + return 0; +} + +UsbScan_List::~UsbScan_List() +{ +} + +std::list> UsbScan_List::find_all() +{ + auto devs = find_all_usb(); + std::list> usbs; + for (auto inter = devs.begin(); inter != devs.end(); inter++) { + usbs.push_back(std::shared_ptr(new UsbScanEx(inter->index))); + } + return usbs; +} + +std::list> UsbScan_List::find_vid_pid(int vid, int pid) +{ + auto devs = find_all_usb(); + std::list> usbs; + for (auto inter = devs.begin(); inter != devs.end(); inter++) { + if (inter->vid == vid && inter->pid == pid) + usbs.push_back(std::shared_ptr(new UsbScanEx(inter->index))); + } + return usbs; +} + +std::list UsbScan_List::find_all_usb() +{ + BOOL b_ret = FALSE; + DWORD cbRet = 0; + TCHAR szDevPath[MAX_PATH] = { 0 }; + DEVICE_DESCRIPTOR dev_desc; + HANDLE h_dev; + std::list usbs; + usb_scan_dev_info dev_info; + + for (int i = 0; i < 1024; i++) { + + _stprintf(szDevPath, TEXT("\\\\.\\Usbscan%d"), i); + h_dev = CreateFile(szDevPath, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + if (h_dev != INVALID_HANDLE_VALUE) { + b_ret = DeviceIoControl(h_dev, (DWORD)IOCTL_GET_DEVICE_DESCRIPTOR, + &dev_desc, sizeof(dev_desc), &dev_desc, sizeof(dev_desc), + &cbRet, NULL); + if (b_ret != 0) { + dev_info.index = i; + dev_info.vid = dev_desc.usVendorId; + dev_info.pid = dev_desc.usProductId; + usbs.push_back(dev_info); + } + CloseHandle(h_dev); + } + } + + return usbs; +} diff --git a/UsbScanEx.h b/UsbScanEx.h new file mode 100644 index 0000000..fd30b89 --- /dev/null +++ b/UsbScanEx.h @@ -0,0 +1,76 @@ +#pragma once +#include +#include +#include +#include +#include "IUsb.h" + + +#pragma pack(1) +struct tag_usb_pipe +{ + HANDLE h_pipe; + USBSCAN_PIPE_INFORMATION pipe_info; + OVERLAPPED overlap; +}; +typedef struct tag_usb_pipe usb_pipe_t, * pusb_pipe_t; +#pragma pack() + +typedef struct tag_usb_scan_dev_info +{ + WORD vid; + WORD pid; + WORD index; +}usb_scan_dev_info, * pusb_scan_dev_info; + +typedef struct tag_usb_scan_dev +{ + USHORT _NumberOfDevs; + tag_usb_scan_dev_info dev_infos[1024]; +}usb_scan_dev, * pusb_scan_dev; + +class UsbScanEx : public IUsb +{ +public: + UsbScanEx(int index); + virtual ~UsbScanEx(); + // 通过 IUsb 继承 + virtual bool open() override; + virtual bool close() override; + virtual void set_timeout(int timeout) override; + virtual int read_bulk(void *data, int len) override; + virtual int write_bulk(void *data, int len) override; + virtual int control_msg(int rtype, int req, int value, int index, int len, void* data) override; + virtual bool is_open() override; + virtual bool is_connected() override; + virtual int read_int(void* data, int len) override; + +private: + + int BULK_OUT; + int BULK_IN; + int INT_IN; + int CTRL_IN_OUT; + USBSCAN_PIPE_CONFIGURATION m_usbscan_config; + usb_pipe_t m_usb_pipes[MAX_NUM_PIPES]; + HANDLE m_h_dev; + bool m_b_is_connected; + int m_h_index; + int timeout; + OVERLAPPED ov[4]; +}; + + +class UsbScan_List +{ +public: + ~UsbScan_List(); + + static std::list> find_all(); + static std::list> find_vid_pid(int vid, int pid); + +private: + static std::list find_all_usb(); + UsbScan_List(); + UsbScan_List(uint16_t vendor_id, uint16_t product_id); +}; diff --git a/device_common.h b/device_common.h new file mode 100644 index 0000000..7ec9b1e --- /dev/null +++ b/device_common.h @@ -0,0 +1,147 @@ +#pragma once +#define FLASH_ADDR_START (0x300000) //!open(); + if (m_usb->is_open()) { + GetFWVersion(); + GetSerialNum(); + } } + } static void DoEvents() @@ -121,7 +132,7 @@ void GScn_Drv::pushMat(JpegBuffer& data) BOOL GScn_Drv::IsConnected() { - return m_usb.is_connected(); + return m_usb->is_connected(); } @@ -129,9 +140,8 @@ cv::Mat GScn_Drv::Get_Img_Data(int bufferSize) { cv::Mat iData(1, bufferSize, CV_8UC1); USBCB usbcb = { GET_IMAGE,0,(UINT32)bufferSize }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - m_usb.Read_Data(iData.data, bufferSize, 2000, &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + m_usb->read_bulk(iData.data, bufferSize); return iData; } @@ -187,7 +197,7 @@ DWORD GScn_Drv::usbmain() devState = DEV_ISRUNNING; while (devState == DEV_ISRUNNING) { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) { this_thread::sleep_for(chrono::milliseconds(200)); continue; @@ -260,13 +270,12 @@ DWORD GScn_Drv::usbmain() void GScn_Drv::config_params(SFreeImage & params) { - if (m_usb.is_connected()) + if (m_usb->is_connected()) { hgConfigClass cfg(params); UINT32 cfgdata = cfg.GetData(); USBCB usbcb = { CONFIGURED_DATA,cfgdata,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(USBCB), &transfer); + m_usb->write_bulk(&usbcb, sizeof(USBCB)); setdecodepixtype(params.m_HardWareParams.PixType); m_pImages.setparam(params); } @@ -275,12 +284,12 @@ void GScn_Drv::config_params(SFreeImage & params) /////////////////////////////////////////////////////////////////////////// void GScn_Drv::Scanner_StartScan(UINT16 count) { - if (m_usb.is_connected()) + if (m_usb->is_connected()) { std::lock_guard lck(m_imgLocker); DWORD transfer; USBCB usbcb = { START_COMMAND,(UINT32)count ,0 }; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); run(); m_pImages.SetScanningStatus(true); m_pImages.run(); @@ -291,16 +300,15 @@ void GScn_Drv::Scanner_StartScan(UINT16 count) std::string GScn_Drv::GetFWVersion() { XdPrint("GetFWVersion \n"); - if (m_usb.is_connected()) + if (m_usb->is_connected()) { std::lock_guard lck(m_imgLocker); if (fwVersion.empty()) { fwVersion = " "; USBCB usbcb = { GET_FW_VERSION,8,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - m_usb.Read_Data(&fwVersion[0], 8, 200, &transfer); + m_usb->write_bulk( &usbcb, sizeof(usbcb)); + m_usb->read_bulk(&fwVersion[0], 8); } return fwVersion; } @@ -310,16 +318,15 @@ std::string GScn_Drv::GetFWVersion() /////////////////////////////////////////////////////////////////////////// std::string GScn_Drv::GetSerialNum() { - if (m_usb.is_connected()) + if (m_usb->is_connected()) { std::lock_guard lck(m_imgLocker); if (SerialNum.empty()) { SerialNum = " "; USBCB usbcb = { GET_SERIAL,12,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - m_usb.Read_Data(&SerialNum[0], 12, 200, &transfer); + m_usb->write_bulk( &usbcb, sizeof(usbcb)); + m_usb->read_bulk(&SerialNum[0], 12); } return SerialNum; } @@ -329,16 +336,15 @@ std::string GScn_Drv::GetSerialNum() /////////////////////////////////////////////////////////////////////////// USBCB GScn_Drv::Get_Scanner_Status() { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) { USBCB errorType = { NO_COMMAND ,PC_SCAN_BUSY_or_ERROR ,0 }; return errorType; } USBCB usbcb = { GET_DSP_STATUS ,0,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - m_usb.Read_Data(&usbcb, sizeof(usbcb), 200, &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + m_usb->read_bulk(&usbcb, sizeof(usbcb)); return usbcb; } @@ -353,28 +359,26 @@ bool GScn_Drv::is_scan() BOOL GScn_Drv::Get_Scanner_PaperOn() { XdPrint("Get_Scanner_PaperOn \n"); - if (!m_usb.is_connected()) + if (!m_usb->is_open()) { return FALSE; } USBCB usbcb = { GET_PAPER_STATUS ,0,0 }; - DWORD transfer; std::lock_guard lck(m_imgLocker); - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); - m_usb.bulk_in(0x00, &usbcb, sizeof(usbcb), 200, &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); + m_usb->read_bulk( &usbcb, sizeof(usbcb)); return usbcb.u32_Data != 0; } /////////////////////////////////////////////////////////////////////////// void GScn_Drv::Pop_Image() { - if (!m_usb.is_connected()) + if (!m_usb->is_open()) { return; } USBCB usbcb = { POP_IMAGE ,0,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); } void GScn_Drv::trim(std::string &s) @@ -392,25 +396,24 @@ void GScn_Drv::trim(std::string &s) /////////////////////////////////////////////////////////////////////////// void GScn_Drv::Stop_scan() { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) { return; } std::lock_guard lck(m_imgLocker); USBCB usbcb = { STOP ,0,0 }; - DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); } void GScn_Drv::ResetScanner() { - if (!m_usb.is_connected()) + if (!m_usb->is_connected()) return; std::lock_guard lck(m_imgLocker); USBCB usbcb = { INIT_HARDWARE_SYS ,0,0 }; DWORD transfer; - m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); + m_usb->write_bulk(&usbcb, sizeof(usbcb)); } /////////////////////////////////////////////////////////////////////////// diff --git a/gscn_drv.h b/gscn_drv.h index 4edd8ab..d0d4e45 100644 --- a/gscn_drv.h +++ b/gscn_drv.h @@ -1,5 +1,4 @@ #pragma once -#include "scn_usb.h" #include #include #include @@ -37,11 +36,38 @@ class DiscardBlank; class CImageApply; -class GScn_Drv +class IGScan +{ +public: + virtual ~IGScan()=0 {}; + + virtual void open(int vid, int pid) = 0;; + virtual int aquire_image(cv::Mat& image) = 0; + virtual BOOL IsConnected() = 0; + virtual std::string GetFWVersion() = 0; + virtual std::string GetSerialNum() = 0; + virtual bool is_scan() = 0; + virtual BOOL Get_Scanner_PaperOn() = 0; + virtual void config_params(SFreeImage& params) = 0; + virtual void Scanner_StartScan(UINT16 count) = 0; + virtual void Stop_scan() = 0; + virtual void ResetScanner() =0; + virtual bool Get_IsImageQueueEmpty() = 0; + virtual void reset() = 0; + + virtual void setdecodepixtype(int twpixtype)= 0; + virtual UINT32 get_ErrorCode() = 0; + virtual void Set_ErrorCode(UINT32 value) = 0; +}; + + +class IUsb; + +class GScn_Drv : IGScan { public: GScn_Drv(); - ~GScn_Drv(); + virtual ~GScn_Drv(); void open(int vid, int pid); int aquire_image(cv::Mat& image); @@ -72,7 +98,8 @@ private: DWORD usbmain(); void Pop_Image(); void trim(std::string &s); - cscn_usb m_usb; +// cscn_usb m_usb; + std::shared_ptr m_usb; HANDLE m_h_usb_thread; DWORD m_dw_ctrl_thread_id; volatile int devState; diff --git a/hugaotwainds.aps b/hugaotwainds.aps index bc0ca39..d5f94e4 100644 Binary files a/hugaotwainds.aps and b/hugaotwainds.aps differ diff --git a/hugaotwainds.vcxproj b/hugaotwainds.vcxproj index 9659f84..ef1bef2 100644 --- a/hugaotwainds.vcxproj +++ b/hugaotwainds.vcxproj @@ -23,20 +23,20 @@ {F928F998-CD13-478E-8D23-5943C2B108F5} MFCDLLProj hugaotwainds - 10.0.17763.0 + 10.0 DynamicLibrary true - v141 + v142 MultiByte Dynamic DynamicLibrary false - v141 + v142 true MultiByte Dynamic @@ -44,14 +44,14 @@ DynamicLibrary true - v141 + v142 MultiByte Dynamic DynamicLibrary false - v141 + v142 true MultiByte Dynamic @@ -139,7 +139,7 @@ Level3 Disabled _WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) - C:\local\boost_1_69_0;.\pub\external\include;.\pub\ddk;.\pub\opencv\include;.\pub\json;%(AdditionalIncludeDirectories) + .\pub\external\include;.\pub\ddk;.\opencv\include;.\pub\json;%(AdditionalIncludeDirectories) Windows @@ -227,6 +227,8 @@ + + @@ -252,7 +254,6 @@ - Create Create @@ -271,6 +272,7 @@ + @@ -295,8 +297,11 @@ + + + @@ -313,6 +318,7 @@ + @@ -324,8 +330,8 @@ - + @@ -340,6 +346,7 @@ + diff --git a/hugaotwainds.vcxproj.filters b/hugaotwainds.vcxproj.filters index 0c7f5c8..c141dea 100644 --- a/hugaotwainds.vcxproj.filters +++ b/hugaotwainds.vcxproj.filters @@ -90,9 +90,6 @@ USB閫氫俊 - - USB閫氫俊 - UI @@ -189,6 +186,15 @@ 浠g爜鏂囦欢 + + 浠g爜鏂囦欢 + + + 浠g爜鏂囦欢 + + + 浠g爜鏂囦欢 + @@ -271,9 +277,6 @@ USB閫氫俊 - - USB閫氫俊 - UI @@ -388,6 +391,24 @@ 澶存枃浠 + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + diff --git a/scn_usb.cpp b/scn_usb.cpp deleted file mode 100644 index 9c816d9..0000000 --- a/scn_usb.cpp +++ /dev/null @@ -1,455 +0,0 @@ -#include "stdafx.h" -#include -#include -#include "scn_usb.h" -#include "winioctl.h" -#include "PublicFunc.h" -#include "filetools.h" - -//CUSBHotPlugged usb; -cscn_usb::cscn_usb(void) -{ - m_h_dev = INVALID_HANDLE_VALUE; - m_usbscan_config = { 0 }; - m_w_serial_no = 0; -} - -cscn_usb::~cscn_usb(void) -{ - close(); - //FileTools::write_log("1.txt", "~cscn_usb"); -} - -void cscn_usb::init(WORD w_vid, WORD w_pid) -{ - m_h_dev = INVALID_HANDLE_VALUE; - w_vid = w_vid; - w_pid = w_pid; - m_w_serial_no = 0; -} - -HANDLE cscn_usb::open(WORD index) -{ - BOOL b_ret = FALSE; - TCHAR szDevPath[MAX_PATH] = { 0 }; - INT i = 0, j = 0; - DEVICE_DESCRIPTOR dev_desc; - DWORD cbRet = 0; - - - _stprintf(szDevPath, TEXT("\\\\.\\Usbscan%d"), index); - m_h_dev = CreateFile(szDevPath, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); - if (m_h_dev != INVALID_HANDLE_VALUE) - { - m_b_is_connected = TRUE; - b_ret = DeviceIoControl(m_h_dev, (DWORD)IOCTL_GET_DEVICE_DESCRIPTOR, - &dev_desc, sizeof(dev_desc), &dev_desc, sizeof(dev_desc), - &cbRet, NULL); - - if (b_ret) - { - m_w_vid = dev_desc.usVendorId; - m_w_pid = dev_desc.usProductId; - m_w_serial_no = index; - b_ret = DeviceIoControl(m_h_dev, (DWORD)IOCTL_GET_PIPE_CONFIGURATION, - NULL, 0, &m_usbscan_config, sizeof(USBSCAN_PIPE_CONFIGURATION), - &cbRet, NULL); - if (b_ret && m_usbscan_config.NumberOfPipes > 0) - { - for (int by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) - { - TCHAR szPipePath[MAX_PATH] = { 0 }; - _stprintf(szPipePath, TEXT("\\\\.\\Usbscan%d\\%d"), index, by_i); - m_usb_pipes[by_i].pipe_info = m_usbscan_config.PipeInfo[by_i]; - m_usb_pipes[by_i].h_pipe = CreateFile(szPipePath, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); - } - } - } - else - { - CloseHandle(m_h_dev); - m_h_dev = INVALID_HANDLE_VALUE; - } - } - - return m_h_dev; -} - -BOOL cscn_usb::close(void) -{ - BOOL b_ret = FALSE; - BYTE by_i = 0x00; - - if (m_h_dev != INVALID_HANDLE_VALUE) - { - - BOOL bState = FALSE; - DWORD cbRet = 0; - OVERLAPPED overlapped; - PIPE_TYPE pipeType = ALL_PIPE; - - memset(&overlapped, 0, sizeof(OVERLAPPED)); - overlapped.hEvent = - CreateEvent(NULL, // pointer to security attributes - FALSE, // automatic reset - FALSE, // initialize to nosignaled - NULL); // pointer to the event-object name - bState = - DeviceIoControl(m_h_dev, - (DWORD)IOCTL_CANCEL_IO, - (LPVOID)&pipeType, - sizeof(PIPE_TYPE), - NULL, - 0, - &cbRet, - &overlapped); - WaitForSingleObject(overlapped.hEvent, 1000); - CloseHandle(overlapped.hEvent); - - for (by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) - { - CancelIo(m_usb_pipes[by_i].h_pipe); //++@2012-06-08 - CloseHandle(m_usb_pipes[by_i].h_pipe); - m_usb_pipes[by_i].h_pipe = INVALID_HANDLE_VALUE; - } - - CancelIo(m_h_dev); //++@2012-06-08 - b_ret = CloseHandle(m_h_dev); - if (b_ret) - { - m_h_dev = INVALID_HANDLE_VALUE; - b_ret = TRUE; - } - } - m_b_is_connected = FALSE; - return b_ret; -} - -BOOL cscn_usb::control_in(BYTE by_pipe_addr, WORD w_value, WORD w_index, PVOID p_data, DWORD dw_size, PDWORD pdw_read, LPOVERLAPPED lp_overlap) -{ - IO_BLOCK irp; - DWORD dw_ret; - HANDLE h_pipe = INVALID_HANDLE_VALUE; - - if (m_h_dev == INVALID_HANDLE_VALUE) - return TRUE; - irp.uOffset = w_value; - irp.uLength = dw_size; - irp.uIndex = w_index; - irp.pbyData = (LPBYTE)p_data; - - if (by_pipe_addr == 0x00) - h_pipe = m_h_dev; - else - { - BYTE by_i = 0x00; - for (by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) - { - if (m_usb_pipes[by_i].pipe_info.EndpointAddress == by_pipe_addr) - h_pipe = m_usb_pipes[by_i].h_pipe; - } - } - return DeviceIoControl(h_pipe, IOCTL_READ_REGISTERS, &irp, sizeof(IO_BLOCK), p_data, 64, &dw_ret, lp_overlap); -} - -BOOL cscn_usb::control_out(BYTE by_pipe_addr, WORD w_value, WORD w_index, PVOID p_data, DWORD dw_size, PDWORD pdw_write, LPOVERLAPPED lp_overlap) -{ - BOOL b_ret = FALSE; - IO_BLOCK irp; - DWORD dw_ret; - HANDLE h_pipe = INVALID_HANDLE_VALUE; - - if (m_h_dev == INVALID_HANDLE_VALUE) - return TRUE; - irp.uOffset = w_value; - irp.uLength = dw_size; - irp.uIndex = w_index; - irp.pbyData = (LPBYTE)p_data; - if (by_pipe_addr == 0x00) - h_pipe = m_h_dev; - else - { - BYTE by_i = 0x00; - for (by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) - { - if (m_usb_pipes[by_i].pipe_info.EndpointAddress == by_pipe_addr) - h_pipe = m_usb_pipes[by_i].h_pipe; - } - } - b_ret = DeviceIoControl(h_pipe, IOCTL_WRITE_REGISTERS, &irp, sizeof(IO_BLOCK), NULL, 0L, &dw_ret, lp_overlap); - if (!b_ret) - { - if (ERROR_FILE_NOT_FOUND == GetLastError()) - m_b_is_connected = FALSE; - } - return b_ret; -} - -BOOL cscn_usb::interrupt_in(BYTE by_pipe_addr, PBYTE pby_data, BYTE by_len, PBYTE pby_read, LPOVERLAPPED lp_overlap) -{ - BOOL b_ret = FALSE; - IO_BLOCK irp = { 0 }; - DWORD dw_ret = 0L; - HANDLE h_pipe = INVALID_HANDLE_VALUE; - BYTE by_i = 0x00; - - if (m_h_dev == INVALID_HANDLE_VALUE) - return FALSE; - - for (by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) - { - if (m_usb_pipes[by_i].pipe_info.EndpointAddress == by_pipe_addr) - h_pipe = m_usb_pipes[by_i].h_pipe; - } - b_ret = DeviceIoControl(h_pipe, (DWORD)IOCTL_WAIT_ON_DEVICE_EVENT, - NULL, 0, pby_data, by_len, &dw_ret, lp_overlap); - if (!b_ret) - { - if (ERROR_FILE_NOT_FOUND == GetLastError()) - m_b_is_connected = FALSE; - } - if (lp_overlap != NULL) - { - DWORD dw_trans = 0x0L; - b_ret = WaitForSingleObject(lp_overlap->hEvent, 50) == WAIT_OBJECT_0; - if (b_ret) - { - b_ret = GetOverlappedResult(h_pipe, lp_overlap, &dw_trans, FALSE); - if (b_ret) - { - if (pby_read != NULL) - *pby_read = dw_trans & 0xff; - } - else - { - if (ERROR_FILE_NOT_FOUND == GetLastError()) - m_b_is_connected = FALSE; - } - } - } - else - { - if (pby_read != NULL) - *pby_read = dw_ret & 0xff; - } - - return b_ret; -} - -BOOL cscn_usb::bulk_in(BYTE by_pipe_addr, PVOID p_data, DWORD dw_size,DWORD timeout, PDWORD pdw_ret) -{ - HANDLE h_pipe = INVALID_HANDLE_VALUE; - BOOL b_ret = FALSE; - - OVERLAPPED oa; - memset(&oa, 0, sizeof(oa)); - oa.hEvent = CreateEvent(0, TRUE, FALSE, NULL); - LPOVERLAPPED lp_overlap = &oa; - - if (m_h_dev == INVALID_HANDLE_VALUE) - return TRUE; - if (by_pipe_addr == 0x00) - h_pipe = m_h_dev; - else - { - BYTE by_i = 0x00; - for (by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) - { - if (m_usb_pipes[by_i].pipe_info.EndpointAddress == by_pipe_addr) - h_pipe = m_usb_pipes[by_i].h_pipe; - } - } - b_ret = ReadFile(h_pipe, p_data, dw_size, pdw_ret, lp_overlap); - if (lp_overlap != NULL) - { - DWORD dw_trans = 0x0L;; - b_ret = WaitForSingleObject(lp_overlap->hEvent, timeout) == WAIT_OBJECT_0; - if (b_ret) - { - b_ret = GetOverlappedResult(h_pipe, lp_overlap, &dw_trans, FALSE); - if (b_ret) - { - if (pdw_ret != NULL) - *pdw_ret = dw_trans; - } - else - { - if (ERROR_FILE_NOT_FOUND == GetLastError()) - m_b_is_connected = FALSE; - } - } - } - else - return b_ret; - CloseHandle(lp_overlap->hEvent); - return b_ret; -} -//overlap do not use current -BOOL cscn_usb::bulk_out(BYTE by_pipe_addr, PVOID p_data, DWORD dw_size, PDWORD pdw_ret) -{ - BOOL b_ret = FALSE; - HANDLE h_pipe = INVALID_HANDLE_VALUE; - - OVERLAPPED oa; - memset(&oa, 0, sizeof(oa)); - oa.hEvent = CreateEvent(0, TRUE, FALSE, NULL); - LPOVERLAPPED lp_overlap = &oa; - - if (m_h_dev == INVALID_HANDLE_VALUE) - return TRUE; - if (by_pipe_addr == 0x00) - h_pipe = m_h_dev; - else - { - BYTE by_i = 0x00; - for (by_i = 0x00; by_i < m_usbscan_config.NumberOfPipes; by_i++) - { - if (m_usb_pipes[by_i].pipe_info.EndpointAddress == by_pipe_addr) - h_pipe = m_usb_pipes[by_i].h_pipe; - } - } - - b_ret = WriteFile(h_pipe, p_data, dw_size, pdw_ret, lp_overlap); - if (!b_ret) - { - DWORD dw_trans = 0x0L; - b_ret = WaitForSingleObject(lp_overlap->hEvent, 1000) == WAIT_OBJECT_0; - if (b_ret) - { - b_ret = GetOverlappedResult(h_pipe, lp_overlap, &dw_trans, FALSE); - if (b_ret) - { - if (pdw_ret != NULL) - *pdw_ret = dw_trans; - } - else - { - if (ERROR_FILE_NOT_FOUND == GetLastError()) - m_b_is_connected = FALSE; - } - } - } - CloseHandle(lp_overlap->hEvent); - return b_ret; - -} - -BOOL cscn_usb::Read_Data(PVOID p_data, DWORD length, DWORD timeout, PDWORD pdw_ret) -{ - //HANDLE h_pipe = INVALID_HANDLE_VALUE; - BOOL b_ret = FALSE; - OVERLAPPED oa; - memset(&oa, 0, sizeof(oa)); - oa.hEvent = CreateEvent(0, TRUE, FALSE, NULL); - - LPOVERLAPPED lp_overlap = &oa; - - if (m_h_dev != NULL) - { - b_ret = ReadFile(m_h_dev, p_data, length, pdw_ret, lp_overlap); - DWORD dw_trans = 0x0L; - b_ret = WaitForSingleObject(lp_overlap->hEvent, timeout) == WAIT_OBJECT_0; - if (b_ret) - { - b_ret = GetOverlappedResult(m_h_dev, lp_overlap, &dw_trans, FALSE); - if (b_ret) - { - if (pdw_ret != NULL) - { - *pdw_ret = dw_trans; - } - CloseHandle(lp_overlap->hEvent); - return TRUE; - } - } - } - CloseHandle(lp_overlap->hEvent); - return FALSE; -} - -BOOL cscn_usb::is_connected(void) -{ - return m_b_is_connected; -} - -usb_scan_dev Devices() -{ - usb_scan_dev devs; - memset(&devs, 0, sizeof(devs)); - BOOL b_ret = FALSE; - TCHAR szDevPath[MAX_PATH] = { 0 }; - DEVICE_DESCRIPTOR dev_desc; - DWORD cbRet = 0; - HANDLE h_dev; - for (int i = 0; i < 1024; i++) - { - _stprintf(szDevPath, TEXT("\\\\.\\Usbscan%d"), i); - h_dev = CreateFile(szDevPath, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); - - if (h_dev != INVALID_HANDLE_VALUE) - { - b_ret = DeviceIoControl(h_dev, (DWORD)IOCTL_GET_DEVICE_DESCRIPTOR, - &dev_desc, sizeof(dev_desc), &dev_desc, sizeof(dev_desc), - &cbRet, NULL); - if (b_ret) - { - devs.dev_infos[devs._NumberOfDevs].index = i; - devs.dev_infos[devs._NumberOfDevs].vid = dev_desc.usVendorId; - devs.dev_infos[devs._NumberOfDevs].pid = dev_desc.usProductId; - devs._NumberOfDevs++; - } - CloseHandle(h_dev); - h_dev = INVALID_HANDLE_VALUE; - } - } - - return devs; -} -usb_scan_dev Devices(WORD w_vid) -{ - usb_scan_dev all_dev = Devices(); - usb_scan_dev devs; - memset(&devs, 0, sizeof(devs)); - for (int i = 0; i < all_dev._NumberOfDevs; i++) - { - if (all_dev.dev_infos[i].vid == w_vid) - { - devs.dev_infos[devs._NumberOfDevs] = all_dev.dev_infos[i]; - devs._NumberOfDevs++; - } - } - return devs; -} -usb_scan_dev Devices(WORD w_vid, WORD w_pid) -{ - usb_scan_dev all_dev = Devices(); - usb_scan_dev devs; - memset(&devs, 0, sizeof(devs)); - for (int i = 0; i < all_dev._NumberOfDevs; i++) - { - if (all_dev.dev_infos[i].vid == w_vid && all_dev.dev_infos[i].pid == w_pid) - { - devs.dev_infos[devs._NumberOfDevs] = all_dev.dev_infos[i]; - devs._NumberOfDevs++; - } - } - return devs; -} \ No newline at end of file diff --git a/scn_usb.h b/scn_usb.h deleted file mode 100644 index 6e6043b..0000000 --- a/scn_usb.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SCN_USB_H_HEADER_INCLUDED_B2BF228E -#define SCN_USB_H_HEADER_INCLUDED_B2BF228E -#include -#include - -#pragma pack(1) -struct tag_usb_pipe -{ - HANDLE h_pipe; - USBSCAN_PIPE_INFORMATION pipe_info; - OVERLAPPED overlap; -}; -typedef struct tag_usb_pipe usb_pipe_t, *pusb_pipe_t; -#pragma pack() - -typedef struct tag_usb_scan_dev_info -{ - WORD vid; - WORD pid; - WORD index; -}usb_scan_dev_info, *pusb_scan_dev_info; - -typedef struct tag_usb_scan_dev -{ - USHORT _NumberOfDevs; - tag_usb_scan_dev_info dev_infos[1024]; -}usb_scan_dev, *pusb_scan_dev; - -//##ModelId=4D40D3230138 -class cscn_usb -{ -public: - - USBSCAN_PIPE_CONFIGURATION m_usbscan_config; - usb_pipe_t m_usb_pipes[MAX_NUM_PIPES]; - HANDLE m_h_dev; - void init(WORD w_vid, WORD w_pid); - BOOL control_in (BYTE by_pipe_addr, WORD w_value, WORD w_index, PVOID p_data, DWORD dw_size, PDWORD pdw_read, LPOVERLAPPED lp_overlap); - BOOL control_out (BYTE by_pipe_addr, WORD w_value, WORD w_index, PVOID p_data, DWORD dw_size, PDWORD pdw_write, LPOVERLAPPED lp_overlap); - BOOL interrupt_in(BYTE by_pipe_addr, PBYTE pby_data, BYTE by_len, PBYTE pby_read, LPOVERLAPPED lp_overlap); - BOOL bulk_in (BYTE by_pipe_addr, PVOID p_data, DWORD dw_size, DWORD timeout,PDWORD pdw_ret); - BOOL bulk_out(BYTE by_pipe_addr, PVOID p_data, DWORD dw_size, PDWORD pdw_ret); - HANDLE open(WORD index); - BOOL Read_Data(PVOID p_data, DWORD length, DWORD timeout, PDWORD pdw_ret); - BOOL close(void); - cscn_usb(void); - ~cscn_usb(void); - BOOL is_connected(void); - -private: - BOOL m_b_is_connected; - //##ModelId=4D41B612027E - WORD m_w_vid; - //##ModelId=4D41B62200F7 - WORD m_w_pid; - //##ModelId=4D41B63103A7 - WORD m_w_serial_no; - -}; - - -usb_scan_dev Devices(); -usb_scan_dev Devices(WORD w_vid); -usb_scan_dev Devices(WORD w_vid, WORD w_pid); - -#endif /* SCN_USB_H_HEADER_INCLUDED_B2BF228E */