【发布时间】:2019-09-10 21:21:04
【问题描述】:
我正在尝试通过制造商和 Ctypes 提供的 .dll 使用 Python 与示波器进行通信。我是 C 的新手,所以我可能会遗漏一些明显的东西,但我似乎无法正确调用更复杂的函数。
我可以访问 .dll 文件和 .h 文件。
.h 文件摘录:
typedef long ScHandle;
...
int ScOpenInstrument(int wire, char* address, ScHandle* rHndl);
我的python代码:
import ctypes
lib = ctypes.WinDLL("ScAPI.dll")
# Define types
ScHandle = ctypes.c_long
# Define function argument types
lib.ScOpenInstrument.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ScHandle)]
lib.ScStart.argtypes = [ScHandle]
# Init library
ret = lib.ScInit()
# Open instrument
wire = ctypes.c_int(7)
addr = ctypes.c_char_p("91SB21329".encode("utf-8"))
handle = ScHandle(0)
ret = lib.ScOpenInstrument(wire, addr, ctypes.byref(handle))
该函数应该向示波器返回一个句柄,但我得到了错误:
ValueError:过程可能调用了太多参数(超过 12 个字节)
【问题讨论】: