From 4d6c5a9a3a32351da1d2ddf94304e39bf4307b87 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Fri, 16 Sep 2022 18:54:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3python=20demo=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E6=89=AB=E6=8F=8F=E6=B5=81=E7=A8=8B=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=89=AB=E6=8F=8F=E5=87=BA=E7=9A=84=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/scannerlib/test.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/test/scannerlib/test.py b/test/scannerlib/test.py index 01bcaa9b..8174bd8f 100644 --- a/test/scannerlib/test.py +++ b/test/scannerlib/test.py @@ -4,6 +4,7 @@ from os import system import time import platform from ctypes import * +import random class HGLibSaveImageParam(Structure): _fields_ = [ ("size", c_uint), @@ -78,25 +79,37 @@ HGLib_SetDeviceParam.restype = ctypes.c_int DevParam = ctypes.c_int(1) #HGLIB_OPTION_ENUMVALUE_DLSCLX_W -> 不进行多流输出类型 Ret = HGLib_SetDeviceParam(Device, 1, byref(DevParam)) #见HGLib_SetDeviceParam 头文件接口说明 1 -> HGLIB_OPTION_NAME_DLSC 多流输出 -bStop=False + #扫描事件回调 def HGLibDeviceScanEventFunc(device: c_void_p, event: c_uint, err: c_int, info: c_char_p, param: c_void_p): - print(info) + s_info=info + global bStop + print("event code",event," event info:",s_info) if event == 2:#HGLIB_DEVSCAN_EVENT_END 扫描停止 bStop=True + print("bStop true") elif event == 1: bStop=False + print("bStop false") return - +imgindex=0 #扫描图像事件回调 def HGLibDeviceScanImageFunc(device: c_void_p, image: c_void_p, param: c_void_p): + global imgindex ImageParam = HGLibSaveImageParam() ImageParam.size = 20 ImageParam.jpegQuality = 100 ImageParam.tiffCompression = 0 ImageParam.tiffJpegQuality = 0 ImageParam.ocr = 0 - Ret = HGLib_SaveImage(image, c_char_p(b"3.jpg"), pointer(ImageParam)) + print("image call back!!") + imgindex+=1 + t_index=imgindex + imgname=str(t_index) + '_scanned.jpg' + print(imgname) + b_imagename=imgname.encode('utf-8') + pchar=c_char_p(b_imagename) + Ret = HGLib_SaveImage(image, pchar, pointer(ImageParam)) return #注册扫描相关事件并启动扫描 @@ -111,9 +124,12 @@ print("start scan") Ret = HGLib_StartDeviceScan(Device, cb1, 0, cb2, 0) #模拟扫描持续应等待扫描事件回调返回扫描停止才结束本次扫描流程 -while(bStop != True): +while(not bStop): time.sleep(1) - break; + print("scanning...") + + +print("scan done!!!") #关闭当前打开的设备 HGLib_CloseDevice=Objdll.HGLib_CloseDevice