ctypes uint64转换错误

时间:2014-10-29 10:09:53

标签: python ctypes uint64 nidaqmx

我遇到了以下问题:

我通过c类型加载nicaiu.dll来控制NI-USB6218数据采集板,我必须调用几个函数来初始化它(DAQmxCreateTask(), DAQmxCreateAIVoltageChan() and 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,请参阅Doc 这是我的函数调用:

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),但它没有用。

EDIT1: 该DLL位于System32文件夹(Win7)

dll = cdll.nicaiu

例如,此函数调用有效(returnvalue = 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)

EDIT2:

添加了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 个答案:

答案 0 :(得分:0)

我无法测试它,因为我没有该乐器,但我会从以下内容开始:

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))