Python 中的 SAAT-500 系列有源 RFID 使用 C 代码项目

SAAT-500 Series Active RFID in Python using C code PROJECT

我们正在构建一个使用有源 RFID 的项目,此 RFID 需要在 Python 上进行编码才能在 Raspberry PI3

上使用

SAAT RFID 已有 DLL 文件,RFIDAPI.lib 和 RFIDAPIEXPORT.h 以及各种 API 调用函数

例如我需要执行的基本代码

bool SAAT_TCPInit (void** pHandle,char *pHostName,int nsocketPort)
HANDLE hp; if(!SAAT_TCPInit(&hp,”192.168.0.238”,7086) ) 
{ 
    printf("reader initialization failed!\n"); return false; 
} 

如何将此代码转换为 Python 以进入 RFID?

未经测试,但说明了您需要做什么。我假设 Python 3,但 Python 2 是相似的。

#!python3
import ctypes

# import the DLL
dll = ctypes.CDLL('RFIDAPI')

# declare the argument and return value types
dll.SAAT_TCPInit.argtypes = ctypes.POINTER(ctypes.c_void_p),ctypes.c_char_p,ctypes.c_int)
dll.SAAT_TCPInit.restype = ctypes.c_bool

# For the output parameter, create an instance to be passed by reference.
hp = ctypes.c_void_p()
if not dll.SAAT_TCPInit(ctypes.byref(hp),b'192.168.0.238',7086):
    print('reader initialization failed!')

记下 IP 的字节字符串。在 Python 中,3 字节字符串是 c_char_p 的正确输入。