Dec 11, 2010

LabVIEW Style Checklist - Part 1: Front Panel

LabVIEW風格檢查清單

養成良好的編寫風格,對於程式的維護與擴充性有極大的幫助
相較之後減少的負擔,一開始花些時間做乍看似乎不重要的事,如把控件排列整齊,這樣的代價其實是值得的

以下為我翻譯自NI網站的內容,並加入自己的補充,並非全文翻譯
Front Panel checklist
o         Give controls meaningful labels and captions.
control控件件有意義的labelcaption
-label
是物件的名稱(可以與其他控件一樣名字,但是不建議這樣做),要能夠明白指出這控件的功能function,能短則短,但不要失去完整意義
-caption
以作為控件的敘述,可以長敘述,最好寫上預設值或是單位資訊,像是 high limit temperature (75 degF)
-
可以的話,最好是為控件編寫Context Help敘述,讓滑鼠移至此,可以了解其操作

o         Set controls with reasonable default values.
給予控件預設值
-
避免因為沒有輸入造成錯誤
-
但對於indicator像是graph, array, string給予預設值則是盡量避免,因為會佔用記憶體
-
甚至控件定義好range範圍,以避免使用者輸入錯誤超出預期

o         Ensure the background of control and indicator labels are transparent.
控件與顯示件的label為透明,非必要特別去著色

o         Check for consistent placement of control labels.
控件的label請放在適當位置,不要與其他重疊或是遠離輸入位置

o         Use standard, consistent fonts –application, system, and dialog—throughout all front panels.
整個版面使用一致的字體樣式
-
限制只用三種字體樣式(application, system, dialog),除非特殊理由才用不一樣的樣式

o         Use “Size to Text” for all text for portability and add carriage returns if necessary.
為了可攜性,對所有text設定成”Size to Text”,需要的話加上歸位(carriage returns)-這主要是針對不同平台的顯示差異問題, 一般LabView都已預設Size to Text,對於字體樣式較大的text,最好給予空格,以避免顯示時發生疊合干擾
-carriage return
是把cursor移到下一行的最前頭,Labviewcode display而言為”\r”,這種string需求會發生在與硬體或是檔案I/O

o         Allow extra space between controls to prevent labels from overlapping objects because of font changes on multiple platforms.
控件之間要有額外的空間,以避免label與控件疊合,因為不同平台會有樣式顯示改變的問題

o         Use path controls instead of string controls to specify the location of files or directories.
使用path control而非string控件來指定檔案或資料夾的位置
-labview
path control有對不同作業系統設計做調整,避免分隔符號不同的問題(Ex: MS:”\” Linux: “/” )
-path control
可以設定瀏覽選項(Browse option):限定讀取檔案或資料夾

o         Configure numeric inputs with data ranges.
數字輸入的control給定資料範圍最大,最小,增加量(increment)
-
按右鍵在Data Entry中設定
-
避免使用者給了程式不能接受的數值
-increment
的設定是當按control旁邊的上下按鈕,會上下變化的步值

o         Write descriptions and create tip strips for controls and indicators, including array, cluster, and refnum elements.
controlindicator給予適當描述與提示,包含陣列,,參考件(Refnum)
-description
可以點兩下直接寫在附近位置
-tip
則是按右鍵”Description and Tips”編寫,當滑鼠移至此,就會顯示

o         Arrange controls logically.
適當地排列control
-
保持頁面的簡潔,不要造成使用者的混亂
-
把最重要的control放在顯眼的地方
-
對於subVI,其控件排列要與接線icon排列方式一樣,左邊為輸入,右邊為輸出

o         Group and arrange controls attractively.
群組控件與排列控件,引導使用者的注意力
-
使用”Align Objects””Distribute Objects”將控件排列一致
-
使用裝飾件(decorations)Raised BoxHorizontal Smooth Box,來把相關功能的控件群組在一起
-
善用toolbar”Reorder”中的”Group”功能來群組控件
-
不要為美觀而把控件組合成cluster

o         Do not overlap controls with other controls, with their label, digital display, or other objects unless you want to achieve a special effect. Overlapped controls are mush slower to draw and might flash.
不要把控件與控件,label,數位顯示,或其他物件疊合, 疊合會使畫面更新變慢

o         Use color logically, sparingly, and consistently, if at all.
顏色配置以適當與一致為原則
-
請使用最少的顏色,不要太多顏色造成雜亂
-
顏色有時會讓使用者忽略重要資訊,舉例來說,,,亮橘的背景會使紅色的危險警示變的不明顯
-
不要單純以顏色indicator(LED)來顯示裝置狀態,因為在顏色改變時,人多少會因為色盲而無法明顯察覺
-Graph
multiplot,line過多時,以顏色做區分並沒有多大意義,因為太雜亂,請搭配line style如虛線
-
背景使用淺灰,白或柔和顏色
-LabView
調色盤顯示上,第一排為淡灰色系,適合於背景與一般控件;第二排為亮色系,可以用於標識重要的控件
-
隨時確認顏色的一致性

o         Provide a stop button if necessary. Do not use the “Abort” button to stop a VI. Hide the “Abort” button.
front panel上放置”stop”停止按鈕來終止迴圈程序,請勿直接按工具列上的”Abort”按鈕
-Abort
是馬上停止VI的執行,不管程式運行到哪裡;stop的停止,在迴圈中則是完整流程執行完才停止
-
直接以”Abort”來終止程序,會造成硬體溝通上不可預期錯誤

o         Use ring controls and enumerated type controls where appropriate. If you are using a Boolean control for two options, consider using an enumerated type control instead to allow for future expansion of options.
盡可能使用ring control或是enum control。如果你是使用Boolean作為T/F的二元選項,請考慮使用enum來取代,對於之後的選項擴充性才有支援
-Ring control
對於人機介面上,需要可程式改變顯示選項項目上有很大幫助。你或許會想要用string control來取代boolean control來操作超過兩個以上的選項,而這樣的功能在ring當中可以很容易的增加選項內容
-Enum
VI執行中無法程式化改變選項內容,在執行一開始就要定義好。使用Enum,請使用”type define control”,將控件存成ctl,對於之後增加或移除選項有極佳擴充性
-Enum
另一個優勢是當其連接至Case Structure,Case上的顯示文字與Enum同步,對於理解與標示有很大幫助

o         Use type definitions for common controls, especially for enumerated type controls and data structures.
對於常用的control設定type define,特別是enum與複雜資料結構如cluster
-
control按右鍵àAdvancedàCustomize,將其設定type def.並存成ctl檔案

o         Label custom controls with the same name as the file. For example, Alarm Boolean. Ctl has the default name Alarm Boolean.
定義好的control,將其label與其ctl檔案名稱一致,例如Alarm Boolean.ctl這檔案內的控件labelAlarm Boolean

o         Make sure all the controls on the front panel are of the same type. For example, do not use both classic and modern controls on the same front panel.
確認前板的控件格式一致性,例如不要在同一個前板有的使用傳統格式有的用現代格式
-
一樣的control, modern type為後期新的labview採用的外觀,classic為早期labview所用的外觀

o         Use Property Nodes to give the user more feedback on the front panel and to make the VI easier to use.
使用”Property Node”來讓使用者與前板互動,VI更容易使用
-Property Nodes
可以操作如下
把重點放在主要最常用的控件上,key focus設為True
隱藏控件或是讓控件失效,當控件目前無用或是無關的時候
利用highlight控件來引導使用者,Blinking設為True
改變顏色來引起注意,特別是error
-
可以利用SubVI來改變主VI的前板,只要用control reference,將控件的refnum傳入SubVI,SubVI使用Property NodesInvoke Nodes讀取或寫入來操作主前板

o         Use imported graphics to enhance the front panel.
插入圖片來美化前板
-
可以插入圖片作為背景,Ring的圖形化控制選項,與部份控件或顯示件
-
使用圖片,請確認在不同作業系統下的差異
-
使用圖片的缺點是會使螢幕更新變慢,請勿將controlindicator至於圖片上,這樣才不會更新indicator時要重新畫圖。如果需要放置大型圖片為背景,可以將其拆成小部份,留空放置controlindicator

o         Set up key navigation and keyboard shortcuts for controls and indicators on the front panel.
為前板的控件與顯示件設置key navigation與鍵盤快速鍵
-
有些使用者喜歡使用鍵盤來操作,設置鍵盤快速鍵的確是有很大的便利性
-
請注意Key navigationàFocus的設定,Enter預設為OK按鈕的鍵,請勿設為熱鍵
-VI
執行時,控件預設為當按Tab鍵時會在control控件之間切換,其順序為EditàSet Tabbing order,請將順序由左至右,由上而下
-
”Cancel”按鈕,請設為其熱鍵
-
Property Node設定Key Focus,可以程式化引導使用者於特定控件上

o         Configure the front panel to fit on the screens of most users.
設定前板屬性以滿足大部份使用者的螢幕
-
一般使用與開法是高解析度螢幕,所以會習慣設計大的前板,而有些螢幕只有有限的解析度
-Icon
上右鍵”VI Properties”à”Window Appearance, Window Size, Window Run-Time Position”可以作設定

o         Create dialog boxes to help users input data.
設定對話框來幫助使用者輸入資料
-
用另一個VI,VI PropertiesàWindow Appearance設成”Dialog”,設好Tab順序, OK, Cancel按件與其熱鍵,作為主VI一開始執行讓使用者輸入參數設定

No comments:

Post a Comment