From 94f6e5531679424585d3fe1ff443976c428e9ac9 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Fri, 22 Jul 2022 11:24:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9scannerlib=E7=9A=84=E6=B5=8B?= =?UTF-8?q?=E8=AF=95demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/scannerlib/CMakeLists.txt | 12 ++ test/scannerlib/main.cpp | 193 +++++++++++++++++++++++++++++++++ test/scannerlib/test.cpp | 35 ------ 3 files changed, 205 insertions(+), 35 deletions(-) create mode 100644 test/scannerlib/CMakeLists.txt create mode 100644 test/scannerlib/main.cpp delete mode 100644 test/scannerlib/test.cpp diff --git a/test/scannerlib/CMakeLists.txt b/test/scannerlib/CMakeLists.txt new file mode 100644 index 00000000..d52fc773 --- /dev/null +++ b/test/scannerlib/CMakeLists.txt @@ -0,0 +1,12 @@ +project(testdemo) + +FILE(GLOB SRC "*.cpp" "*.h" "*.c") +include_directories(${PROJECT_SOURCE_DIR}/../include) + +add_executable(${PROJECT_NAME} ${SRC}) + +target_link_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/../lib) + +target_link_libraries(${PROJECT_NAME} LscBase lscdriver LscImgFmt LscImgProc LscScannerLib mupdf pdf sane-lscsane) + +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin) \ No newline at end of file diff --git a/test/scannerlib/main.cpp b/test/scannerlib/main.cpp new file mode 100644 index 00000000..5f6ee89e --- /dev/null +++ b/test/scannerlib/main.cpp @@ -0,0 +1,193 @@ +#include +#include +#include +#include +#include "HGScannerLib.h" +#include "sane_option_definitions.h" + +#define DELEAY_MS(x) std::this_thread::sleep_for(std::chrono::milliseconds((x))) +using namespace std; + +//有图事件回调 +static void DeviceScanImageFunc(HGLibDevice device, HGLibImage image, HGPointer param) +{ + static int indeximg = 0; + string savepath = std::to_string(++indeximg) + ".jpg"; + cout << "save image : " << savepath << endl; + auto ret = HGLib_SaveImage(image, savepath.c_str(), 0); + cout << "save image : " << savepath << (ret ? " success" : " failed") << endl; +} + +//设备热拔插事件回调 +static void DeviceHotPlugEvent(HGUInt event, const HGChar *deviceName, HGPointer param) +{ + cout << "Devices : " << deviceName << " DeviceHotPlugEvent : " << (event == HGLIB_DEVHOTPLUG_EVENT_ARRIVE ? "HGLIB_DEVHOTPLUG_EVENT_ARRIVE " : "HGLIB_DEVHOTPLUG_EVENT_LEFT") << endl; +} + +//扫描状态事件回调 +static void DeviceScanEvent(HGLibDevice device, HGUInt event, HGBool err, const HGChar *info, HGPointer param) +{ + switch (event) + { + case HGLIB_DEVSCAN_EVENT_BEGIN: + cout << "DeviceScanEvent Start Scan" << endl; + break; + case HGLIB_DEVSCAN_EVENT_END: + cout << "DeviceScanEvent Scan stopped" << endl; + break; + case HGLIB_DEVSCAN_EVENT_INFO: + cout << "DeviceScanEvent info : " << info << endl; + break; + default: + cout << "Unkownun DeviceScanEvent " << event << endl; + break; + } +} + +int main(unsigned char argc, unsigned char *argv[]) +{ + std::cout << "*********Enter LSC Scanner SDK Demo *********" << std::endl; + HGLib_InitDevice(DeviceHotPlugEvent, 0); //初始化调用模块 + DELEAY_MS(5000); + + HGChar **devNameList = HGLib_GetDeviceNameList(); //获取已连接的设备列表,已字符数组的形式返回 + if (devNameList) + { + HGLibDevice dev = HGLib_OpenDevice(devNameList[0]); //此示例代码中调用设备列表中第一个设备 + if (dev) + { + + HGUInt grpCount = 0; + HGLibDeviceGetParamGroup *groups = HGLib_GetDeviceParamGroupList(dev, &grpCount); + if (groups) + { + //获取sdk支持的功能项及配置项内容 + for (size_t i = 0; i < grpCount; i++) + { + cout << groups[i].groupName << endl; + for (size_t j = 0; j < groups[i].paramCount; j++) + { + cout << " title: " << groups[i].param[j].param.title + << " type: " << groups[i].param[j].param.type << endl; + switch (groups[i].param[j].rangeType) + { + case HGLIB_DEVPARAM_RANGETYPE_INTLIST: + for (size_t k = 0; k < groups[i].param[j].intValueList.count; k++) + { + cout<<"support value["<0 指定数量扫描 + // setparam.title = OPTION_TITLE_SMZS; + // setparam.type = HGLIB_DEVPARAM_TYPE_STRING; + // setparam.stringValue = OPTION_VALUE_SMZS_LXSM;//连续扫描 + // HGLib_SetDeviceParam(dev,&setparam,1); + + + setparam.title = OPTION_TITLE_SMZS; + setparam.type = HGLIB_DEVPARAM_TYPE_STRING; + setparam.stringValue = OPTION_VALUE_SMZS_SMZDZS;//指定张数扫描 + HGLib_SetDeviceParam(dev,&setparam,1); + + setparam.title = OPTION_TITLE_SMSL; + setparam.type = HGLIB_DEVPARAM_TYPE_INT; + setparam.intValue = 1;//扫描张数 + HGLib_SetDeviceParam(dev,&setparam,1); + if (HGLib_StartDeviceScan(dev, DeviceScanEvent, 0, DeviceScanImageFunc, 0)) //开始启动扫描并注册扫描事件以及图像回调 + { + DELEAY_MS(10000); //实际走纸延时等待处理 + HGLib_StopDeviceScan(dev); + } + HGBool ret = HGLib_ReleaseDeviceParamGroupList(groups,grpCount); + if(!ret) + cout << "HGLib_ReleaseDeviceParamGroupList failed"< - -static void DeviceScanImageFunc(HGLibDevice device, HGLibImage image, HGPointer param) -{ - HGLib_SaveImage(image, "D:\\11111.jpg", 0); -} - -int main() -{ - HGLib_InitDevice(0, 0); - - Sleep(100); - - HGChar **devNameList = HGLib_GetDeviceNameList(); - if (devNameList) - { - HGLibDevice dev = HGLib_OpenDevice(devNameList[0]); - if (dev) - { - if (HGLib_StartDeviceScan(dev, 0, 0, DeviceScanImageFunc, 0)) - { - Sleep(10000); - HGLib_StopDeviceScan(dev); - } - - HGLib_CloseDevice(dev); - } - - HGLib_ReleaseDeviceNameList(devNameList); - } - - HGLib_DeinitDevice(); - return 0; -} \ No newline at end of file