Upload
others
View
9
Download
5
Embed Size (px)
Citation preview
ni.com/training
美商國家儀器台北市敦化南路二段216號12樓
ni.com/training
儀表控制軟體與模擬
授課人: 林俊宏
國立陽明大學醫學工程博士
[email protected]#3704
ni.com/training
虛擬儀控軟體架構
測試及資料管理軟體NI TestStand , DIAdem
量測自動化服務軟體
LabVIEW圖形化開發
應用開發環境
SignalExpressVI Logger
Vision Builder AI
互動式工具
ni.com/training
What is LabVIEW?
• Laboratory Virtual Instrument Engineering Workbench
• 圖形化程式語言(G語言)
• LabVIEW的程式:VIs (Virtual Instruments)
• 易於資料擷取、分析、呈現 Acquire, Analyze and Present
• 最新版本:2010
• 支援多核心版本:8.5 or later
6
ni.com/training
VI:Front Panel
• 人機介面(使用者介面)• Control (Input)• Indicator (Output)
9
Control Indicator
ni.com/training
VI:Block Diagram
• 程式方塊圖(圖形化程式語言)• Terminal(接點)− Control & Indicator
• Constant(常數)• Node(節點)− SubVI(副程式)− Function(函數)− Structure(結構)
• Wire(接線)
10
controlindicator
ni.com/training
Project Explorer• 開發大型程式或專案• 管理多個VI及subVI,將LabVIEW
與non-LabVIEW檔案包在一起• Compile to EXE, DLL, Installer• Deploy to PDA, FPGA, RT
system
12
ni.com/training
Front Panel:Front Panel Toolbar & Controls Palette
13
View » Controls Palette或空白處按右鍵
控制面版
ni.com/training
Block Diagram:SubVI(副程式)• VI• 具有Front Panel與Block Diagram• Icon & Connector Pane• 內建 & 自創
• Express VI• 功能較強大的內建VI• 對話框
21
ni.com/training
更多資源
• ni.com• Knowledge Base: http://ni.com/kb• Forum: http://ni.com/taiwan/forum• Forum: http://www.labviewpro.net
• (02)2377-2222
23
ni.com/training
資料型別:Numeric & Boolean
• Numeric• Floating-Point• Integer• Complex
• Boolean• 開關型
− Switch (開關)
• 按鈕型− Switch (開關)− Latch (門鈴)
24
ni.com/training
練習1.4:Mechanical Action
• Try to learn Mechanical Action from the example in LabVIEW
• Switch/Latch• Pressed/Released
25
ni.com/training
練習-樓梯燈控制• 假設有兩層樓,樓上樓下分別有一個開關可控制樓
梯燈,請使用Switch When Pressed的型態來設計開關,要注意樓上樓下都要能同時控制喔!
26
ni.com/training
For Loop• i 從 0 開始,每一圈增加 1
• 總共執行N次(最後的 i =N-1)
• 亦可提供停止條件(或繼續條件)
• 通常知道迴圈執行次數,用For loop;未知迴圈執行次數(由其他條件來決定),用While loop
29
ni.com/training
Wait & Wait Until Next ms Multiple
等待時間
程式時間
100ms50ms
100ms50ms
100ms50ms
情況一
等待時間
程式時間
100ms120ms
100ms情況二
120ms100ms
120ms
等待時間
程式時間
100ms50ms
100ms50ms
100ms50ms
情況一
等待時間
程式時間
100ms120ms
100ms情況二
120ms100ms
120ms
ni.com/training
遞迴(Iterative)資料:Shift Register• 紀錄先前迴圈的資料• 在迴圈左/右邊框按右鍵,Add Shift Register• 可同時多個Shift Register
• 紀錄先前多次迴圈的資料(Shift Register上按Add Element)
38
3
50
8
ni.com/training
遞迴(Iterative)資料:Shift Register(cont.)
• 初始值
39
VI stops execution Run AgainRun Once
55
84
ni.com/training
繪製資料
• Waveform Chart(可記憶)• 通常資料為scalar(亦可為vector)• 每次新增加一個點• 常置於迴圈中• 可繪製一條或多條資料(Bundle)• Waveform Graph(不可記憶)• 資料必為vector• 每次重新繪製資料• 於迴圈中常配合Shift Register• 可繪製一條或多條資料(2D-array)• XY Graph(不可記憶)• 資料為陣列數對(Bundle of array)
41
ni.com/training
Waveform Chart
• 清除歷史資料• 按右鍵,Data Operations → Clear Chart
• 不同的更新模式• Data Operations → Update mode
42
ni.com/training
Chart Update Modes• Right-click the chart and select Advanced»Update Mode
from the shortcut menu• Strip chart is the default update mode• Scope chart and Sweep chart modes display plots
significantly faster than the strip chart mode
ni.com/training
練習1.9:比較各種Waveform
45
• 產生一條斜率為1的直線(0,0)~(10,10)• 用Waveform Chart做• 用Waveform Graph做• 用XY Graph做
ni.com/training
Case Structure• 面對不同的情況,要讓程式做不同的動作
• 一次只有一種可能(只能進入其中一個case)
• 不一定每個case都要使用輸入資料,但若有輸出,則必須為每個case定義各自的輸出
• “?”可接受的格式• Boolean, Integer, String, Enum
46
ni.com/training
• 使用者可以選擇「加」、「減」、「乘」或「除」
• 若發生「除以零」的情形,則答案顯示出「999」
• 設定使用者只能輸入整數,且第二個數只能為0~100的整數
練習1.10:計算機
47