90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
|
import ctypes
|
||
|
import time
|
||
|
from ctypes import *
|
||
|
|
||
|
class HGLibSaveImageParam(Structure):
|
||
|
_fields_ = [ ("size", c_ulong),
|
||
|
("jpegQuality", c_ulong),
|
||
|
("tiffCompression", c_ulong),
|
||
|
("tiffJpegQuality", c_ulong),
|
||
|
("ocr", c_int)]
|
||
|
|
||
|
Objdll = ctypes.WinDLL("D:/sane/code_app/test/scannerlib/HWScannerLib.dll")
|
||
|
|
||
|
HGLib_LoadImage = Objdll.HGLib_LoadImage
|
||
|
HGLib_LoadImage.argtypes = [ctypes.c_char_p]
|
||
|
HGLib_LoadImage.restype = ctypes.c_void_p
|
||
|
Image = HGLib_LoadImage(c_char_p(b"d:/1.jpg"))
|
||
|
|
||
|
HGLib_SaveImage = Objdll.HGLib_SaveImage
|
||
|
HGLib_SaveImage.argtypes = [ctypes.c_void_p, ctypes.c_char_p, POINTER(HGLibSaveImageParam)]
|
||
|
HGLib_SaveImage.restype = ctypes.c_int
|
||
|
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"d:/2.jpg"), pointer(ImageParam))
|
||
|
|
||
|
HGLib_ReleaseImage = Objdll.HGLib_ReleaseImage
|
||
|
HGLib_ReleaseImage.argtypes = [ctypes.c_void_p]
|
||
|
HGLib_ReleaseImage.restype = ctypes.c_int
|
||
|
Ret = HGLib_ReleaseImage(Image)
|
||
|
|
||
|
|
||
|
def HGLibDeviceHotPlugEventFunc(event: c_ulong, deviceName: c_char_p, param: c_void_p):
|
||
|
print(deviceName)
|
||
|
return
|
||
|
|
||
|
FuncType = CFUNCTYPE(None, c_ulong, c_char_p, c_void_p)
|
||
|
cb = FuncType(HGLibDeviceHotPlugEventFunc)
|
||
|
HGLib_InitDevice = Objdll.HGLib_InitDevice
|
||
|
HGLib_InitDevice.argtypes = [FuncType, c_void_p]
|
||
|
HGLib_InitDevice.restype = ctypes.c_int
|
||
|
Ret = HGLib_InitDevice(cb, 0)
|
||
|
|
||
|
time.sleep(1)
|
||
|
|
||
|
HGLib_GetDeviceNameList = Objdll.HGLib_GetDeviceNameList
|
||
|
HGLib_GetDeviceNameList.argtypes = []
|
||
|
HGLib_GetDeviceNameList.restype = POINTER(ctypes.c_char_p)
|
||
|
DeviceNameList = HGLib_GetDeviceNameList()
|
||
|
|
||
|
HGLib_OpenDevice = Objdll.HGLib_OpenDevice
|
||
|
HGLib_OpenDevice.argtypes = [ctypes.c_char_p]
|
||
|
HGLib_OpenDevice.restype = ctypes.c_void_p
|
||
|
Device = HGLib_OpenDevice(DeviceNameList[0])
|
||
|
|
||
|
HGLib_SetDeviceParam = Objdll.HGLib_SetDeviceParam
|
||
|
HGLib_SetDeviceParam.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_void_p]
|
||
|
HGLib_SetDeviceParam.restype = ctypes.c_int
|
||
|
DevParam = ctypes.c_int(1)
|
||
|
Ret = HGLib_SetDeviceParam(Device, 1, byref(DevParam))
|
||
|
|
||
|
def HGLibDeviceScanEventFunc(device: c_void_p, event: c_ulong, err: c_int, info: c_char_p, param: c_void_p):
|
||
|
print(info)
|
||
|
return
|
||
|
|
||
|
def HGLibDeviceScanImageFunc(device: c_void_p, image: c_void_p, param: c_void_p):
|
||
|
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"d:/3.jpg"), pointer(ImageParam))
|
||
|
return
|
||
|
|
||
|
FuncType1 = CFUNCTYPE(None, c_void_p, c_ulong, c_int, c_char_p, c_void_p)
|
||
|
cb1 = FuncType1(HGLibDeviceScanEventFunc)
|
||
|
FuncType2 = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p)
|
||
|
cb2 = FuncType2(HGLibDeviceScanImageFunc)
|
||
|
HGLib_StartDeviceScan = Objdll.HGLib_StartDeviceScan
|
||
|
HGLib_StartDeviceScan.argtypes = [c_void_p, FuncType1, c_void_p, FuncType2, c_void_p]
|
||
|
HGLib_StartDeviceScan.restyped = ctypes.c_int
|
||
|
print("start scan")
|
||
|
Ret = HGLib_StartDeviceScan(Device, cb1, 0, cb2, 0)
|
||
|
|
||
|
time.sleep(10)
|