pythontcpzkteco

Retrieve data from ACP-260 door panel


I have a ACP-260 (2 door panel) working, and I was previously managing said device with ZKAccess 3.5, however, because of various errors I'd like to design my own Python script to properly retrieve data from this device. I was investigating and found ZkTeco's pullSDK which shows code to implement a connection to the device in Python, however, this solution did not work for me, since it doesn't seem to retrieve any of the logs. Here is my take on this SDK:

import time
import threading
from ctypes import windll, create_string_buffer

plcommpro_dll_path = "E:/pyTCP/deps/plcommpro.dll"

class DeviceController:
    def __init__(self, ip, port=4370, timeout=4000, passwd=""):
        self.ip = ip
        self.port = port
        self.timeout = timeout
        self.passwd = passwd
        self.hcommpro = None
        self.commpro = windll.LoadLibrary(plcommpro_dll_path)
        self.is_running = False
        self.log_thread = None

    def connect(self):
        params = f"protocol=TCP,ipaddress={self.ip},port={self.port},timeout={self.timeout},passwd={self.passwd}"
        constr = create_string_buffer(params.encode())
        self.hcommpro = self.commpro.Connect(constr)
        return self.hcommpro

    def disconnect(self):
        if self.hcommpro:
            self.commpro.Disconnect(self.hcommpro)
            self.hcommpro = None

    def get_real_time_logs(self, buffer_size=256):
        rt_log = create_string_buffer(buffer_size)
        ret = self.commpro.GetRTLog(self.hcommpro, rt_log, buffer_size)
        return rt_log.value.decode()

    def retrieve_logs_continuously(self, interval=60):
        while self.is_running:
            rt_logs = self.get_real_time_logs()
            print(rt_logs)  
            time.sleep(interval)

    def start_logging(self, interval=60):
        if not self.is_running:
            self.is_running = True
            self.log_thread = threading.Thread(target=self.retrieve_logs_continuously, args=(interval,))
            self.log_thread.start()

    def stop_logging(self):
        if self.is_running:
            self.is_running = False
            self.log_thread.join()

if __name__ == "__main__":
    device = DeviceController(ip="10.0.0.240")

    device.connect()

    device.start_logging(interval=600)

    try:
        while True:
            time.sleep(1)  

    except KeyboardInterrupt:
        device.stop_logging()
        device.disconnect()

The data I would like to retrive is the real time logs created everytime someone enters through either door 1 or door 2. These logs show you the time, user, method of entrance (fingerprint or card) and other information about each individual use of the door, including failed attempts.

My Python script did not successfully retrieve said logs.

If anyone has experience working with these devices, I'd like to know if there is a specific way to connect to them without the use of ZKAccess 3.5.

I've also read a bit about a python library called pyzkaccess but it only seems to work with certain panels, and the one I have (ACP-260) is not included, so this solution is not possible for me.


Solution

  • You need to use pullsdk. That's what ZKAccess is using. There is no documentation, you have to guess.

    You can either use events, or you can read the transactions table periodically.

    I had to do a simular job, here is my code, it's in C#: https://github.com/MuaazH/ZKTeco_PULLSDK_Wrapper