<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Seneca5 Software Blog &#187; LabVIEW</title>
	<atom:link href="http://www.seneca5.com/blog/category/labview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.seneca5.com/blog</link>
	<description>Expert LabVIEW™ Development</description>
	<lastBuildDate>Mon, 06 Sep 2010 15:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>July User Group &#8211; Circular Buffer in LabVIEW</title>
		<link>http://www.seneca5.com/blog/2010/07/july-user-group-circular-buffer-in-labview/</link>
		<comments>http://www.seneca5.com/blog/2010/07/july-user-group-circular-buffer-in-labview/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 15:35:57 +0000</pubDate>
		<dc:creator>Craig Bedward</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[User Group]]></category>
		<category><![CDATA[example]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=562</guid>
		<description><![CDATA[Ludwik Kordas presented the concept of a Circular Buffer (CB) and various ways to implement it in LabVIEW. His presentation and example VI&#8217;s are included in this post. Definition An area of memory  used to store a continuous stream of data by starting again at the beginning of the buffer after reaching the end. A [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/07/CircularBuffer_Ring1.png"></a><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/07/CircularBuffer_Ring1.png"><img class="alignright size-full wp-image-564" title="CircularBuffer_Ring1" src="http://www.seneca5.com/blog/wp-content/uploads/2010/07/CircularBuffer_Ring1.png" alt="" width="132" height="151" /></a>Ludwik Kordas presented the concept of a Circular Buffer (CB) and various ways to implement it in LabVIEW.</p>
<p>His presentation and example VI&#8217;s are included in this post.</p>
<p><span id="more-562"></span></p>
<h3>Definition</h3>
<p>An area of memory  used to store a continuous stream of data by starting again at the beginning of the buffer after reaching the end. A circular buffer is usually written by one process and read by another. Separate read and write pointers are maintained. These are not allowed to pass each other otherwise either unread data would be overwritten or invalid data would be read.<br />
<a href="http://www.seneca5.com/blog/wp-content/uploads/2010/07/CircularBuffer_Ring1.png"><img class="alignright size-full wp-image-564" title="CircularBuffer_Ring1" src="http://www.seneca5.com/blog/wp-content/uploads/2010/07/CircularBuffer_Ring1.png" alt="" width="188" height="215" /></a></p>
<h3>Simple CB Models</h3>
<ul>
<li style="text-align: left;">FIFO: first IN first OUT</li>
<li style="text-align: left;">(first WRITTEN first READ)</li>
<li style="text-align: left;">Number of elements: n+1</li>
<li style="text-align: left;">Predefined # of elements: n</li>
<li style="text-align: left;">“n+1” element is forbidden for write/read pointers</li>
<li style="text-align: left;">Elements could be of any data type including arrays, clusters or even clusters of arrays of clusters</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/07/july-user-group-circular-buffer-in-labview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VIG Example &#8211; Stopwatch</title>
		<link>http://www.seneca5.com/blog/2010/07/vig-example-stopwatch/</link>
		<comments>http://www.seneca5.com/blog/2010/07/vig-example-stopwatch/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 19:35:06 +0000</pubDate>
		<dc:creator>Craig Bedward</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Functional Global]]></category>
		<category><![CDATA[VIG]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=535</guid>
		<description><![CDATA[A VIG or &#8220;functional global&#8221; is a LabVIEW VI that provides the features of a global variable while overcoming some of the down sides of an actual global variable. A function global uses uninitialized shift registers to maintain state information and a typedef function to select the mode of operation. This example implements a stopwatch [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/07/StopWatchScreen1.png"><img class="alignright size-medium wp-image-536" title="StopWatchScreen1" src="http://www.seneca5.com/blog/wp-content/uploads/2010/07/StopWatchScreen1-300x255.png" alt="" width="300" height="255" /></a>A VIG or &#8220;functional global&#8221; is a LabVIEW VI that provides the features of a global variable while overcoming some of the down sides of an actual global variable.</p>
<p>A function global uses uninitialized shift registers to maintain state information and a typedef function to select the mode of operation.</p>
<p>This example implements a stopwatch timer. You can use it to time up to 16 independent events in your application.</p>
<p>For more information on functional globals, check out these links:</p>
<p><a href="http://decibel.ni.com/content/docs/DOC-2143" target="_blank">Basic Functional Global Example</a></p>
<p><a href="http://decibel.ni.com/content/docs/DOC-12054" target="_blank">Functional Global Flags to Protect a Shared Resource</a></p>
<p><a href="http://search.ni.com/nisearch/app/main/p/bot/no/ap/tech/lang/en/pg/1/ps/10/sn/ssnav:dzn/q/%22functional%20global%22/ses/false/" target="_blank">Other &#8220;functional global&#8221; examples in NI Developer Zone</a></p>
<h4>Download the Code here:</h4>
<ul>
<li><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/07/StopwatchLV2009.zip">Stopwatch LV2009</a></li>
<li><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/07/StopwatchLV61.zip">Stopwatch LV61</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/07/vig-example-stopwatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Certified LabVIEW Associate Developer (CLAD) Example Tests</title>
		<link>http://www.seneca5.com/blog/2010/06/clad-example-tests/</link>
		<comments>http://www.seneca5.com/blog/2010/06/clad-example-tests/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 21:14:21 +0000</pubDate>
		<dc:creator>Craig Bedward</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[User Group]]></category>
		<category><![CDATA[Certification]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=515</guid>
		<description><![CDATA[There was a lot of interest at our last group meeting about NI certification tests. The Certified LabVIEW Associate Developer (CLAD) is the first step in getting certified. The test shows knowledge of LabVIEW basics. If you have had the LabVIEW Basics class (now called Core 1) or if you have some real-life experience with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/06/testform.jpg"><img class="alignright size-thumbnail wp-image-516" title="testform" src="http://www.seneca5.com/blog/wp-content/uploads/2010/06/testform-150x150.jpg" alt="" width="150" height="150" /></a>There was a lot of interest at our last group meeting about NI certification tests.</p>
<p>The Certified LabVIEW Associate Developer (CLAD) is the first step in getting certified. The test shows knowledge of LabVIEW basics. If you have had the LabVIEW Basics class (now called Core 1) or if you have some real-life experience with LabVIEW, you might be ready. If you want to find out, there are some sample tests you can download from NI&#8217;s web site:</p>
<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/06/clad_sample_exam1.pdf">clad_sample_exam1.pdf</a></p>
<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/06/clad_sample_exam2.pdf">clad_sample_exam2.pdf</a></p>
<p><a href="http://zone.ni.com/devzone/cda/epd/p/id/5225" target="_blank">Certified LabVIEW Associate Developer (CLAD) Sample Exams</a></p>
<p><a href="http://zone.ni.com/devzone/cda/tut/p/id/4261" target="_blank">How Can I Prepare for the Certified LabVIEW Associate Developer (CLAD) Exam?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/06/clad-example-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>June 2010 User Group Invite</title>
		<link>http://www.seneca5.com/blog/2010/05/june-2010-user-group-invite/</link>
		<comments>http://www.seneca5.com/blog/2010/05/june-2010-user-group-invite/#comments</comments>
		<pubDate>Sat, 29 May 2010 05:36:51 +0000</pubDate>
		<dc:creator>Craig Bedward</dc:creator>
				<category><![CDATA[Event]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[User Group]]></category>
		<category><![CDATA[Functional Global]]></category>
		<category><![CDATA[VIG]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=507</guid>
		<description><![CDATA[Mark your calendar. First day back from Memorial Day vacation is the next user group meeting. Topic: LabVIEW Design Patterns &#8211; VIG Timer, Producer/Consumer, and more This meeting will be at Seneca5, Tuesday June 1st at 6:30. We serve pizza, so you can come straight from work. Check out the LabVIEW Advanced User Group page for [...]]]></description>
			<content:encoded><![CDATA[<p>Mark your calendar. First day back from Memorial Day vacation is the next user group meeting.</p>
<p><strong>Topic</strong>: LabVIEW Design Patterns &#8211; VIG Timer, Producer/Consumer, and more</p>
<p>This meeting will be at Seneca5, Tuesday June 1st at 6:30. We serve pizza, so you can come straight from work.</p>
<p>Check out the <a href="http://www.seneca5.com/blog/user-group/" target="_self">LabVIEW Advanced User Group</a> page for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/05/june-2010-user-group-invite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>April 2010 User Group Invite</title>
		<link>http://www.seneca5.com/blog/2010/03/april-2010-user-group-invite/</link>
		<comments>http://www.seneca5.com/blog/2010/03/april-2010-user-group-invite/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 17:26:17 +0000</pubDate>
		<dc:creator>Craig Bedward</dc:creator>
				<category><![CDATA[Event]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[User Group]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=451</guid>
		<description><![CDATA[It&#8217;s time again for our monthly LabVIEW user group meeting. The topic this time is Motor Control with LabVIEW. This meeting will be at Seneca5, Tuesday April 6th at 6:30. We serve pizza, so you can come straight from work. Check out the LabVIEW Advanced User Group page for more details.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time again for our monthly LabVIEW user group meeting. The topic this time is <span style="color: #0000ff;"><strong>Motor Control with LabVIEW</strong></span>.</p>
<p>This meeting will be at Seneca5, Tuesday April 6th at 6:30. We serve pizza, so you can come straight from work.</p>
<p>Check out the <a href="http://www.seneca5.com/blog/user-group/" target="_self">LabVIEW Advanced User Group</a> page for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/03/april-2010-user-group-invite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better Multicolumn Listbox Icons</title>
		<link>http://www.seneca5.com/blog/2010/03/better-multicolumn-listbox-icons/</link>
		<comments>http://www.seneca5.com/blog/2010/03/better-multicolumn-listbox-icons/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 02:55:00 +0000</pubDate>
		<dc:creator>Craig Bedward</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[LabVIEW]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=441</guid>
		<description><![CDATA[Previously, I posted a listbox control with improved icons. Some have asked if it can be used for multicolumn listboxes, too. Well, yet it can. And here it is. (Actually, you can just use the listbox control. Right click and select Replace. Replace it with a multicolumn listbox. The new multicolumn box will maintain the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/03/MulticolumnListbox.png"><img class="alignright size-full wp-image-446" title="MulticolumnListbox" src="http://www.seneca5.com/blog/wp-content/uploads/2010/03/MulticolumnListbox.png" alt="MulticolumnListbox" width="160" height="139" /></a>Previously, I posted a <a href="http://www.seneca5.com/blog/2009/08/better-listbox-icons/">listbox control with improved icons</a>. Some have asked if it can be used for multicolumn listboxes, too. Well, yet it can. And here it is.</p>
<p>(Actually, you can just use the listbox control. Right click and select Replace. Replace it with a multicolumn listbox. The new multicolumn box will maintain the improved icons.)</p>
<p>Download VI: <a href="http://www.seneca5.com/blog/wp-content/uploads/2010/03/MulticolumListBoxIcons2.0.zip">MulticolumListBoxIcons2.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/03/better-multicolumn-listbox-icons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic, Smautomatic</title>
		<link>http://www.seneca5.com/blog/2010/03/automatic-smautomatic/</link>
		<comments>http://www.seneca5.com/blog/2010/03/automatic-smautomatic/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 02:49:57 +0000</pubDate>
		<dc:creator>GrumpyOldMan</dc:creator>
				<category><![CDATA[Grumpy]]></category>
		<category><![CDATA[LabVIEW]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=326</guid>
		<description><![CDATA[When I head out to my work shed to build something with my tools, the tools I use are picked by one and only one person&#8230;me! That&#8217;s the way LabVIEW used to be, too, back in the good old days. Now it&#8217;s all about the young kids and their automatic tool selection. La-ti-da! Manual tool [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/02/automatictoolselection.jpg"><img class="alignright size-full wp-image-328" title="automatictoolselection" src="http://www.seneca5.com/blog/wp-content/uploads/2010/02/automatictoolselection.jpg" alt="automatictoolselection" width="145" height="154" /></a>When I head out to my work shed to build something with my tools, the tools I use are picked by one and only one person&#8230;me! That&#8217;s the way LabVIEW used to be, too, back in the good old days.</p>
<p>Now it&#8217;s all about the young kids and their <em>automatic</em> tool selection. La-ti-da! Manual tool selection was good enough for us, and it should be good enough for them too!</p>
<p>I don&#8217;t let my work shed tell me when to use a hammer and when to use a screwdriver! And if I ever get any of those new &#8220;power tools&#8221; I won&#8217;t want my shed picking those either!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/03/automatic-smautomatic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>It&#8217;s LabVIEW, Stupid!</title>
		<link>http://www.seneca5.com/blog/2010/03/its-labview-stupid/</link>
		<comments>http://www.seneca5.com/blog/2010/03/its-labview-stupid/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 21:09:50 +0000</pubDate>
		<dc:creator>GrumpyOldMan</dc:creator>
				<category><![CDATA[Grumpy]]></category>
		<category><![CDATA[LabVIEW]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=313</guid>
		<description><![CDATA[In my day, we knew that LabVIEW was an acronym, so we spelled it with capital VIEW as God intended! We knew it because we were there when it was being made. Sure, the first versions of LabVIEW were icons chiseled on stone tablets, but we liked it that way! And there is one thing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2010/02/LVSepia1.png"><img class="alignright size-full wp-image-322" title="LVSepia" src="http://www.seneca5.com/blog/wp-content/uploads/2010/02/LVSepia1.png" alt="LVSepia" width="200" height="248" /></a>In my day, we knew that LabVIEW was an acronym, so we spelled it with capital VIEW as God intended! We knew it because we were there when it was being made. Sure, the first versions of LabVIEW were icons chiseled on stone tablets, but we liked it that way!<br />
And there is one thing for sure we knew: the VIEW in LabVIEW is an acronym, so it needs to be capitalized.</p>
<p>It is not Labview, LabView, or LABVIEW.  It&#8217;s LabVIEW!</p>
<p>Maybe we could never remember what the acronym stood for but we knew it was one.</p>
<p>Violent Inhuman Enormous Wildebeest<br />
Vital Inheritance Expense Withholding<br />
Virtually Idiot-proof Enhanced Whatchamagig</p>
<p>It doesn&#8217;t matter. It&#8217;s an acronym. Now you know. So spell it right!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/03/its-labview-stupid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vision Solution</title>
		<link>http://www.seneca5.com/blog/2010/01/vision-solution/</link>
		<comments>http://www.seneca5.com/blog/2010/01/vision-solution/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 04:16:28 +0000</pubDate>
		<dc:creator>Michael Jones</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[LabVIEW Vision USB Camera]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=253</guid>
		<description><![CDATA[Good vision systems are difficult to engineer. Our brain, as far as computations are concerned, is a very parallel system. It can account for contrast and brightness, recognize and categorize a seemingly endless number of shapes, and set our eyes to focus faster than any commercial camera, all simultaneously. It can also, through the depth [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-278" title="11-air-pressure-gauge" src="http://www.seneca5.com/blog/wp-content/uploads/2010/01/11-air-pressure-gauge1.jpg" alt="11-air-pressure-gauge" width="218" height="261" />Good vision systems are difficult to engineer. Our brain, as far as computations are concerned, is a very parallel system. It can account for contrast and brightness, recognize and categorize a seemingly endless number of shapes, and set our eyes to focus faster than any commercial camera, all simultaneously. It can also, through the depth perception of having two eyes or through the patterns of experience, give volume to the two dimensional image your eyes obtain.</p>
<p>Replicating these tasks on a computer is nothing short of impossible with today&#8217;s level of research and design.</p>
<p>What the computer does well though is sequential logic very quickly. Vision systems use this to their advantage by constraining the vision problem to one task at the time. In the end the computer can attack and solve particular vision problems better than our own vision systems can.</p>
<p>Today we will be detecting the value of an off-the-shelf PSI gauge using <a href="http://zone.ni.com/devzone/cda/tut/p/id/10430" target="_blank">NI Vision Builder</a>. Hopefully our solution gives some insight into the current level of vision systems.</p>
<p><span id="more-253"></span><strong>Acquire</strong></p>
<p>The first step in any vision application is to acquire the image.  Vision Builder makes this particularly easy for USB, Firewire, or Ethernet cameras.</p>
<p><a style="text-decoration: none;" href="http://www.seneca5.com/blog/wp-content/uploads/2010/01/1.JPG"><img class="aligncenter size-full wp-image-234" title="1" src="http://www.seneca5.com/blog/wp-content/uploads/2010/01/1.JPG" alt="1" width="576" height="433" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2010/01/vision-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nice Threads</title>
		<link>http://www.seneca5.com/blog/2009/11/nice-threads/</link>
		<comments>http://www.seneca5.com/blog/2009/11/nice-threads/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 07:33:57 +0000</pubDate>
		<dc:creator>Craig Bedward</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.seneca5.com/blog/?p=202</guid>
		<description><![CDATA[Multithread programming in traditional languages can be a challenge. The programmer is responsible for managing many things, such as: Separating logical tasks Avoiding race conditions Avoiding thread starvation conditions Managing communication between the threads LabVIEW, on the other hand, lends itself easily to multithreaded programming. In fact, if you follow the dataflow rules, multithreading will [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2009/11/VI-Server-Functions1.PNG"></a><a href="http://www.seneca5.com/blog/wp-content/uploads/2009/11/Threads_RGB.png"><img class="alignright size-full wp-image-478" title="Threads" src="http://www.seneca5.com/blog/wp-content/uploads/2009/11/Threads_RGB.png" alt="" width="305" height="340" /></a>Multithread programming in traditional languages can be a challenge. The programmer is responsible for managing many things, such as:</p>
<ul>
<li>Separating logical tasks</li>
<li>Avoiding race conditions</li>
<li>Avoiding thread starvation conditions</li>
<li>Managing communication between the threads</li>
</ul>
<p>LabVIEW, on the other hand, lends itself easily to multithreaded programming. In fact, if you follow the dataflow rules, multithreading will happen <em>automatically</em> when LabVIEW finds the opportunity.</p>
<h3><span id="more-202"></span>Dataflow Programming</h3>
<p>LabVIEW follows a programming model called dataflow programming. Rather than writing a program in the form of Step 1, Step 2, Step 3, &#8230;, LabVIEW programs pass the data on wires. Any VI taking inputs must wait for all of its inputs to be ready before it can run. In the example below, Loop A must run before Loop B is able to run, because Loop A produces data that is used by Loop B. The data dependency controls the order of execution.</p>
<div id="attachment_216" class="wp-caption aligncenter" style="width: 466px"><a href="http://www.seneca5.com/blog/wp-content/uploads/2009/11/loops_dependent.PNG"><img class="size-full wp-image-216" title="loops_dependent" src="http://www.seneca5.com/blog/wp-content/uploads/2009/11/loops_dependent.PNG" alt="Loops with a data dependency" width="456" height="140" /></a><p class="wp-caption-text">Loops with a data dependency</p></div>
<p>However, if we remove the data dependency, we no longer force the order of execution. LabVIEW gets to decide which loop will run first. But is it Loop A or Loop B? Actually, it is both. This is where LabVIEW&#8217;s automatic multithreading kicks in. LabVIEW will create multiple threads and run each loop simultaneously, one in each thread.</p>
<div id="attachment_217" class="wp-caption aligncenter" style="width: 466px"><a href="http://www.seneca5.com/blog/wp-content/uploads/2009/11/loops_threaded.PNG"><img class="size-full wp-image-217" title="loops_threaded" src="http://www.seneca5.com/blog/wp-content/uploads/2009/11/loops_threaded.PNG" alt="Loops with no data dependency" width="456" height="140" /></a><p class="wp-caption-text">Loops with no data dependency</p></div>
<h3>Sharing Data</h3>
<p>Remember, LabVIEW can do automatic multithreading only because there is no wired data dependency between the two loops, so the next question is, how do we share data between the two loops?</p>
<h4>Local Variable</h4>
<p>The first way of sharing data between loops that probably comes to mind is a local variable. It provides a way for you to access the value of data without wiring, so it can indeed be used and still allow automatic multithreading. But there are some drawbacks to local variables: they can cause race conditions, they need to be initialized, they break the dataflow programming paradigm, so you should not get used to using them (if you are a LabVIEW purist, you would never use a local variable).</p>
<h4>Queues</h4>
<p>A better way to share data between loops is with a queue. One loop can send a message to the other with a queue without creating a data dependency. And the message is delivered in a more predictable manner than a local variable. A great example of this technique is the standard Producer/Consumer template.</p>
<div id="attachment_219" class="wp-caption aligncenter" style="width: 543px"><a href="http://www.seneca5.com/blog/wp-content/uploads/2009/11/producer-consumer.PNG"><img class="size-full wp-image-219" title="producer-consumer" src="http://www.seneca5.com/blog/wp-content/uploads/2009/11/producer-consumer.PNG" alt="Producer-Consumer Template" width="533" height="371" /></a><p class="wp-caption-text">Producer-Consumer Template</p></div>
<h3>Spinning Off Threads</h3>
<p>Multithreading with multiple parallel loops is fine, but it takes you only so far. Take for example a program that needs to capture data from a DAQ card as fast as possible, handle the user interface at a medium rate to keep up with the operator, and log the data to a file as a background function. Using parallel loops, you cannot control the priority of the various loops, which means the file loop runs as an equal to the DAQ task. That will likely slow down the DAQ and cause data to be lost.</p>
<p>One solution is to put each of the loops into a separate VI and &#8220;spin off&#8221; each of those VI&#8217;s to run independently. You can control the priority of a VI (under <em>VI Properties-&gt;Execution</em>), so you can set the DAQ VI to be time critical and the file I/O to be a background task.</p>
<h3>How to Spin Off a Thread</h3>
<p><img class="alignright size-full wp-image-220" style="margin-left: 10px; margin-right: 10px;" title="AppControlPalette" src="http://www.seneca5.com/blog/wp-content/uploads/2009/11/AppControlPalette.PNG" alt="AppControlPalette" width="174" height="225" /></p>
<p>To run a VI as a thread, you can&#8217;t just call it as you would a normal VI. Normally, when a VI calls another, that VI suspends its execution until the sub-VI completes. That&#8217;s the opposite of the multithreaded operation we are after. To spin off a VI, we can make use of some of the <em>VI Server </em>VI&#8217;s. These can be found in the <em>Application Control</em> palette.</p>
<p>The process is not difficult:</p>
<ol>
<li>Open VI Reference</li>
<li>Invoke Node &#8211; <em>Invoke Run VI</em>, specifying to not <em>Wait Until Done</em></li>
<li>(Optionally) Invoke Node &#8211; Invoke <em>FP.Open</em> to show the front panel of the VI you are spinning off</li>
<li>Use a named queue to communicate between the threads</li>
<li>When the thread is terminated, use Close Reference to dispose of the reference to the VI</li>
</ol>
<p><a href="http://www.seneca5.com/blog/wp-content/uploads/2009/11/VI-Server-Functions1.PNG"><img style="display: block; margin-left: auto; margin-right: auto; border: 0px initial initial;" title="VI Server Functions" src="http://www.seneca5.com/blog/wp-content/uploads/2009/11/VI-Server-Functions1.PNG" alt="VI Server Functions" width="536" height="144" /></a></p>
<h4>Priority</h4>
<p>When you spin off a thread, it will run with the priority specified in <em>VI Properties-&gt;Execution</em>. You can also set the <em>Preferred Execution System</em> to tweak performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seneca5.com/blog/2009/11/nice-threads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
