我试图通过制造商提供的.dll和Ctypes使用Python与示波器进行通信。我是C的新手,所以我可能遗漏了一些明显的东西,但我似乎无法正确地调用更复杂的函数。你知道吗
我有权访问.dll文件和.h文件。你知道吗
typedef long ScHandle;
...
int ScOpenInstrument(int wire, char* address, ScHandle* rHndl);
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字节)
根据[Python 3.Docs]: ctypes - Calling functions(强调是我的):
似乎您使用了错误的调用约定(此错误还表示您正在运行32位Python)。要更正它,请使用:
此外,您还可以缩短地址初始化:
相关问题 更多 >
编程相关推荐