2014-10-29 105 views
1

我有以下問題:ctypes的UINT64轉換錯誤

我通過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 

例如此函數調用作品(返回值= 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. 
+0

你能再發表更多代碼?你如何打開DLL?看起來你並沒有使用'argtypes'。 – 101 2014-10-29 20:59:03

+0

在我的問題中增加了更多代碼 – Gora 2014-10-30 07:56:36

+0

TaskHandle是如何定義的? – 101 2014-10-30 09:44:59

回答

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

現在它的工作原理:D 我不得不將第一個argtype更改爲c_int,並且在該函數中將Rising Edge和Finite Samples的第4個和第5個值更改爲正確的值 Thx很多: D – Gora 2014-10-30 10:06:47

+0

嚴格地說,TaskHandle應該可能是一個結構,但如果它只是和int然後從不知道:) – 101 2014-10-30 11:07:02

+0

是啊,最初它被定義爲void * ,但通過調用DAQmxCreateTask它得到一個內存地址(我看到很長的一段時間) – Gora 2014-10-30 11:14:39