Dec 14, 2010

LabVIEW Style Checklist -Part 2: Block Diagram

The block diagram is the primary way for others to understand how a VI works, so it is often worth effort to make block diagrams more organized and easier to read.

以下為個人筆記,非全文翻譯

o         Avoid creating extremely large block diagrams. Limit the scrolling necessary to see the entire block diagram to one direction.
避免產生版面過於巨大的程式框圖, 必要的話,最大限度是移動一個方向維度捲軸能看完的框圖大小
—block diagram
影響LabVIEW的閱讀性,最好版面大小不要超過螢幕
移動一個方向的捲軸為閱讀的極限,要又上下又左右的,非常難閱讀
儘可能用subVI來精簡版面(subVI不是為了重用性而是為了閱讀性與追蹤程式)
o         Label Call Library Function Nodes, Code Interface Nodes, and algorithms.
Call Library Function Nodes, Code Interface Nodes與演算法做詳細標示
程式開發者要有好的文件編寫,以增進程式的維護性與擴充,LabVIEW這樣圖形化介面,亦如此,且是撰寫在block diagram
—Call Library
CIN,秀出其label,即呼叫library的路徑
使用自由標籤(free label)描述block diagram裡使用的演算法與概念,甚至也可貼圖輔助說明
o         Use comments on the block diagram to explain what the code is doing.
在程式圖框上給予注釋,說明程式在做什麼功用
使用自由標籤,block diagram點兩下即可輸入
o         Avoid creating excessive wire patterns and colors if you change the wire appearance of a LabVIEW class wire.
使用class物件時,需要改變接線的話,避免過度改變接線樣式與顏色
block diagram內顏色與樣色的數目影響程式閱讀性,過於花俏並不適當
一般資料型態(ex: numeric, array, cluster..)並不允許使用者改變接線樣式
物件是允許使用者改變接線樣式,但不要與一般資料型態使用一樣的型態以避免誤解
o         Use the standard application font in free labels on all block diagrams.
在程式圖框內, 自由標籤使用統一且一致的標準應用字型(application font)
o         Use “Size to Text” for all text for portability and add carriage returns if necessary.
為了可攜性,對所有text設定成”Size to Text”,需要的話加上歸位(carriage returns)
a front panel style checklist已提到,為了操作平台顯示不同之因
o         Make sure data flows from left to right and wires enter from the left and exit to the right.
整個程式流向是由左至右; 接線是左進右出
雖然元件的位置並不是決定執行順序的依據,但請避免把接線從右拉往左
只有接線與架構決定資料流向
使用自由標籤(白色底,加上箭頭 ex: >data>)來為接線作標示,這對於shift register以及長接線很有幫助
避免過長的接線,特別是橫跨版面的長線
o         Align and distribute functions, terminals, and constants.
對元件,接線,參數值排列整齊,以對齊與等距為原則
圈選元件,點選toolbar上的”Align Objects””Distribute Objects”
o         Avoid placing block diagram objects, such as subVIs or structures, on the top of wires, and do not wire behind objects.
避免把元件(subVI,或架構-case, loop…)疊在接線上,也不要讓接線藏在元件後方
接線被隱藏,會造成閱讀與追蹤資料流動上的困擾
o         Use path constants instead of string constants to specify the location of files or directories.
使用path control而非string控件來指定檔案或資料夾的位置
o         Make sure the program can deal with error conditions and invalid values.
確認程式可以處理錯誤和無效輸入
輸入要定Range, subVIerror in/out, error handing機制……
o         Use sequence structures sparingly because they hide code. If flow-through parameters are not available and you must use a sequence structure in the VI, consider using a Flat Sequence structure.
盡量少用sequence structure,因為序列架構會隱藏程式碼
—sequence structure
內的程式碼無法展開成一眼看完,只有看到部份
o         Make sure the subVI icon, rather than the connector pane, is visible on the block diagram.
在程式框圖,subV的顯示模式用圖示icon,而非接口圖(connector pane)
subVIicon按右鍵選擇”Visible Item””Terminals”為未勾選
o         Use a type definition when you use the same unique control in more than one location or when you have a very large data structure passing between several subVIs.
使用type definition來設定control,尤其是當control不只被使用一次以及需要在各subVI之間傳送較大的資料結構的時候
control上右鍵”Advance”à”Customize” 為其設定Type Def.,並存成.ctl檔案
o         If you open references to a LabVIEW object, such as an application, control, or VI, close the references by using the Close Reference Function. It is good practice to close any reference you open programmatically.
當開啟了reference,一定要搭配使用close reference,這主要是開啟application, control, VI這樣的應用
Invoke node上有各種referenceopen/close設定
有開啟而無關閉會造成非預期的錯誤,所以要養成良好習慣
o         Make sure the Name Format for Property Nodes and Invoke Nodes is set to Short Names to ensure the best readability of the block diagram.
為了閱讀性考量,PropertyInvoke Nodes的名稱顯示(Name Format)請設定為”Short Name”
—Property Nodes, Invoke Nodes
右鍵選項”Name Format”勾選”Short Name”
o         Make sure control and indicator terminals on the connector pane are not inside structures on the block diagram.
盡量不要把controlindicator放在structure架構中
—control, indicator, constant
不要放在case structure,for loop, while loop
main VI中盡量避免此情形,會增大計憶體配置,subVI尤其不能
o         Avoid using local variables when you can use a wire to transfer data. Every local variable that reads the data makes a copy of the data. Use global and local variables as sparingly as possible.
可以用接線來傳數據就不要用local variables, 因為local variables會需要特別複製記憶體空間來使用,請儘可能少用localglobal variables
不是說local/global variables不可以使用,而是要少用以及謹慎使用;一但使用不當,如把Array的資料型態建成local/global,記憶體的使用會影響程式效率
—local/global vriables
要小心資料競爭(race condition)的情況發生,因為Labview預設是平行式的,variables會發生同時被其他程式讀取或寫入(請用wire確認好資料流向)
使用function global variables來取代global variables, Function Global Variables並不會產生多於空間配置而且允許初始化,讀取,寫入,清除等動作

No comments:

Post a Comment