Dec 21, 2010

LabVIEW Style Checklist -Part 3: VI

Organizing your VIs in directories and LLBs allows you to easily transfer VIs to another computer and other platforms.



VI checklist
o         Organize Vis in a hierarchical directory with easily accessible top-level VIs and subVIs in subdirectories.
以階層式的目錄來管理VI, 把最上層的主VI放在最前面可以容易看到的地方,subVI放在次目錄裡
資料夾中,VI在資料夾一進去就可以看到的地方,subVI在次目錄的資料夾中
目錄的階層數目不要太多層
把有關的subVI以及相關的模組放在同一個目錄下,Ex: instrument drivers, configuration utilities, file I/O….etc
o         If you will use the Vis as subVIs, create a .mnu file. Hide dependent subVIs. Arrange the palettes and name the menus logically.
對於會重用的VIsubVI,可以建立.mnu目錄檔,隱藏從屬的subVI,而目錄檔的排列以整齊有相關性排列為原則
—.mnu
目錄檔的建立: toolbar上的Tools>Advanced>Edit Palette Sets..,會出現分別出現FunctionsControls (Functions屬於block diagram,controls屬於Front Panel),按右鍵Insert,可以選擇插入VI或是資料夾,建議是資料夾,但事先要先把VI放在同一個資料夾, 編輯完成後”Save Changes”系統會自動建立目錄檔
從屬的subVI,也就是屬於目錄上VI的支援VI,並不會用來讓使用者放在程式框圖上,純粹只是支援VI,就隱藏起來(可以建一個子資料夾,其名稱的前方放一個底線”_”,這樣的資料夾並會不顯示在labview目錄上)
o         Avoid using absolute paths in VIs.
避免在VI中使用絕對路徑位置
絕對路徑位置,VI在不同電腦上操作時,可能會發生錯誤
如果要使用絕對路徑位置,請確認路徑是否存在,若不存在則從新建一個
o         Give VIs meaningful names without special characters, such as blackslash (\), slash (/), colon (:), and tilde (~).
請給VI有意義的名字,避免使用特殊符號如”\ , /, ; ,~”
不要給過長的名字,大部分的作業系統最長只能接受255個字元
避免在目前操作的所有VI階層下,有取同樣名字的VI出現,LabVIEW執行時,記憶體中只能把一個名字指向一個VI,不能同一個名字分配到不同VI
project來管理VI的話,不同project是可以有同樣名字的VI,這是因為採取了name space名稱空間來管理,但仍不建議這樣做
一次只開啟一個project,避免不同project發生有同樣名字的VI衝突困擾
o         Use standard extensions (.vi, .ctl) so the operating system can distinguish files.
副檔名請用vi, ctl,讓作業系統可以清楚分辨,知道這是屬於labview相關程式
—vi
是給程式用的; ctl則是給控件用的
o         Capitalize first letters of VI names.
VI
的名字第一個字請用大寫
o         Distinguish example VIs, top-level VIs, subVIs, controls, and global variables by saving them in subdirectories or separate libraries in the same directory or by giving them descriptive names, such as X Main.vi, X Example.vi, X Global.vi, and x TypeDef.ctl.
為區別不同的使用,如範例VI,VI,subVI,控件,global variables,可以將其存於子目錄中(子目錄名稱就是其功能名稱ex: Example, Top-level, SubVI, Global, Controls),或是在同一目錄下分開存成程式庫,亦或給予分別所屬的描述性名稱如 X Main.vi, X Example.vi, X Global.vi, X TypeDef.ctl.
o         Write a VI description, proofread it, and confirm that it displays correctly in the Context Help window.
給予VI適當的描述,並校對與確認在Context Help視窗上顯示無誤
icon上右鍵>Documentation> VI Description編寫與此VI簡要清楚的功能描述
大寫 ……
o         Create a meaningful icon for every VI.
請為VI建立有意義的圖示
—icon
圖示就是labview圖象化的表徵,設計的當,可以讓人一眼明白這vi的功能
—icon
的解析度是32x32
—LabVIE
的程式庫中有不少VI的圖示可供參考,如果不想特別設計以圖來做icon,用文字text也是可以,文字的大小最小不要低於8 points (基本上以14最明顯)
可以的話,請也編輯black and white icon (B&W),因為不是每個使用者都有彩色列印(可以直接在B&W,直接copy from “256 color”,看顏色的調配是否在B&W顯示得當)
圖示與主VI,使用統一的樣式,讓使用者可以清楚知道此subVI與主VI是有相關性
可以使用Icon Art Glossary來輔助建立icon
o         Keep the default 4x2x2x4 connector pane pattern to leave extra terminals for later development.
盡量使用4x2x2x4的接線模式,讓之後可以擴充
儘可能的選擇最多接線的模式
—5x3x3x5
亦是一個擴充性高的方案
o         Use a consistent connector pane layout across related VIs.
在相關的VI使用,使用一致的接線模式
使用一致的接線模式,可以讓wire不會有凸起,所以在一開始接線模式就要選擇最有可能最多的接頭模式
接線方式為左進又出,輸入都在左邊,輸出都在右邊
o         Avoid using connector panes with more than 16 terminals.
避免一個icon的接頭超過16個以上
太多接線,會讓畫面混亂複雜
當有太多數據要傳遞時,請改用cluster資料型態
o         Use Required, Recommended, and Optional settings on the connector pane.
為圖示icon的接口定義”Required, Recommended, Optional”
icon上顯示為Show connector, 為其設定的接口右鍵”This connector is”即可設定Required, Recommended, Optional(預設為Recommended)
—Required
input之用,使用者必須要有為其接線傳送進資料,否則程式則無法執行,Context Help視窗上可以看到這種屬性接口的敘述名稱為大寫
—Optional
input之用,通常是用於預設數值用,不太需要送值進去的接口用
o         Set the print options for the VI to display the output in the most useful format.
適當設定VIprint option,使其顯示以最有用的格式
icon
右鍵>VI properties>Print Option
o         Make test VIs that check error conditions, invalid values, and Cancel buttons. Save test VIs in a separate directory so you can reuse them.
建立測試VI,來檢查錯誤狀態,無效輸入值,取消按鈕,並把測試VI存在分開的目錄下以便之後使用
o         Make good use of reusable, testable subVIs.
盡可能的使用可重用,測試過的subVI
o         Use error in and error out clusters in all subVIs.
subVI
要有Error in/outcluster接口與處理
即便subVI不會發生錯誤(如單純數值處理),error in/out對於整個程式執行流程的控制有所幫助
error cluster的輸入,則建個case structure,當有錯誤送進來,subVI的程式碼並不執行,直接將error code送出去
o         If the VIs run on multiple platforms, create different versions of the VI that contain the Call Library Function node and the CIN for each platform.
如果VI會在多種平台上運行,請為包含Call Library FunctionCINVI建立各種版本
—Call Library Function
CIN是有平台專一性的,所以VI中含有呼叫文字code程式碼的,需要建立多種平台版本以免跨平台發生問題
—CIN
的文字程式碼是在特定平台下的編譯器所編譯的
o         Save the VI with the most important frame of multiframed structures—Case, Stacked Sequence, and Event structures—showing.
儲存VI,對於有多個框架的Structure架構(Case, Stacked Sequence, Event structure),請先秀出最重要的框架再儲存
讓最重要的frame,在一開啟時能清楚看到
o         Review the VI for efficiency, data copying, and accuracy, especially parts without data dependency.
重新檢視VI的效率,資料重複拷貝與精確度,特別是沒有資料相關性的部份
Tools>Profile>”Show Buffer Allocations”查看哪邊有發生數據重複複製的情況(有黑點在閃爍的地方),減少複製問題可以提昇程式效率
—LabVIEW
為了資料安全性,當判斷data有可能發生數據改變的地方(Array插入)就會先複製一份data再作處理
o         Load and test VIs on multiple platforms, making sure labels fit and window size and position are correct.
在不同平台上載入與測試VI,確認VI的樣式與視窗大小,位置正確
o         Avoid using VIs that are platform specific if the VIs need to run on multiple platforms.
VI需要運行在多種平台上時,避免使用只能用於特定平台的VI
o         Consider creating different versions of VIs that contain platform-specific VIs and functions.
考慮建立各種版本的VI, 其包含各個用於特定平台的VI與功能
o         Avoid putting too many VIs in one LLB because large LLBs take longer to save.
避免在LLB內放入太多VI,因為會讓LLB的載入與儲存花太久的時間
o         Select Tools>>LLB Manager to mark top-level VIs within an LLB.
Tools> LLB Manager為主VI特別標示
LLB Manager視窗上,選定好top-levelVI,右鍵勾選”Top-level”
o         Design the VI for maximum performance.
VI
的設計以最大效能為為原則
程式優化對於包含大量數據Array與及時反應的程式來說非常重要
如果While loop內的程式對於時間不是非常要求的話,加上Wait function,以避免拖累外圍的程式執行
以使用者介面的loop,如果沒有加上wait,會因為佔著處理時間而讓其他loop無法執行
Wait(ms)對於電腦運算有很大的幫助,一般來說50100msdelay就很夠用了,但還有其他的因素會造成dealy
Wait Until Next ms Multipleloop,可以精準控制時間
請使用Event Structure,因為這種架構不會佔處理時間來等待人機介面上的使用者觸發事件
如果可以的話,盡量不要在loop中放置”Build Array”,會造成一值呼叫labVIEW的記憶體管理功能來因應Array大小的動態變化。比較有效的方式是先建好初始Array然後用Replace Array Subset來取代。同樣地,對於string亦是如此,因為string就是字串的array
對於graphchart,避免使用autoscaling,因為會拖累速度
選取適當的資料型態來操作,避免使用佔用太多記憶體的資料,extension precision
只顯示必須的資料在front panel,太常更新資料是會拖累速度的,特別是graphchart顯示大量的資料

No comments:

Post a Comment