using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using libzkfpcsharp;
using System;
using System.Threading;
namespace API.Controllers
{
[Route("api/")]
[ApiController]
public class HomeController : Controller
{
private class ZKTecoReader
{
public byte[] CapturedFingerprintData { get; private set; }
private IntPtr mDevHandle = IntPtr.Zero;
private IntPtr mDBHandle = IntPtr.Zero;
private byte[] FPBuffer;
private int mfpWidth = 256; // Replace with the actual width of the fingerprint image
private int mfpHeight = 288; // Replace with the actual height of the fingerprint image
private bool isCapturing = false;
public bool Initialize(out int errorCode)
{
int ret = zkfp2.Init();
errorCode = ret;
return ret == zkfperrdef.ZKFP_ERR_OK;
}
public bool OpenDevice(int deviceIndex)
{
mDevHandle = zkfp2.OpenDevice(deviceIndex);
return mDevHandle != IntPtr.Zero;
}
public bool InitDB()
{
mDBHandle = zkfp2.DBInit();
return mDBHandle != IntPtr.Zero;
}
public bool StartCapture()
{
FPBuffer = new byte[mfpWidth * mfpHeight];
isCapturing = true;
Thread captureThread = new Thread(DoCapture);
captureThread.IsBackground = true;
captureThread.Start();
return true;
}
public void StopCapture()
{
isCapturing = false;
}
private void DoCapture()
{
try
{
while (isCapturing && CapturedFingerprintData == null)
{
int cbCapTmp = 2048;
byte[] CapTmp = new byte[cbCapTmp];
int ret = zkfp2.AcquireFingerprint(mDevHandle, FPBuffer, CapTmp, ref cbCapTmp);
if (ret == zkfp.ZKFP_ERR_OK)
{
CapturedFingerprintData = CapTmp;
// Handle captured fingerprint data
// You can raise an event, store the data, or perform any desired operations.
}
Thread.Sleep(200);
}
}catch(Exception ex)
{
string x = ex.Message + ex.StackTrace;
}
}
// Add additional methods as needed for enrollment, verification, identification, etc.
public void CloseDevice()
{
StopCapture();
zkfp2.CloseDevice(mDevHandle);
zkfp2.DBFree(mDBHandle);
zkfp2.Terminate();
}
}
private ZKTecoReader reader = new ZKTecoReader();
[HttpGet("readfinger")]
public JsonResult ReadFingerPrint()
{
int errorCode;
bool initialized = reader.Initialize(out errorCode);
if (!initialized)
{
Console.WriteLine($"Failed to initialize the SDK. Error code: {errorCode}");
return Json($"Failed to initialize the SDK. Error code: {errorCode}");
}
bool deviceOpened = reader.OpenDevice(0);
if (!deviceOpened)
{
Console.WriteLine("Failed to open the device.");
return Json("Failed to open the device.");
}
bool dbInitialized = reader.InitDB();
if (!dbInitialized)
{
Console.WriteLine("Failed to initialize the fingerprint database.");
return Json("Failed to initialize the fingerprint database.");
}
bool captureStarted = reader.StartCapture();
if (!captureStarted)
{
Console.WriteLine("Failed to start capturing fingerprints.");
return Json("Failed to start capturing fingerprints.");
}
// Sleep for a while to capture the fingerprint
Thread.Sleep(5000);
// Access the captured fingerprint data
byte[] capturedFingerprintData = reader.CapturedFingerprintData;
string fingerprintData = Convert.ToBase64String(capturedFingerprintData);
reader.StopCapture();
reader.CloseDevice();
// You can now use the fingerprintData as needed
return Json(new { status = true, message = "Fingerprint captured successfully.", data = fingerprintData });
}
}
}
[code]using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using libzkfpcsharp; using System; using System.Threading;
namespace API.Controllers { [Route("api/")] [ApiController] public class HomeController : Controller { private class ZKTecoReader { public byte[] CapturedFingerprintData { get; private set; } private IntPtr mDevHandle = IntPtr.Zero; private IntPtr mDBHandle = IntPtr.Zero; private byte[] FPBuffer; private int mfpWidth = 256; // Replace with the actual width of the fingerprint image private int mfpHeight = 288; // Replace with the actual height of the fingerprint image private bool isCapturing = false;
public bool Initialize(out int errorCode) { int ret = zkfp2.Init(); errorCode = ret; return ret == zkfperrdef.ZKFP_ERR_OK; }
public bool StartCapture() { FPBuffer = new byte[mfpWidth * mfpHeight]; isCapturing = true; Thread captureThread = new Thread(DoCapture); captureThread.IsBackground = true; captureThread.Start(); return true; }
public void StopCapture() { isCapturing = false; }
private void DoCapture() { try { while (isCapturing && CapturedFingerprintData == null) { int cbCapTmp = 2048; byte[] CapTmp = new byte[cbCapTmp]; int ret = zkfp2.AcquireFingerprint(mDevHandle, FPBuffer, CapTmp, ref cbCapTmp); if (ret == zkfp.ZKFP_ERR_OK) { CapturedFingerprintData = CapTmp; // Handle captured fingerprint data // You can raise an event, store the data, or perform any desired operations. } Thread.Sleep(200); }
}catch(Exception ex) { string x = ex.Message + ex.StackTrace; }
}
// Add additional methods as needed for enrollment, verification, identification, etc.
public void CloseDevice() { StopCapture(); zkfp2.CloseDevice(mDevHandle); zkfp2.DBFree(mDBHandle); zkfp2.Terminate(); } }
private ZKTecoReader reader = new ZKTecoReader();
[HttpGet("readfinger")] public JsonResult ReadFingerPrint() { int errorCode; bool initialized = reader.Initialize(out errorCode); if (!initialized) { Console.WriteLine($"Failed to initialize the SDK. Error code: {errorCode}"); return Json($"Failed to initialize the SDK. Error code: {errorCode}"); }
bool deviceOpened = reader.OpenDevice(0); if (!deviceOpened) { Console.WriteLine("Failed to open the device."); return Json("Failed to open the device."); } bool dbInitialized = reader.InitDB(); if (!dbInitialized) { Console.WriteLine("Failed to initialize the fingerprint database."); return Json("Failed to initialize the fingerprint database."); } bool captureStarted = reader.StartCapture(); if (!captureStarted) { Console.WriteLine("Failed to start capturing fingerprints."); return Json("Failed to start capturing fingerprints."); } // Sleep for a while to capture the fingerprint Thread.Sleep(5000); // Access the captured fingerprint data byte[] capturedFingerprintData = reader.CapturedFingerprintData; string fingerprintData = Convert.ToBase64String(capturedFingerprintData);
reader.StopCapture(); reader.CloseDevice(); // You can now use the fingerprintData as needed
return Json(new { status = true, message = "Fingerprint captured successfully.", data = fingerprintData }); } } } [/code] В этой части возникла проблема:
[code] int ret = zkfp2.AcquireFingerprint(mDevHandle, FPBuffer, CapTmp, ref cbCapTmp); [/code]
ошибка:
System.AccessViolationException: 'Попытка прочитать или память, защищенная от записи. Часто это указывает на то, что другая память повреждена.
Я хочу сделать веб -сайт, на котором я хочу проверить пользователя по отпечаткам пальцев. Я хочу сохранить пользовательский отпечаток пальцев в базе данных, просто используя сканер отпечатков пальцев Mobile, я не хочу использовать какой -либо...
Я попытался интегрировать свое приложение Winform с системой учета посещаемости в реальном времени.
Я использовал класс zkemkeeper. подключенные устройства.
может читать другие данные. но не могу получить журнал в реальном времени.
private void...
Я попытался интегрировать свое приложение Winform с посещаемостью в реальном времени.
Я использовал класс Zkemkeeper. подключенные устройства.
может читать другие данные. но не может получить журнал в реальном времени.
private void...
Может ли кто -нибудь порекомендовать другие приложения для управления устройствами zkteco, помимо продуктов ZKTeco Softwares? Создайте пользовательское простое приложение для управления устройствами управления доступом ZKTECO и посещаемости времени....
Может ли кто -нибудь порекомендовать другие приложения для управления устройствами zkteco, помимо продуктов ZKTeco Softwares? Создайте пользовательское простое приложение для управления устройствами управления доступом ZKTECO и посещаемости времени....