Python使用ZKteco SDK写访问冲突

Python Access Violation Writing using ZKteco SDK

我一直在尝试使用制造商 (ZKTECO) 提供的 SDK 向设备设置一些数据。某些功能(例如连接、断开连接、修改 IP 地址)可以正常工作,但是当我尝试将数据更新到内部 table 时,出现以下错误:exception: access violation writing 0x000000000205A040。根据我的研究,最常见的问题与设置正确的 argtypesrestypes 有关,我已将其应用到我的理解中。作为额外信息,我使用 python 3.7 以及 Windows 10 pro 64 位。

文档中的函数:

int SetDeviceData(HANDLE handle,const char *TableName, const char *Data, const char *Options)

int Connect(const char *Parameters)

Void Disconnect(HANDLE handle)

我目前拥有的代码:

import ctypes
from ctypes import cdll, windll, create_string_buffer, c_char_p, c_void_p
from ctypes.wintypes import HANDLE

zk = windll.LoadLibrary("C:/Windows/System32/plcommpro.dll")

zk.Connect.argtypes = [c_char_p]
zk.Connect.restype = HANDLE

zk.SetDeviceData.argtypes = (HANDLE, c_char_p, c_char_p, c_char_p)
zk.SetDeviceData.restypes = ctypes.c_int

zk.Disconnect.argtypes = [HANDLE]
zk.Disconnect.restypes = c_void_p


params = b"protocol=TCP,ipaddress=192.168.100.178,port=4370,timeout=2000,passwd="
params_buf = c_char_p(params)

handler = zk.Connect(params_buf)

string = "Handler is: {0}\n".format(handler)
print(string)


try:
    table = b"user"
    data = b"Pin=9999\tPassword=1793\tName=Test\tStartTime=20190522\tEndTime=2010523"
    options = b""

    table_buf = c_char_p(table)
    data_buf = c_char_p(data)

    ret = zk.SetDeviceData(handler, table_buf, data_buf, options)

    del table_buf
    del data_buf

    result = "Result: {0}".format(ret)
    print(result)

except Exception as e:
    print(e)

zk.Disconnect(handler)

回溯:

Traceback (most recent call last):
  File "tmpdll.py", line 35, in <module>
    ret = zk.SetDeviceData(handler, table, data, options)
OSError: exception: access violation writing 0x000000005EF65040

handle 在 python 3.7 上的生成方式似乎存在一些问题。

我测试了其他版本,似乎在 3.5 版本之后出现错误,低于该版本的任何版本似乎都可以正常工作。