Labivew  中可以直接呼叫 .NET DLL ,iammic 沒想到原來 Labview 也可以 Build 成 DLL 讓 .NET

呼叫,下列 iammic 要示範一個簡單使用 VB.NET 呼叫 Labview DLL。

 

SETP 1.建立一個 Labivew Project。

SETP2.專案中建立一個 VI。

SETP3.寫一個簡單程式,下列是一個簡單的將輸入的數值 +1 然後輸出的程式。

程式畫面:

image

程式:

image

請參考 SUB VI 將 Numeric 連接到左邊 Input,Numeric2 連接到右邊的 Output,如下圖。

 image

SETP4.到 Project Explorer 中的 Build Specifications 中按右鍵點選

【New】->【Shared Library(DLL)】

image

SETP5.輸入你要儲存 Build 好的 DLL 所在目錄。

image

SETP6.選擇要Exported VIs 的 VI 點選圖中標記的箭頭按鈕。

image

SETP7.檢查輸入輸出參數無誤,可修改 Funtion Name 為自己想要的名稱,點選 【 OK】 按鈕。

image

SETP 8.直接點選 Build 按鈕進行 Buid。

SETP 9.寫一個簡單的 VB.NEt 調用程式。

程式畫面:

image

程式 :

Public Class Form1
    Declare Auto Function Cal Lib "SharedLib.dll" (ByVal val1 As Double) As Double
 
 
    Private Sub test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles test.Click
        Me.txtOutput.Text = Cal(Val(Me.txtInput.Text))
    End Sub
End Class

SETP 10.將 Labivew DLL 放置到 VB.NET 產生 .EXE 檔案目錄下。

 

 

最後執行程式,輸入你要的數值在 Input 欄位中,點選 【test】按鈕,Output 產生+ 1 數值。

image

 

 

註記:

如果 Build Vb.NET 程式發生 PInvokeStackImbalance  錯誤

可以參考 http://msdn.microsoft.com/zh-tw/library/0htdy0k3.aspx

在 Visual Studio Menu 中【偵錯】->【例外狀況】->【Managed Debugging Assistants】

中的 PInvokeStackImbalance 將擲回取消。

 

參考網站:

http://zone.ni.com/devzone/cda/epd/p/id/2737

arrow
arrow
    全站熱搜

    iammic 發表在 痞客邦 留言(0) 人氣()