OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Reading Digital PErsona HId 4500 Reader in python using C types

  • Thread starter Thread starter Edu Sistemas
  • Start date Start date
E

Edu Sistemas

Guest
im new into programming, im using a sample c# code from SDK Digital persona, in python.

I read SDK and didn't found the exact conversion, im excepting the Code to read the USB finger reader and register fingerprints to match person

The codes detects the usb reader, it turns on but the code doesn't, know how to interpret and return this error: dpfpdd_init result: 0 dpfpdd_query_devices (count) result: 96075789, device_count: 1 Press any key to continue . . .

This is the code:

Code:
import sys
import ctypes
from ctypes import *
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QPushButton, QListWidget
from PyQt5.QtGui import QImage, QPixmap

class FingerprintApp(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Fingerprint Scanner")
        self.setGeometry(100, 100, 600, 400)

        self.layout = QVBoxLayout()

        self.label = QLabel("Press the button to scan fingerprint", self)
        self.layout.addWidget(self.label)

        self.device_list_label = QLabel("No devices found", self)
        self.layout.addWidget(self.device_list_label)

        self.device_list = QListWidget(self)
        self.layout.addWidget(self.device_list)

        self.button = QPushButton("Scan Fingerprint", self)
        self.button.clicked.connect(self.scan_fingerprint)
        self.layout.addWidget(self.button)

        container = QWidget()
        container.setLayout(self.layout)
        self.setCentralWidget(container)

        self.device_handle = c_void_p()

    def scan_fingerprint(self):
        dll_path = "C:\\Program Files\\DigitalPersona\\U.are.U SDK\\Windows\\Lib\\x64\\dpfpdd.dll"

        try:
            dpfpddDll = ctypes.CDLL(dll_path)
        except OSError:
            self.label.setText(f"Library not found at {dll_path}")
            return

        if not self.init_dpfpdd(dpfpddDll):
            return

        self.query_device(dpfpddDll)

    def init_dpfpdd(self, dpfpddDll):
        dpfpdd_init = dpfpddDll.dpfpdd_init
        dpfpdd_init.argtypes = []
        dpfpdd_init.restype = c_int
        result = dpfpdd_init()
        print(f"dpfpdd_init result: {result}")

        if result != 0:
            self.label.setText("Initialization failed")
            return False
        return True

    def query_device(self, dpfpddDll):
        class DPFPDD_DEV_INFO(Structure):
            _fields_ = [
                ("size", c_uint),
                ("name", c_char * 32),
                ("modality", c_uint),
                ("technology", c_uint),
                ("version", c_uint),
                ("serial_num", c_char * 32),
                ("prv", c_void_p),
            ]

        dpfpdd_query_devices = dpfpddDll.dpfpdd_query_devices
        dpfpdd_query_devices.argtypes = [POINTER(c_uint), POINTER(POINTER(DPFPDD_DEV_INFO))]
        dpfpdd_query_devices.restype = c_int

        device_count = c_uint(0)
        device_info_buffer = POINTER(DPFPDD_DEV_INFO)()

        result = dpfpdd_query_devices(byref(device_count), byref(device_info_buffer))
        print(f"dpfpdd_query_devices (count) result: {result}, device_count: {device_count.value}")

        if result != 0 or device_count.value == 0:
            self.device_list_label.setText("No devices found")
            return

        self.device_list_label.setText(f"Devices found: {device_count.value}")
        for i in range(device_count.value):
            device_info = device_info_buffer[i]
            device_name = device_info.name.decode('utf-8')
            self.device_list.addItem(device_name)
            self.device_list.currentItemChanged.connect(lambda: self.open_device(dpfpddDll, device_name.encode('ascii')))

    def open_device(self, dpfpddDll, device_name):
        dpfpdd_open = dpfpddDll.dpfpdd_open
        dpfpdd_open.argtypes = [c_char_p, POINTER(c_void_p)]
        dpfpdd_open.restype = c_int

        result = dpfpdd_open(device_name, byref(self.device_handle))
        print(f"dpfpdd_open result: {result}, device_handle: {self.device_handle}")

        if result != 0:
            self.label.setText(f"Failed to open device, error code: {result}")
            return

        self.capture_fingerprint(dpfpddDll)

    def capture_fingerprint(self, dpfpddDll):
        dpfpdd_capture = dpfpddDll.dpfpdd_capture
        dpfpdd_capture.argtypes = [c_void_p, c_uint, POINTER(c_ubyte), POINTER(c_uint)]
        dpfpdd_capture.restype = c_int

        timeout = 5000  # 5 seconds

        capture_size = c_uint(512 * 512)  # Adjust the buffer size
        capture_buffer = (c_ubyte * capture_size.value)()

        print(f"Before capture: device_handle={self.device_handle}, timeout={timeout}, capture_size={capture_size.value}")
        result = dpfpdd_capture(self.device_handle, timeout, capture_buffer, byref(capture_size))
        print(f"dpfpdd_capture result: {result}, capture_size: {capture_size.value}")

        if result != 0:
            self.label.setText(f"Failed to capture fingerprint, error code: {result}")
            return

        if capture_size.value == 0:
            self.label.setText("Capture buffer is empty")
            return

        image_data = bytes(capture_buffer[:capture_size.value])
        image = QImage(image_data, 512, 512, QImage.Format_Grayscale8)  # Adjust the image dimensions as needed
        pixmap = QPixmap.fromImage(image)
        self.image_label.setPixmap(pixmap)
        self.image_label.setScaledContents(True)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = FingerprintApp()
    window.show()
    sys.exit(app.exec_())
<p>im new into programming, im using a sample c# code from SDK Digital persona, in python.</p>
<p>I read SDK and didn't found the exact conversion, im excepting the Code to read the USB finger reader and register fingerprints to match person</p>
<p>The codes detects the usb reader, it turns on but the code doesn't, know how to interpret and return this error:
dpfpdd_init result: 0
dpfpdd_query_devices (count) result: 96075789, device_count: 1
Press any key to continue . . .</p>
<p>This is the code:</p>
<pre><code>import sys
import ctypes
from ctypes import *
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QPushButton, QListWidget
from PyQt5.QtGui import QImage, QPixmap

class FingerprintApp(QMainWindow):
def __init__(self):
super().__init__()

self.setWindowTitle("Fingerprint Scanner")
self.setGeometry(100, 100, 600, 400)

self.layout = QVBoxLayout()

self.label = QLabel("Press the button to scan fingerprint", self)
self.layout.addWidget(self.label)

self.device_list_label = QLabel("No devices found", self)
self.layout.addWidget(self.device_list_label)

self.device_list = QListWidget(self)
self.layout.addWidget(self.device_list)

self.button = QPushButton("Scan Fingerprint", self)
self.button.clicked.connect(self.scan_fingerprint)
self.layout.addWidget(self.button)

container = QWidget()
container.setLayout(self.layout)
self.setCentralWidget(container)

self.device_handle = c_void_p()

def scan_fingerprint(self):
dll_path = "C:\\Program Files\\DigitalPersona\\U.are.U SDK\\Windows\\Lib\\x64\\dpfpdd.dll"

try:
dpfpddDll = ctypes.CDLL(dll_path)
except OSError:
self.label.setText(f"Library not found at {dll_path}")
return

if not self.init_dpfpdd(dpfpddDll):
return

self.query_device(dpfpddDll)

def init_dpfpdd(self, dpfpddDll):
dpfpdd_init = dpfpddDll.dpfpdd_init
dpfpdd_init.argtypes = []
dpfpdd_init.restype = c_int
result = dpfpdd_init()
print(f"dpfpdd_init result: {result}")

if result != 0:
self.label.setText("Initialization failed")
return False
return True

def query_device(self, dpfpddDll):
class DPFPDD_DEV_INFO(Structure):
_fields_ = [
("size", c_uint),
("name", c_char * 32),
("modality", c_uint),
("technology", c_uint),
("version", c_uint),
("serial_num", c_char * 32),
("prv", c_void_p),
]

dpfpdd_query_devices = dpfpddDll.dpfpdd_query_devices
dpfpdd_query_devices.argtypes = [POINTER(c_uint), POINTER(POINTER(DPFPDD_DEV_INFO))]
dpfpdd_query_devices.restype = c_int

device_count = c_uint(0)
device_info_buffer = POINTER(DPFPDD_DEV_INFO)()

result = dpfpdd_query_devices(byref(device_count), byref(device_info_buffer))
print(f"dpfpdd_query_devices (count) result: {result}, device_count: {device_count.value}")

if result != 0 or device_count.value == 0:
self.device_list_label.setText("No devices found")
return

self.device_list_label.setText(f"Devices found: {device_count.value}")
for i in range(device_count.value):
device_info = device_info_buffer
device_name = device_info.name.decode('utf-8')
self.device_list.addItem(device_name)
self.device_list.currentItemChanged.connect(lambda: self.open_device(dpfpddDll, device_name.encode('ascii')))

def open_device(self, dpfpddDll, device_name):
dpfpdd_open = dpfpddDll.dpfpdd_open
dpfpdd_open.argtypes = [c_char_p, POINTER(c_void_p)]
dpfpdd_open.restype = c_int

result = dpfpdd_open(device_name, byref(self.device_handle))
print(f"dpfpdd_open result: {result}, device_handle: {self.device_handle}")

if result != 0:
self.label.setText(f"Failed to open device, error code: {result}")
return

self.capture_fingerprint(dpfpddDll)

def capture_fingerprint(self, dpfpddDll):
dpfpdd_capture = dpfpddDll.dpfpdd_capture
dpfpdd_capture.argtypes = [c_void_p, c_uint, POINTER(c_ubyte), POINTER(c_uint)]
dpfpdd_capture.restype = c_int

timeout = 5000 # 5 seconds

capture_size = c_uint(512 * 512) # Adjust the buffer size
capture_buffer = (c_ubyte * capture_size.value)()

print(f"Before capture: device_handle={self.device_handle}, timeout={timeout}, capture_size={capture_size.value}")
result = dpfpdd_capture(self.device_handle, timeout, capture_buffer, byref(capture_size))
print(f"dpfpdd_capture result: {result}, capture_size: {capture_size.value}")

if result != 0:
self.label.setText(f"Failed to capture fingerprint, error code: {result}")
return

if capture_size.value == 0:
self.label.setText("Capture buffer is empty")
return

image_data = bytes(capture_buffer[:capture_size.value])
image = QImage(image_data, 512, 512, QImage.Format_Grayscale8) # Adjust the image dimensions as needed
pixmap = QPixmap.fromImage(image)
self.image_label.setPixmap(pixmap)
self.image_label.setScaledContents(True)

if __name__ == "__main__":
app = QApplication(sys.argv)
window = FingerprintApp()
window.show()
sys.exit(app.exec_())

</code></pre>
 

Latest posts

Top