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

Example Code

Top Contributors
Sort by:
An example of grabbing raw 8-bit Bayer data, saving to file & converting to RGB in real-time, based on NI's "Low Level Grab Raw Data.vi" example.
View full article
Using .NET it is possible to work backwards from a mapped drive to obtain the full UNC path to a network shared directory. This is useful when there is a network interruption and Windows hasn't refreshed its connection list. The VI currently only returns mapped drive information; however, by expanding the functionaltiy of the case structure within the code, it is possible to get detailed information about all drives currently attached to the machine.
View full article
Introduction This VI uses a 2D array of pixel values between 0 and 255.  The array is converted to an image and displayed.  It, also, checks the pixel value and compares it to a threshold specified by the user.  All pixel values below the threshold are set to 0 (black) and all values about the threshold are set to 255 (white).  The array is then converted to an image and displayed. Steps to Complete Enter values between 0 and 255 into the array.  Specify a threshold.  Run the VI. Additional Notes None.
View full article
This VI find outs Prime Numbers in the range of given from and to numbers. Give numbers in From and To controls and Run VI. This will find prime numbers and display in an array. Other requirements: No hardware Require.
View full article
   Game Category Winner Category: Games Summary: This example project aims to demonstrate the basics of inheritance in LVOOP.  The included classes model a 2 player board game on a common 8x8 board, the board used for Checkers and Chess, etc.  There are a number of games played with similar rules on a similar board, so inheriting the general methods of the Board Game to the specific cases of particular games seemed like a natural fit for OO inheritance. LVOOP has some catching up to do with traditional LabVIEW in terms of the quantity and diversity of examples available. Having more LVOOP examples should help bring new users into the OO-in-LV fold. For the example, I've chosen to implement one of my favorites: Othello. ( http://en.wikipedia.org/wiki/Reversi ). Othello is played with a set of pieces that are white on one side and black on the other.  Players take turns placing pieces on the board, any of the opponents pieces that form a line between the new piece and an existing current players' piece get flipped.  A player must make a move if any exist.  If you have no available moves, play passes back to the other player. The winner has the most pieces when neither player has legal moves. The example game gives players the option to select between 2-player Othello and 1-Player vs. a computer opponent.  The class hierarchy could conceivably be extended to make other games available.  I'll leave an implementation of Chess as an exercise for the reader . This code was written over the course of the last week and a half expressly for this contest. Function: The top level VI coordinates the public methods of "8x8 Board Game.lvclass".  Since Othello is a special case of an 8x8 Board Game class, an Othello class inherits from Board Game. A special case of Othello would be a 1-player vs. computer version, so the Othello-AI class inherits from Othello. When the program runs, an object of the Board Game class is written to a shift register in the main loop.  When the user selects a game, the object on the class wire is replaced with an object for the selected game. Methods in the parent class (Board Game) are mostly overridden, but only where necessary: "Forfeit" and "Next Player" take pretty much the same form in all games, so the general case is coded into the parent class and children can override it if necessary.   On the other hand, "Handle Move" has no meaning in the parent class, and is so dependent on a particular game's rules, that it is an empty method in the parent and must be overridden in child classes. I try to highlight a few features of LVOOP and LV2010 in the code: I make pretty extensive use of data member access through property nodes.  I find that when accessing multiple data members at once, the block diagram gets pretty messy and the property nodes (can) really help fight block diagram sprawl. Where possible, overriding methods call the parent method first, this prevents unnecessary duplication of existing code and speeds development. I make a few compromises from the full-on LVOOP implementation.  Clearly "Player" and "Turn" would make pretty good classes, and there are other possibilities as well.  I wanted to keep the number of classes to a minimum to focus the attention on the inheritance structure that the Game/Othello/Othello plus AI classes revolve around. This project is written in LV2010, due to use of new features for LVOOP in 2010 (esp. property node accessors). **Updated to add LV2009SP1 source code** Steps to execute code: To play the game: Download and unzip the project, and run "Main Example - Play a board game.vi" To inspect the classes: Open the project and select View->Labview Class Hierarchy from the menu bar. Right click on each class and select Properties.  Take a look at Inheritance especially. click on a Board Game member VI on the Main block diagram to open the VI: see how you get the option to also open override VIs of the child classes. check out how easy it is to extend a class by calling the parent method in the override VI: see New Game.vi in all three main classes. Screenshots: VI Snippet: A producer-consumer (events) architecture coordinates the game logic around the method calls. Project attached below
View full article
Overview LabVIEW FPGA VI and example showing how to generate pseudo random numbers using a linear feedback shift register algorithm.   Description The Pseudo Random Number Generator VI is built as an IP core for LV FPGA and can be used in a variety of applications. The VI is set to be reentrant so that it can be used multiple times in an application.The linear feedback shift register algorithm used to generate the pseudo random number is explained in detail in this Wikipedia article.     Requirements LabVIEW 2012 Full or Professional Development System LabVIEW 2012 FPGA Module   Steps to Implement or Execute Code To simulate this algorithm on a development computer: Open "Pseudo Random Generator 2012 NIVerified.vi " and run it to show random values populating on the chart. Open the "Pseudo Random Number Generator (FPGA) 2012" to examine how this is accomplished. To implement this on an FPGA target: Add the "Pseudo Random Number Generator (FPGA) 2012" and "Pseudo Random Generator 2012 NIVerified" VIs to your directory and/or project. Use the "Pseudo Random Generator 2012 NIVerified" as your FPGA VI, then compile and run this example interactively to notice the numbers populating     Additional Information or References   VI Snippet of Pseudo Random Generator 2012 NIVerified.vi   VI Snippet of Pseudo Random Number Generator (FPGA) 2012     **This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**
View full article
Overview This VI allows the user to dynamically update the duty cycle in order to change the position of the servo on the fly. Description This VI was created and tested on an NI M Series DAQ card for the purpose of controlling a servo motor that operates at a frequency of 50 Hz and varies its position relative to the duty cycle (or pulse width) of the signal. Requirements Software NI LabVIEW 8.5 or compatible NI DAQmx 8.6.1 or compatible Hardware Most DAQ cards with Counter I/O Steps to Implement or Execute Code 1. Select the desired counter output physical channel. 2. Set your initial frequency and duty cycle. 3. Run the VI. 4. Change the duty cycle and press the 'Update Duty Cycle' button to trigger update. Block Diagram Steps 1. The DAQmx Create Channel.vi to creates and configures the counter output frequency task to generate a pulse train of a user specified frequency and duty cycle.  2. The DAQmx Timing.vi to sets the mode to continuous and the timing to be implicit (i.e. does not require sample timing since it is a counter task for pulse train generation). 3. Start the task. 4. Enter the True case to update the duty cycle upon user selection.  The False case simply passes through the task and error wires. 5. Stop the task. 6. Dynamically reconfigure the duty cycle of the pulse train. 7. Restart the task. 8. Exit the while loop if an error occurs or upon user selection, and then clear the task and handle errors. **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article
Overview This example load multiple jpg images and display them sequentially using the LabVIEW picture control function. Description Read jpeg images (jpg) and shows it on a front panel. The old image get's overwritten by the next one using the same picture indicator. Requirements LabVIEW 8.6 "or compatible" Steps to Implement or Execute Code 1.) Download all the attachments including the example images into one single folder 2.) Open "Update Image.vi" 3.) Select the first image in the path input selector "Test Image1.jpg" 4.) Run the LabVIEW example Additional Information or References Vision Development Module is not required to run this example **This document has been updated to meet the current required format for the NI Code Exchange. For more details visit thisdiscussion thread**
View full article
This is the fine example that illustrates the Both the Modulation and Demodulation of Amplitude with a Modulating signal of 100KHz, both at the receiving end and transmitting end and a carrier at 21.4 MHz.This example has been tested and verified with Oscilloscope Also. Hello FriendsFirst Go through the example and understand the terminology and its representation. Like how the loop works and what are our requirements, are we meeting it. Also understand what is HOST and What is FPGA Target. Come up with the Errors, Errors are the only source that makes u perfect in LV.From rajeshg@icsgloabl.biz
View full article
The Main_Calculus.vi is a program that achieves the following things: plots the graph of the Polynomial Function and its 1th and 2th derivatives, computes and plots the local Minima, the local Maxima, the inflections points and more operations on a polynomial function. This example shows how to manipulate strings, how to manipulate arrays, how to use Run-Time menu, how to evaluate a function and some tips about of GUI design. DESCRIPTION The Main_Calculus.vi is aprogram that achieves the following things: - Plots the graph of one PolynomialFunction, within a given interval. - Plots the graph of the 1thand 2th Derivative of the Polynomial Function. - Computes and Plot, theintersection points with the x axis (the zeroes). - Computes and Plot, thelocal Minima of the Function. - Computes and Plot, thelocal Maxima of the Function. - Computes and Plot, theinflections points of the Function. - Computes and Plot, the intervalswhere the Function is increasing. - Computes and Plot, theintervals where the Function is decreasing. - Computes and Plot, theintervals where the Function is concave. - Computes and Plot, theintervals where the Function is convex. - Allows saving the graph in a .png image file, with the purpose of pasting or inserting in othersapplications, such as: Word, PowerPoint, Web Sites, etc. INSTRUCTIONS 1. Run Main_Calculus.vi 2. Enter the coefficients (A,B, C, D and E) of the Polynomial Function,and then enter the interval in which the Function will be drawn. Next press Enter Key or press the Aceptar Datos Button. 3. Look at the results in the Graph. But, before you must choose one option in the menu, which is located inthe left part of the Front Panel. This menu is a radio buttons control customized. 4. You can press the Ctrl X keys to abort the program. Note 1.- If you want to change the interval of the chart or if you want to change the coefficient ofthe Function. You must press the Ctrl F keys. Note 2.- If you want to savethe graphic results in a image file, you can press the Ctrl G Keys. Note 3.- You can press the Ctrl H keys to read about of the Author or about of the Institution. GUI
View full article
Introduction This VI is a small project I put together to monitor a web page, and notify the user when it has changed via multiple methods including pop up dialog, opening the page in the default browser, and sending a text message to a list of recipients.  I originally created it for buying concert tickets that were a very hot item.  The tickets sold out within 3 minutes, and I was one of the few people who got them. Steps to Complete The VI is pretty straightforward to understand.  Simply open and run the Web Site Notifier.vi.  If this is the first time using the VI you will get a pop up asking for the site URL and parameters to filter (See Filter Text (Variable) for information on this). Then the main window will open allowing you to set options such as the Refresh Rate, dialog timeout and Text message options. Open URL in Default Browser When the page in question changes, you will first see it pop up in the default browser.  This will allow you to make sure that it was the real update you were looking for and not a false alarm. Dialog At the same time as the browser opening, a dialog will pop up asking you if the URL is real or fake.  If you select fake, nothing will happen and the program will continue to check the page again.  If you select Real, it will send a text message to anyone on the announcement list.  If no response is select within the "Dialog Timeout" time limit, then the program will assume that it's real and you are too busy buying your tickets to care about a popup.  It will then automatically close and send the text message. Send Text Message If the change is real or the user hasn't selected an option within the Dialog Timeout limit, the program will automatically send a text message as configured in the Text message options. Mail Server must be a valid outgoing mail server. Return address can be any valid or invalid email address, but must be correctly formatted (username@server.com) 10 digit cell phone numbers must be in the format 5551234567 You must choose the correct cell phone provider, as the mailto address will be different for each.  To add an entry to the list, simply type in the next available array element. To remove from the list, type the name to delete and press the delete button. Kudos Thanks to CaptainKirby for his Mass SMS Message Example and A_Patel for his Woot Off Checker
View full article
Description This is just a simple implementation of a Two Way Stream API. You can use this to more easily implement communication with a remote system. It is based on Network Streams. This example code can also be used as a reference for you to learn how to encapsulate data into LabVIEW classes to create an API for any function. Steps to Implement or Execute Code Run the example in Tester.vi or the RT project on your cRIO. If you want you can put the remote loop on a cRIO or remote PXI. Requirements Software LabVIEW 2013 Network Streams installed on the remote system Hardware NA Additional Images or Video
View full article
Overview Connect to Motoman SDA10 Robot through TCP with the standard TCP Client caused a connection timed out. Description The VI is used to establish a connection to the Motoman Robot. VI was worked on by Students at Loughborough University in the Wolfson  Steps to Implement or Execute Code Run the VI attached Requirements Software LabVIEW Hardware Motoman Robot Additional Images or Video
View full article
Introduction This is an example of an XControl that can act as a simple replacement for the Error Out Cluster.  It has a Tri-state LED that is green if there is no error, yellow if there is a warning, or red if there is an error.  Note that it has functionality that you can right click on the LED and pull up the Explain Error window, just as you can with the Error Clusters. Steps to Complete Open Test.vi to see them in action. Additional Notes This was inspired by this LabVIEW Idea Exchange Suggestion.
View full article
This VI allows the user to configure up to 32 channels of digital data for combinatorial triggering. Applies "Mask Input" to "Trigger Input Line(s)" and returns the result as T or F for use as a custom digital trigger on FPGA based hardware. (cRIO, R Series)  Mask options include "And", and "Or" and like lines do not need to be adjacent.  "Trigger Line(s) Input" must be array of size = 32.  Right-click array and select "set dimensions" to adjust.  Lines not used can be masked out by selecting "Ignore" in the mask array. Change control: Added documentation and implemented single-cycle timed loops in subVI's for optimization.
View full article
Overview This VI allows you to trigger a pulse to be outputted after a set number of pulses from an incoming signal are counted. Description This VI uses the DAQmx drivers to accomplish this functionality. The main VI used is the CO Pulse Ticks VI, which can be configured in several ways to define the behavior of when and how to output a pulse. When using this VI, you select a digital signal as the input. This is the signal that the CO Pulse Ticks will count edges from to determine when to output a pulse. It can be the output of a counter, an encoder, or any other type of digital signal. To define the behavior of the output pulse, the CO Pulse Ticks VI has inputs for "low ticks" and "high ticks". The "low ticks" input defines how many counts of the input signal that the output needs to remain low. Conversely, the "high ticks" input defines how many counts of the input signal the output needs to be high. The low output count is performed before the high output count. For example, if low ticks was set to 15 and high ticks was set to 5, the output would be low for the first 15 pulses (or edges) of the incoming signal, and then be high for the next 5. This is VI is hardware retriggerable, so the behavior will immediately repeat after one cycle is completed and another trigger is received. This VI is great for custom triggering such as needing a trigger that occurs exactly after 5 minutes have passed, or after an angular encoder has turned exactly 17 degrees, etc. This VI can also be made to run continuously by changing the Timing VI from "finite samples" to "continuous" samples. In this fasion, the above example would result in 15 low, 5 high, 15 low, 5 high, 15 low, 5 high, etc. (a 25% duty cycle output) until the task is stopped. This could easilty be 30,000 low ticks and 2 high ticks, or any other combination of values. Requirements Software LabVIEW 2010 or compatible DAQmx 9.1.5 or compatible Hardware DAQ device that has available counters Steps to Implement or Execute Code Download and extract the appropriate version for your LabVIEW installation below. Set the number of high and low ticks to get the behavior that you want. Run and notice the behavior. Additional Information or References **This document has been updated to meet the current required format for the NI Code Exchange.**
View full article
Create a table of blank spaces in a Microsoft Word table using the Report Generation Toolkit. Uses border formatting to make the cells appear to be underlined. Demonstrates some advanced techniques of formatting Microsoft Word tables in LabVIEW. Ex: ___________  ___________  ___________ ___________  ___________  ___________ ___________  ___________  ___________
View full article
Scenario: I'm acquiring several signals from several ethercat devices, using I/O Nodes, and I want to process them using single point functions, like filters and Spectrum analisys. Problem: Single point functions allow only one signal at time, no arrays and these functions have internal memory (uninitialized shift registers) so the following option will not work: Solution: Use Dynamic call to load several instances of filters and pass each element from array to one instance of the filter: 1. This case will never be executed, it is there only to make LabVIEW load the filter diring the caller load 2. This loop will call the reentrant VI according the number of signals to be processed and store its references 3. This for loop will pass each  element array to an filter instance. Creating a subVI and applying this to the scenario solution we have the folloing code: Support and Contact This code provided as open-source  software.  If it does not meet your exact specification, you are  encouraged to modify the source code to meet your needs.  It is not  officially supported by National Instruments. Any attached Code is provided As Is.  It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments.  You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense
View full article
Summary: This example demonstrates the usefulness of Annotations and Clusters. The User Interface requirement is to effectively capture and display multi-dimensional information. Annotations are used on a 2-D XY graph to display multi-dimensional information. The use of annotations make the display easy to understand. An array of clusters is used to collect a varying set of information from the user. Function: The VI is used to collect a time profile of currents and other settings through which a TEC is cycled. Each time interval has multiple variables. The challenge is to easily capture and display the variables. Steps to execute code: Run the VI. For the description of individual controls, turn on context help. Make settings for multiple time intervals. The XY graph display is updated with a time profile. Annotations are used to display the interval settings. Double click on the XY graph to stop the program. Screenshots: ANNOTATION Text Format Interval_Frequency Legend RED - TEC is ON and set to HEAT BLUE - TEC is ON and set to COOL GREY - TEC is OFF ARROW - Indicates BDA is enabled. VI Snippet: Scan_Timing_Details.vi - For some reason, the main VI snippet includes bad wires. Create_XY_Graph_Plot.vi Stop_Loops_On_Error.vi VI attached below LabVIEW 2010
View full article
Overview This application is an implementation of the classic game Boxman.   Description Use the arrow buttons on the keyboard to direct the "pig" to push the box to the destination. Most of the internal work is done through flat sequence structures and array storage. Maps are broken down into grids which are stored into 2D arrays. Notice that the resource (include maps and picture is dynamic loaded).I write another tool(VC++ 6.0) which called boxman_mapeditor to editor and add new maps. Enjoy youself!     Change control: first release.internal version 1.03.   Steps to Implement or Execute Code Download and extract contets of zip Open boxman1.03.llb Open boxman1.03.vi Run vi and play game Requirements Software LabVIEW 9 or later **This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**
View full article