【正文】
8.。表格顯示正弦波每 25 個(gè)采樣點(diǎn)的平均值。圖 34 Reduce Samples VI 的程序框圖6. 顯示前面板,運(yùn)行 VI。5. 利用連線工具,將 Sample Compression Express VI 的 Mean 輸出端連接到 Build Table Express VI 的 Signals 輸入端。4. 拖拉這些對(duì)象進(jìn)入 While Loop 區(qū)域,處于 Mean 連線終端的右邊。對(duì)角線拖拉光標(biāo),直到選擇矩形區(qū)包含 Build Table Express VI 和 Table 連線終端,如左圖所示。注意,Table 連線終端自動(dòng)連線到 Build Table Express VI。1. 在前面板,從 Text Indicators 選板中選擇 Express Table 顯示控件,并把它放置在前面板內(nèi)的波形圖的右邊。7. 點(diǎn)擊 STOP 停止運(yùn)行 VI。6. 點(diǎn)擊 Enable 開(kāi)關(guān),注意波形圖的變化。4. 保存此 VI。每隔 250 秒時(shí)間延遲,循環(huán)程序?qū)⒚扛羲姆种幻胫貜?fù)執(zhí)行一次。2.在 Time Delay(Seconds)文本框內(nèi)鍵入 完成下面的步驟,來(lái)控制 VI 的執(zhí)行速度。While Loop 執(zhí)行循環(huán)內(nèi)的函數(shù),直到用戶(hù)按 STOP 按鈕。5. 顯示前面板,運(yùn)行 VI。圖 33 放置環(huán)繞 Express VIs 的 While Loop注意,While Loop,如左圖所示,顯示有一個(gè) STOP 按鈕,與條件(Condition Terminal)相連線。3. 移動(dòng)光標(biāo)至程序框圖的左上角,在此放置 While Loop 邊框的左上角。注意 VI 運(yùn)行后就停止,且沒(méi)有 STOP 按鈕。為了在某條件滿(mǎn)足前 VI 可一直運(yùn)行,可在程序框圖中加入 While 循環(huán) (While Loop)。8.保存此 VI 程序。圖 32 Reduce Samples VI 的程序框圖7.顯示前面板。6. 排列程序框圖中的對(duì)象,如圖 32 所示。5. 利用連線工具,將 Sample Compression Express VI 的 Mean 輸出端連接到 Sine 控件終端。注意,您可以從程序框圖中創(chuàng)建控制件和顯示件。3. 右擊 Enable 輸入端,單擊 CreateControl 來(lái)創(chuàng)建 Enable 開(kāi)關(guān)控件。1. 右擊 Smaple Compression VI 的 Mean 輸出,單擊 CreateNumeric Indicator 來(lái)創(chuàng)建一個(gè)數(shù)字顯示件。您也可以在程序框圖中添加控制件和顯示件。9. 利用連線工具,將 Simulate Signal Express VI 的 Sine 輸出端連接到 Sample Compression Express VI 的 Signals 輸入端。7. 配置 Sample Compression Express VI,指定平均因子為25,來(lái)減少信號(hào)的樣本點(diǎn)數(shù)。注意,LabVIEW 使 Sample Compression Express VI 跟隨著光標(biāo)移動(dòng)。4. 熟悉該 Express VI 的描述后,點(diǎn)擊在左邊 Place on the block diagram 按鈕,來(lái)選擇該 Express VI。注意,該單詞的選擇反映出您需要 Express VI 壓縮還是減少信號(hào)采樣點(diǎn)。HowTo Help,打開(kāi) LabVIEW Help。調(diào)整信號(hào)完成下面的步驟,利用 LabVIEW Help,查找可以使信號(hào)采樣點(diǎn)減少的Express VI。注意,此時(shí) Context Help 窗口內(nèi)顯示出 Simulate Signal Express VI的配置。8. 關(guān)閉 Configure Simulate Signal 對(duì)話(huà)框。6. 配置 Simulate Signal Express VI,以產(chǎn)生一個(gè)頻率為 、振幅為2的正弦波。4. 選擇 Express VI 并將其放置到程序框圖內(nèi),出現(xiàn) Configure Simulate Signal 對(duì)話(huà)框。注意,Context Help 窗口中顯示每個(gè) Express VI 的功能的信息。您也可以按Show Context Help Window(如左圖所示),打開(kāi) Context Help 窗口。添加一個(gè)模擬信號(hào)的 Express VI完成下面的步驟,查找您想要使用的 Express VI,并將其添加到程序框圖中。點(diǎn)擊在 Functions 選板左上方的圖釘圖標(biāo),如左圖所示,則把該模板放置在屏幕上。注意 在 New 對(duì)話(huà)框的 Create new 列表內(nèi)單擊 Blank VI,或者從前面板或程序框圖的菜單欄中單擊 FileNew VI,都可以打開(kāi)一個(gè)空 VI。1. 在 LabVIEW 對(duì)話(huà)框,點(diǎn)擊 New 按鈕上的箭頭,從快捷菜單中單擊 Blank VI 或快捷鍵CtrlN,來(lái)打開(kāi)一個(gè)空 VI。圖 31 Reduce Samples VI 的前面板打開(kāi)一個(gè)空 VI如果沒(méi)有模板適合您需要實(shí)現(xiàn)的任務(wù),您可以從一個(gè)新 VI 開(kāi)始,添加Express VIs 來(lái)實(shí)現(xiàn)指定的任務(wù)。當(dāng)您完成練習(xí)時(shí),VI 程序的前面板如圖 31 所示。利用空模板創(chuàng)建新的 VI在下面的練習(xí)中,您將要打開(kāi)一個(gè)空的 VI,并在程序框圖中添加 Express VIs 和結(jié)構(gòu),來(lái)創(chuàng)建一個(gè)新的 VI 程序。然而,在某些情況下模板并不適用于您需要?jiǎng)?chuàng)建的VI程序。 Graph Indicator.2. Display the front panel.3. Run the VI three or four times and observe the waveform graph.Notice that Voltage appears in the waveform graph plot legend.4. Display the block diagram.5. Rightclick the DAQ Assistant Express VI and select Properties to rename thechannel.6. Rightclick Voltage in the Channel List listbox and select Rename to display the Rename a channel or channels dialog box.Tip You also can select the name of the channel and press the F2 key to access the Rename a channel or channels dialog box.7. In the New Name text box, enter First Voltage Reading, and click the OK button.8. Click the OK button to apply this configuration and return to the block diagram.9. Display the front panel and run the VI.Notice that First Voltage Reading appears in the waveform graph plot legend.10. Save this VI.Editing an NIDAQmx TaskYou can add a channel to the task so that you can pare two separate voltage readings. You also can customize the task to acquire the voltage readings continuously. Complete the following steps to add a new channel to the task and acquire data continuously.1. Display the block diagram and doubleclick the DAQ Assistant Express VI to add a new channel.2. Click the Add Step button, shown at left, to open the Add Channels To Task dialog box.3. Select any unused physical channel in the My Physical Channels listbox.4. Click the OK button to return to the DAQ Assistant.5. Rename the channel Second Voltage Reading.6. In the Task Timing tab, select the Acquire Continuously you set timing and triggering options in the DAQ Assistant, these options apply to all the channels in the Channel List.7. Click the OK button to apply this configuration and return to the block diagram.8. Place a While Loop around the DAQ Assistant Express VI and the graph indicator wired to the data output. The block diagram should appear similar to Figure 42.Figure 42. Block Diagram for the Read Voltage VIVisually Comparing Two Voltage ReadingsBecause you have two voltage readings displayed on a graph, you can customize the plots to distinguish between the two. Complete the following steps to customize the plot color on the waveform graph.1. On the front panel, expand the plot legend to include two plots.2. Run the VI.Notice two plots now appear in the graph and the plot legend automatically updates to include both plot names.3.Rightclick First Voltage Reading and select Color from the shortcut menu. Using the Color picker, select a color, such as yellow, so that the plot is easy to read. Change the plot color of Second Voltage Reading.4. Save this VI.Communicating with an InstrumentInstrument drivers simplify instrument control and reduce test program development time by eliminating the need to learn the programming protocol for each instrument. Use an instrument driver for instrument control when possible. National Instruments provides instrument drivers for a wide variety of instruments. Visit the NI Instrument Driver Network at If a driver is not available for your instrument, you can use the Instrument I/O Assistant Express VI to municate with your instrument. Complete the following exercises to municate with an instrument.Selecting an InstrumentBefore municating with an instrument, you must select the instrument with which you want to municate. Complete the following steps to select an instrument using the Instrument I/O Assistant Express VI.1. Make