cancel
Showing results for 
Search instead for 
Did you mean: 
Knowledge Base

Example Code

Top Contributors
Sort by:
Overview This example demonstrates how configure the Time Synchronization Service without installed DSC or Lookout module.   Description In order to keep data properly time stamped in Lookout and LabVIEW DSC you need to ensure the clocks on the computers are synchronized. The NI Time Synchronization (lktsrv.exe) offers the ability to do that. NI Time Synchronization allows a computer to keep its time synchronized with a master time server, or to act as a time server for other machines. You can configurate the NI Time Synchronization in the LabVIEW Development Environment, if you select Tools > Options and select the Shared Variable Engine category. This Example shows how to configure the NI Time Synchronization Server on the remote client computer that doesn't have the LabVIEW or DSC Development Enivronment Installed.   Requirements  Software LabVIEW Base Development System 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached VI Run the program   Additional Information or References       How Do I Synchronize Time Settings on Networked Computers when using Lookout or LabVIEW Datalogging and Supervisory Control Module?   How Can the NI Time Synchronization be Configured Without Lookout or the LabVIEW DSC Module?   **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to calculate the maximum value of an array on FPGA.   Description The FPGA array pallete does not have the Max and Min VI that the standard LabVIEW array pallete has. This example shows one possible implementation to calculate the maximum. The example indexs through the array and compares each value with the maximum found value. When it finds a new maximum it saves the value.   Requirements  Software LabVIEW Full Development System 2012 (or compatible) LabVIEW FPGA Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the [Main] ...VI inside the LabVIEW project and follow the instructions on the Front Panel   Additional Information or References     **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to save the whole front panel of a VI as a screenshot on disk.   Description Sometimes you want to save an image of the front panel, but you do not want to put it in a report and would rather keep it as a separate image file. This VI works as a great subVI to take the VI path you wire to it as well as an image path. You can save your image in JPEG, PNG or BMP file formats.   Requirements  Software LabVIEW Base Development System 2012 (or compatible) If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached VI Open the VI and follow the instructions on the Front Panel   Additional Information or References     If you want to copy the screenshot into the clipboard instead of saving it to disk, take a look into this example: Export A Screenshot Of A Graph/Chart/Front Panel To The Clipboard   **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to play an AVI video file with a user defined wait time between each frame.   Description If you want to replay an AVI video in LabVIEW, you need to control the frame rate of the video. The Vision Development Module (VDM) already provides the functions to open, read and close an AVI file. The frame rate has to be implemented with a wait time inside the loop which reads frame-by-frame from the AVI file.   Requirements  Software LabVIEW Base Development System 2012 (or compatible) NI Vision Development Module 2012 (or compatible) If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the VI and follow the instructions on the Front Panel   Additional Information or References     **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This VI demonstrates how you can interactively extract the color of a pixel from a 2D picture.   Description Have you ever wondered if you could find out the color of a specific pixel on an image? That's exactly what this example does. Run this VI and pick any JPEG image on your computer. An example image is already provided with the VI. Mouse over the picture control and find out the exact color your mouse is over and the coordinates your mouse is hovering over within the picture identifier.   Requirements  Software LabVIEW Base Development System 2012 (or compatible) If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the VI and follow the instructions on the Front Panel   Additional Information or References     **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to include VHDL code in LabVIEW FPGA with the HDL Interface Node.   Description This example demonstrates how to import the functionality of IP in a .vhd file into LV FPGA using the HDL node. It replicates a simple and function that is coded in VHDL and imported into LV using an HDL Node.   Requirements  Software LabVIEW Full Development System 2012 (or compatible) LabVIEW FPGA Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the VI and follow the instructions on the Front Panel   Additional Information or References       Note: Keep in mind that the HDL Interface Node was replaced with the IP Integration Node in LabVIEW 2010. The HDL Interface Node should only be used if you must use LabVIEW 2010 or earlier or if you already use it in an existing application.   **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to bit-pack multiple boolean values into one unsigned integer on FPGA   Description When acquiring a digital waveform in LabVIEW FPGA, the return type is a bool. DMA FIFO transfers from target to host are 32 bit width at the lowest level regardless of how the FIFO is configured (bool, U8, etc). So if you intend to do DMA FIFO transfer of a digital waveform from target to host, if you configure the DMA FIFO to be of type bool, the FIFO is then incredibly inefficient (1/32 efficiency). Additionally, when the bool gets to the host, the host stores bools in memory as a whole byte instead of just a bit (1/8 efficiency). By packing the digital reads into a U32 on the FPGA level before transferring them up to the host, you avoid the inefficiency of a DMA FIFO configured with the bool data type. You also avoid the inefficiency of storing bools in your host side memory as full bytes. Finally, because you are sending U32s up to the host from the FPGA instead of bools, the FIFO can be 1/32 as large. And the host side can read from the FIFO 1/32 as fast to prevent overflow. This example VI uses the rotate with carry and a U8 counter to accomplish this. Note the FIFO is configured with U32 data type.   Requirements  Software LabVIEW FullDevelopment System 2012 (or compatible) LabVIEW FPGA Module 2012 (or compatible) If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the [FPGA] Main.VI and follow the instructions on the Front Panel   Additional Information or References     This example uses a Single Cycle Timed Loop (SCTL) to acquire from the DIO line at 40MHz Onboard Clock speed. Replace the SCTL with a regular while loop if you don't need or can't acquire that fast. Use also a while loop if your IO are not supported within a SCTL.   **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This VI allows users to select a rectangular Region of Interest (ROI) and save that ROI to its own image file.  This would be useful if you would like to extract out a portion of your larger image and save it as its own image file.   Description This VI uses the IMAQ VI's to create a memory location for an image, open that image and then display it. The VI then uses the IMAQ Select Rectangle to open a prompt which allows the user to define a rectangular Region Of Interest (ROI). The IMAQ Extract VI creates a new image for the ROI which is then saved to file.   Requirements  Software LabVIEW Base Development System 2012 (or compatible) NI Vision Development Module 2012 (or compatible) If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the VI and follow the instructions on the Front Panel   Additional Information or References     **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to add the current date and time as overlay to an image.    Description It is sometimes useful to add the data and time of the aquisition or other information to an image. This can be done using the Vision Development Module. This examples add the date and time, but can also easily modified to display other information.   Requirements  Software LabVIEW Base Development System 2012 (or compatible) NI Vision Development Module 2012 (or compatible) If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Run the VI   Additional Information or References     **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to save the ROI (Region Of Interest) with an image and restore the ROI from the image later.    Description It is sometimes useful to store additional information in an image, which are not visible for the user. This can be archived with the custom data provided by the PNG file format. The custom data are non-visible if you open the PNG file for display. You can write the custom data with the IMAQ Write Custom Data VI or read it with IMAQ Read Custom Data VI. This VI demonstrates how to use both functions. It stores the information for a Region of Interest (ROI) inside the custom data and restores the data later. This concept is not limited to the ROI information and can be used to store every kind of information. Only the PNG file format provides the ability to store custom data. Conversion or editing the image can destroy the custom data.   Requirements  Software LabVIEW Base Development System 2012 (or compatible) NI Vision Development Module 2012 (or compatible) If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)  Hardware No hardware is necessary to use this example VI   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the VI and follow the instructions on the Front Panel   Additional Information or References     **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This example demonstrates how to use a Watchdog Timer to reboot a cRIO if the system became unresponsible.   Description This example program provides a solution for the problem shows in KnowledgeBase 4ROEMHXY: Why Won't My VxWorks Controller Reboot or Ping Itself? Using the watchdog timer vi's available under the Functions Palette»Real-Time»RT Watchdog we are able to cause the cRIO to reboot. This example has two loops. The top loop represents your Real-Time Code by making the User LED on the cRIO blink, this also allows you to visually see when the cRIO Reboots itself. (You can also use Console Out to see when the cRIO reboots). The Bottom Loop is the Watchdog Loop. While the Unresponsible Program button is un-pressed the watchdog is "wacked" each iteration of the loop. When the case structure becomes true, the watchdog timer times out after 1 second. When the watchdog times out it executes it's timeout actions, which in this case, is to reset the hardware. This setting can be seen on the "Expiration Actions".   Requirements  Software LabVIEW Full Development System 2012 (or compatible) LabVIEW Real-Time Module 2012 (or compatible)  Hardware compactRIO (cRIO)   Steps to Implement or Execute Code Download and open the attached ZIP-file Open the VI inside the LabVIEW project and follow the instructions on the Front Panel   Additional Information or References     **The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
View full article
Overview This is a very basic example on how you can load one template VI into two sub panels of the same front panel     Description For a modular and flexible coding sometimes you would like to create a VI template then call this template with a different configuration to perform different functionalities. This VI calls a VI template Simulate Signal.vit that can generate a sine or a cosine signal. Then using invoke nodes you pass the parameters to the VI by accessing its reference to determine its execution mode.   Requirements LabVIEW 2012 (or Compatible)       Steps to Implement or Execute Code 1. Download the folder "Load Multiple panels_LV2012_NI Verified" 2. Open the project and run the Main VI 3. Notice how in each panel you have a different signal being generated 4. Stop Execution in both SubPanels  5. Open the Simulate Signal.vit from the subVIs folder in the project explorer to check the template     Additional Information or References     **This document has been updated to meet the current required format for the NI Code Exchange.**    
View full article
Overview This VI demonstrates how to keep trying opening a file until it becomes available or you gain proper permission to open the file, or if a timeout occurs   Description This example shows one way to check a file to see if it is opened and wait until it is available to be opened.  It should also work with permissions and other file related activities.  This may not be always necessary, however, it can be while using ActiveX calls or abnormal file access.     Requirements LabVIEW 2012 (or compatible)     Steps to Implement or Execute Code 1. Download the folder "Wait to Open File_LV2012_NI Verified" 2. Open the VI "Wait To Open file_LV2012_NI Verified" 3. Enter the name of the file Test.txt; browse to the location where this VI is stored and right-click the properties of the Test.txt file to make sure the access mode for this document is set to read-only 4. Choose the operation mode: Open or create 5. Set the access mode to read/write 6. Set the time to wait to 30 seconds and above 7. Run the VI 8. While it is running, browse to the location of the file, right-click on it and open its properties, then uncheck read-only from attributes and click on apply. 9. If the VI stopped before you could perform step 6, increase the time to wait and repeat steps 5 and 6      Additional Information or References   **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article
Overview This VI is a simple example on how to plot data continuously on an XY Graph and make it behave as an XY chart with uncontrollable size.      Description This VI demonstrates how to use arrays to add data points to an array and then have XY plot update continuously with the values from the array. To use XY Chart with controllable history length, check XY Chart in Example Finder     Requirements LabVIEW 2012 (or compatible)     Steps to Implement or Execute Code Open and run the VI "XY Continuous Plot_LV2012_NI Verified"     Additional Information or References     **This document has been updated to meet the current required format for the NI Code Exchange.**  
View full article
Overview This VI will programmatically move a window to the front whether its a LabVIEW window or not.     Description This VI will programmatically move a window to the front whether its a LabVIEW window or not.  There are two Windows APIs that are used to achieve this.  The first one (FindWindow) acquires the handle of the window that you want to bring to the front.The name of the window is passed into the lpWindowName terminal and NULL is passed into the lpClassName terminal.  The second windows API is SetForegroundWindow. This moves the window corresponding to the passed handle to the front.     Requirements LabVIEW 2012 (or compatible)     Steps to Implement or Execute Code 1. Open the VI "Bring Window Forward_LV2012_NI Verified" 2. Choose the window name you want to bring to front 3. Run the VI 4. Stop Execution     Additional Information or References      **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article
Overview This example VI utilizes property nodes and shift registers to add the points one by one to the graph as the user inputs them with the option to draw a line between the points in the order as they were added as well clearing the graph data     Description This example VI utilizes property nodes and shift registers to add the points one by one as the user inputs them then they also have the option to draw a line between the points in the order as they were added and lastly they can clear the graph. Property nodes and shift registers are some of the most useful things you can learn in LabVIEW. You can tell by the screenshots how each case works. The add line function is just calling the Plot Interpolation property node that changes it from just points to a direct line.      Steps to Implement or Execute Code 1. Run the VI "XY Graph Add Point_LV2012_NI Verified" 2. Enter the point coordinates and press on Add 3. Enter another point and click on Add then click on Draw Line 4. Click on Clear Graph to clear all data in the graph 5. Stop execution     Additional Information or References Front Panel    Block Diagram       **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article
Overview  This VI initializes a communication with the keyboard and then monitors what buttons are pressed on the keyboard.      Description This example opens a reference with the keyboard and then monitor the keys pressed on the keyboard using the Acquire Input Data.vi available in the inputDevices.llb. Check Context Help for more information The indicator on the front panel then displays what buttons are being held down. it can detect when several buttons are being pressed at the same time.     Requirements LabVIEW 2012 (or compatible)     Steps to Implement or Execute Code 1. Open and run the VI "Monitor Keyboard Presses_LV2012_NI Verified" 2.. Press any button on the keyboard     Additional Information or References   **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article
Overview  This example shows you how you can programmatically update the indicator of your array index on your front panel.  This allows you to alter what values are visible in your array during run-time.      Description In this example the Index Values property node is used to update the value of the array index on the front panel to reflect the current element being updated in the array.  For this VI the value in the array are not being updated, only the index is as a proof of concept.     Requirements LabVIEW 2012 (or compatible)     Steps to Implement or Execute Code Open and run the VI "Update Array Index Value Programmatically_LV2012_NI Verified"     Additional Information or References       **This document has been updated to meet the current required format for the NI Code Exchange.**  
View full article
Overview This example VI shows how to perform a simple FFT and then an Inverse FFT on a waveform.      Description A fast Fourier transform (FFT) algorithm computes the Discrete Fourier Transform (DFT) of a sequence, or its inverse. Fourier Transsform converts a signal from its original domain (often time or space) to a representation in the frequency domain and vice versa. In this example you  Generate Sine wave, apply Hanning window on the sine wave to generate a signal pulse. Then you calculate the width of the FFT and add zeros to the data to reach the requested Bandwidth. After which, you apply FFT on the signal. Then you go back to the time domain by applying IFFT on the FFT result.     Requirements LabVIEW 2012 (or compatible)   Steps to Implement or Execute Code 1. Open the VI "Pulse FFT & IFFT_LV2012_NI Verified" 2. Modify the Multiplier and the number of Data points to configure the number of cycles and samples generated 3. Choose the FFT Frequency Range 4. Run the VI       Additional Information or References Block Diagram   Front Panel     **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article
  Overview This piece of example code show you how to write to a TDMS file using 3 single point data channels, and at the same time read back from the file all the way up to the last data point saved in the same TDMS file.     Description This example uses a multi loop architecture to perform these operations. The top loop saves the interleaved data to the TDMS file. While the bottom loop checks the number of samples in the file every 250mS and updates a slider to allow you to move through your recorded data. You supply the offset (or window size) of the data you want to view from the latest read position indicated by the slider. For this reason the minimum value of the slider is always the size of the offset. Once your offset number of points is written to the data file the slider maximum will increase with the file size. You can afterwards move the slider to move through the historical data.     Requirements LabVIEW 2012 (or compatible)       Steps to Complete 1. Download the attached zip folder "TDMS Simultaneous Read and Write_LV2012_NI Verified" . 2. Extract the files and open the project called "TDMS Write and Read.lvproj" 3. Open the "TDMS Write and Read.VI" from the project explorer window. 4. Run the VI 5. Modify the offset and Samples to be displayed in the graph (Samples displayed = Samples in File - Offset). Note that you must modify the value of the Samples in File Control in order to see the updates on the graph 6. Stop execution     Additional Information or References If you do not select a group name then you will receive error 4 (End of File) from the TDMS read VI after the first read event.   Block Diagram   Front Panel   **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article