2014-11-20 41 views
0

我試圖從IronPython中調用.NET函數(VS2012)從IronPython的調用函數的.Net [VS2012]

.NET功能:

public int GetData(uint numberOfSamples, float[] iBuffer, float[] qBuffer){..} 

IronPython的:

# Here's my code in IronPython 
numSamples = 1024 
from array import array 
iData = array('f') 
qData = array('f') 

GetData(numSamples, iData, qData) 

最後一行將拋出以下異常,(從本地窗口-VS2012)

enter image description here

我該如何解決這個問題?

+1

在IronPython中的浮點數相當於C#中的兩倍 - 也許這是問題。參考:http://research.microsoft.com/en-us/um/cambridge/projects/infernet/docs/calling%20infer.net%20from%20ironpython.aspx – NoChance 2014-11-20 17:07:09

+0

我也試過'array('d' )',但我得到同樣的錯誤。 – SanVEE 2014-11-20 17:08:52

回答

2

可以傳遞的floats數組(這是System.Single)這樣的:

iData = System.Array[System.Single]([1.0, 2.0, 3.0]) 
qData = System.Array[System.Single]([4.0, 5.0, 6.0]) 
GetData(numSamples, iData, qData) 

編輯:如果你想預分配數組,並沒有實際的Python內容,用途:

iData = System.Array.CreateInstance(System.Single, 1024) 
+0

謝謝帕維爾,這一個似乎工作,但我想定義一個數組的大小,而不是值,是否有可能? – SanVEE 2014-11-21 10:22:44

1

雖然我接受Pawals答案,我結束了使用這樣

iData = Array.CreateInstance(System.Single, 1024) 
qData = Array.CreateInstance(System.Single, 1024) 

我從這個article發現。

+1

我想我們是在同一時間研究:-) – 2014-11-21 15:08:09