ctypes uint64 转换错误

1 投票
1 回答
2158 浏览
提问于 2025-04-30 08:58

我遇到了以下问题:

我通过 c types 加载了 nicaiu.dll,以控制一个 NI-USB6218 数据采集设备。我需要调用几个函数来初始化它,分别是 DAQmxCreateTask()DAQmxCreateAIVoltageChan()DAQmxCfgSampClkTiming()

前两个函数调用都能正常工作,但 DAQmxCfgSampClkTiming() 却出现了这个错误:

Traceback (most recent call last):
File "C:/*********/Voltage.py", line 68, in <module>
values)
ctypes.ArgumentError: argument 6: <type 'exceptions.TypeError'>: Don't know how to convert
parameter 6

参数 6 应该是 uint64 类型,具体可以查看这个 文档

这是我的函数调用:

DAQmx_Val_Rising = 10280 #see NIDAQmx.h
DAQmx_Val_FiniteSamps = 10178 # see NIDAQmx.h
values = uint64(40000) #numpy function
dll.DAQmxCfgSampClkTiming(taskHandle, "OnboardClock", c_float(4000.0), DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,
                                    values)  

我也尝试过 values = c_uint64(40000),但没有成功。

编辑1:

这个 dll 文件位于 System32 文件夹中(Win7)。

dll = cdll.nicaiu

例如,这个函数调用可以正常工作(返回值 = 0):

DAQmx_Val_Diff = 10106
DAQmx_Val_RSE = 10083
DAQmx_Val_Volts = 10348
returnvalue = dll.DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai1", taskName, DAQmx_Val_RSE,
                                           c_float(-1.0),c_float(1.0), DAQmx_Val_Volts, None)

编辑2:

我添加了 argtypes 行。

dll.DAQmxCfgSampClkTiming.argtypes = [c_int, c_char_p, c_float, c_int32, c_int32, c_uint64]
returnvalue = dll.DAQmxCfgSampClkTiming(taskHandle, None, c_float(4000.0), DAQmx_Val_Rising,
                                        DAQmx_Val_FiniteSamps,values)

但仍然出现错误代码 -200077,这个代码的定义是:

nierror code = -200077
Requested value is not a supported value for this property. The property value may be invalid
because it conflicts with another property.
暂无标签

1 个回答

2

我无法测试这个,因为我没有那个工具,但我会从类似下面的内容开始:

samp_clk_timing = dll.DAQmxCfgSampClkTiming
samp_clk_timing.restype = c_int32
samp_clk_timing.argtypes = (TaskHandle,
                            c_char_p,          
                            c_double,         
                            c_int32,
                            c_int32,           
                            c_uint64)

return_val = samp_clk_timing(taskHandle,
                             "OnboardClock",
                             c_double(4000),
                             c_int32(10106),
                             c_int32(10178),
                             c_uint64(40000))

撰写回答