python demo解决c_ulong和.h文件不统一的问题
This commit is contained in:
parent
01f18256e5
commit
97853a8b88
|
@ -6,10 +6,10 @@ import platform
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
|
|
||||||
class HGLibSaveImageParam(Structure):
|
class HGLibSaveImageParam(Structure):
|
||||||
_fields_ = [ ("size", c_ulong),
|
_fields_ = [ ("size", c_uint),
|
||||||
("jpegQuality", c_ulong),
|
("jpegQuality", c_uint),
|
||||||
("tiffCompression", c_ulong),
|
("tiffCompression", c_uint),
|
||||||
("tiffJpegQuality", c_ulong),
|
("tiffJpegQuality", c_uint),
|
||||||
("ocr", c_int)]
|
("ocr", c_int)]
|
||||||
|
|
||||||
print(os.path.abspath('.'))
|
print(os.path.abspath('.'))
|
||||||
|
@ -45,12 +45,12 @@ HGLib_ReleaseImage.restype = ctypes.c_int
|
||||||
Ret = HGLib_ReleaseImage(Image)
|
Ret = HGLib_ReleaseImage(Image)
|
||||||
|
|
||||||
#设备热拔插回调事件
|
#设备热拔插回调事件
|
||||||
def HGLibDeviceHotPlugEventFunc(event: c_ulong, deviceName: c_char_p, param: c_void_p):
|
def HGLibDeviceHotPlugEventFunc(event: c_uint, deviceName: c_char_p, param: c_void_p):
|
||||||
print(deviceName)
|
print(deviceName)
|
||||||
return
|
return
|
||||||
|
|
||||||
#初始化操作
|
#初始化操作
|
||||||
FuncType = CFUNCTYPE(None, c_ulong, c_char_p, c_void_p)
|
FuncType = CFUNCTYPE(None, c_uint, c_char_p, c_void_p)
|
||||||
cb = FuncType(HGLibDeviceHotPlugEventFunc)
|
cb = FuncType(HGLibDeviceHotPlugEventFunc)
|
||||||
HGLib_InitDevice = Objdll.HGLib_InitDevice
|
HGLib_InitDevice = Objdll.HGLib_InitDevice
|
||||||
HGLib_InitDevice.argtypes = [FuncType, c_void_p]
|
HGLib_InitDevice.argtypes = [FuncType, c_void_p]
|
||||||
|
@ -73,14 +73,14 @@ Device = HGLib_OpenDevice(DeviceNameList[0])
|
||||||
|
|
||||||
#设置扫描参数
|
#设置扫描参数
|
||||||
HGLib_SetDeviceParam = Objdll.HGLib_SetDeviceParam
|
HGLib_SetDeviceParam = Objdll.HGLib_SetDeviceParam
|
||||||
HGLib_SetDeviceParam.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_void_p]
|
HGLib_SetDeviceParam.argtypes = [ctypes.c_void_p, ctypes.c_uint, ctypes.c_void_p]
|
||||||
HGLib_SetDeviceParam.restype = ctypes.c_int
|
HGLib_SetDeviceParam.restype = ctypes.c_int
|
||||||
DevParam = ctypes.c_int(1) #HGLIB_OPTION_ENUMVALUE_DLSCLX_W -> 不进行多流输出类型
|
DevParam = ctypes.c_int(1) #HGLIB_OPTION_ENUMVALUE_DLSCLX_W -> 不进行多流输出类型
|
||||||
Ret = HGLib_SetDeviceParam(Device, 1, byref(DevParam)) #见HGLib_SetDeviceParam 头文件接口说明 1 -> HGLIB_OPTION_NAME_DLSC 多流输出
|
Ret = HGLib_SetDeviceParam(Device, 1, byref(DevParam)) #见HGLib_SetDeviceParam 头文件接口说明 1 -> HGLIB_OPTION_NAME_DLSC 多流输出
|
||||||
|
|
||||||
bStop=False
|
bStop=False
|
||||||
#扫描事件回调
|
#扫描事件回调
|
||||||
def HGLibDeviceScanEventFunc(device: c_void_p, event: c_ulong, err: c_int, info: c_char_p, param: c_void_p):
|
def HGLibDeviceScanEventFunc(device: c_void_p, event: c_uint, err: c_int, info: c_char_p, param: c_void_p):
|
||||||
print(info)
|
print(info)
|
||||||
if event == 2:#HGLIB_DEVSCAN_EVENT_END 扫描停止
|
if event == 2:#HGLIB_DEVSCAN_EVENT_END 扫描停止
|
||||||
bStop=True
|
bStop=True
|
||||||
|
@ -100,7 +100,7 @@ def HGLibDeviceScanImageFunc(device: c_void_p, image: c_void_p, param: c_void_p)
|
||||||
return
|
return
|
||||||
|
|
||||||
#注册扫描相关事件并启动扫描
|
#注册扫描相关事件并启动扫描
|
||||||
FuncType1 = CFUNCTYPE(None, c_void_p, c_ulong, c_int, c_char_p, c_void_p)
|
FuncType1 = CFUNCTYPE(None, c_void_p, c_uint, c_int, c_char_p, c_void_p)
|
||||||
cb1 = FuncType1(HGLibDeviceScanEventFunc)
|
cb1 = FuncType1(HGLibDeviceScanEventFunc)
|
||||||
FuncType2 = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p)
|
FuncType2 = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p)
|
||||||
cb2 = FuncType2(HGLibDeviceScanImageFunc)
|
cb2 = FuncType2(HGLibDeviceScanImageFunc)
|
||||||
|
|
Loading…
Reference in New Issue