#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"<