2

I am working on a Python project that includes using Images taken by Fingerprint scanner and processing them. I am currently using ZKTeco ZK8500(ZK9500) that is provided with C SDK library. But i have very little knowledge in C/C++ and to be honest Python is not my strongest language. I am trying to use C SDK via ctypes library in Python but i have some difficulties with that. I am currently testing on Windows, installed SDK from official site. So far my code looks like:

import ctypes
from ctypes import *
import logging

logging.basicConfig(filename='app_fp.log',
                    filemode='a',
                    format='%(asctime)s - %(levelname)s - %(message)s',
                    datefmt='%d-%m-%Y %H:%M:%S',
                    level=logging.INFO)

lib_3 = CDLL('libzkfp.dll')
###############################
lib_3.ZKFPM_Init.restype = ctypes.c_int

lib_3.ZKFPM_Terminate.restype = ctypes.c_int

lib_3.ZKFPM_GetDeviceCount.restype = ctypes.c_int

lib_3.ZKFPM_OpenDevice.restype = ctypes.c_void_p
lib_3.ZKFPM_OpenDevice.argtypes = [ctypes.c_int]

lib_3.ZKFPM_CloseDevice.restype = ctypes.c_int
lib_3.ZKFPM_CloseDevice.argtypes = [ctypes.c_void_p]

lib_3.ZKFPM_GetParameters.restype = ctypes.c_int
lib_3.ZKFPM_GetParameters.argtypes = [ctypes.c_void_p,
                                      ctypes.c_int,
                                      ctypes.POINTER(ctypes.c_ubyte),
                                      ctypes.POINTER(ctypes.c_uint),
                                      ]

paramChar = c_ubyte()
paramInt = c_uint()
################################

res_init = lib_3.ZKFPM_Init()
print("Init:", res_init)

res_getDeviceCount = lib_3.ZKFPM_GetDeviceCount()
print("Dev count:", res_getDeviceCount, type(res_getDeviceCount))

dev0_handle = lib_3.ZKFPM_OpenDevice(0)
print("Dev HANDLE:", dev0_handle)

dev0_getParam = lib_3.ZKFPM_GetParameters(dev0_handle,
                                          1102,
                                          byref(paramChar),
                                          byref(paramInt))
print("Get dev name:", dev0_getParam, paramChar, sizeof(paramChar))

logging.info("DeviceHandle:" + str(dev0_handle))


res_close = lib_3.ZKFPM_CloseDevice(dev0_handle)
print("Close dev:", dev0_handle, res_close)
#
res_terminate = lib_3.ZKFPM_Terminate()
print("Terminate:", res_terminate)

Stdout looks like this:

Init: 0
Dev count: 2 <class 'int'>
Dev HANDLE: 2682398313632
Get dev name: -3 c_ubyte(0) 1
Close dev: 2682398313632 0
Terminate: 0
Check sum data is true!sum=9286, buf[val]=9286
Check sum data is true!sum=-44, buf[val]=-44
opts->Stripe_Reference_Point_X=654, opts->Stripe_Reference_Point_Y=542
Check sum data is true!sum=908, buf[val]=908
CMOS Sensor->Exposure:256, RedGain:152, GreenGain1:200, GreenGain2:187,BlueGain:112.
Main1LED:200, Main2LED:200, Side1LED:175, Side2LED:175, Anti1LED:200, Anti2LED:200.
start to set the exposure parameters

Process finished with exit code 0

Description of GetParameters function from SDK is:

5.2.7 ZKFPM_GetParameters
[Function]
int APICALL ZKFPM_GetParameters(HANDLE hDevice, int nParamCode, unsigned
char* paramValue, unsigned int* cbParamValue);
[Purpose]
This function is used to acquire fingerprint reader parameters.
[Parameter Description]
hDevice
Device operation instance handle
nParamCode
Parameter code (For details, see the parameter code list.)
paramValue [out]
Returned parameter value
cbParamValue [in/out]
[in] Memory size allocated based on nParamCode
[out]Data size of the returned parameter value
[Return Value] 
 0 Succeeded
Others Failed (See the Appendixes.)

Questions:

  1. I do not understand why i can OpenDevice, can CloseDevice but get Get dev name: -3 c_ubyte(0) 1 when i try to get parameter i get -3- No device connected. Maybe something in my Python declaration or variable types?
  2. How i can get image to file from fingerprint scanner? Code snippets if anybody knows?
Vertigo
  • 21
  • 2
  • Can anybody help me please? What am i doing wrong? – Vertigo Jul 08 '22 at 08:25
  • It's a really complicated process, you have to connect, init the database, aquire three times, then zip the result into one so you can get the final template that other devices can use. This is a wrapper in C# https://github.com/MuaazH/ZKTeco_PULLSDK_Wrapper/blob/main/PullSDK_core/FingerReader.cs. Sorry I'm never used python. – MuaazH Jul 26 '22 at 10:06

0 Answers0