<?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>Culverson Software-Custom DAQ Software labVIEW &#187; LabVIEW</title>
	<atom:link href="http://culverson.com/category/lab-view/feed/" rel="self" type="application/rss+xml" />
	<link>http://culverson.com</link>
	<description>Custom Labview Data Acquisition Software Maine</description>
	<lastBuildDate>Thu, 20 May 2010 20:02:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Writing Non-Fragile Code</title>
		<link>http://culverson.com/writing-non-fragile-code/</link>
		<comments>http://culverson.com/writing-non-fragile-code/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 20:48:59 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Easier Programming]]></category>
		<category><![CDATA[LabVIEW]]></category>

		<guid isPermaLink="false">http://culverson.com/?p=254</guid>
		<description><![CDATA[Oooops&#8230;. who broke it?
&#8220;Fragile&#8221; code is code that breaks in one place because of changes you make in some other place. It&#8217;s most aggravating when you&#8217;re due to ship a new version tomorrow and you need to make one last tweak at 11:30 PM, or your client is looking over your shoulder and this little [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong><em>Oooops&#8230;. who broke it?</em></strong></p>
<p>&#8220;Fragile&#8221; code is code that breaks in one place because of changes you make in some other place. It&#8217;s most aggravating when you&#8217;re due to ship a new version tomorrow and you need to make one last tweak at 11:30 PM, or your client is looking over your shoulder and this little &#8220;harmless&#8221; change shows up as a smoldering heap during the demo.</p>
<p>In this case, &#8220;break&#8221; doesn&#8217;t ONLY mean &#8220;broken arrow&#8221; , or uncompilable code (at least you can chase those down easily enough). Here, &#8220;break&#8221; also means &#8220;operates incorrectly&#8221; or &#8220;completely wrecks itself like it never did before&#8221; or somewhere in between.</p>
<p>These sorts of breaks come from unrecognized dependencies, and they&#8217;re all too easy to make: the header size has been 3 for months and months now, so when you add a new function that needs it, it&#8217;s easy to stick in a constant 3 and be done with it.</p>
<p>DON&#8217;T DO IT.</p>
<p><span id="more-254"></span>If you&#8217;re an old-hand bit-banging cycle counter like me, it&#8217;s easy to think of saving a few cycles and adding up the bytes in this cluster, and using a constant of 53 when you need the size of it.</p>
<p>DON&#8217;T DO IT.</p>
<p>The problem is, or course, then when (not <em>if</em>, but <em>when</em>) these things change, then you will have to track down ALL the instances where you use this number and change them.  Not a good plan.  The compiler won&#8217;t complain &#8211; the code is still valid.  But reading thee bytes when you should be reading four will not get you where you want to go.</p>
<p>One tip to solving this is to reduce the number of places that you use such numbers. Focus such procedures into a single VI if you can. But the real key to solving this is to recognize these things when you originate them.</p>
<p><strong>Example #1</strong></p>
<p>Here we need to receive a packet header, consisting of a cluster of a U8 enum command and a U16 integer.  It&#8217;s easy enough to count up to three bytes, and it would be easy to plop down a 3 constant.  However, it is safer to use a constant of the header&#8217;s typedef and calculate its size in code.  This might go against your instincts (it does mine), but in fact the extra time taken (to flatten into string and get string length) is trivial (<a href="http://culverson.com/what-time-is-it/" target="_blank">measure it yourself</a> if you have doubts). On top of a TCP READ operation, this burden is truly insignificant.</p>
<p>And the benefit is that when the integer needs to become an U32 or the command must become a U16, here&#8217;s one less thing YOU have to worry about.  Since the constant here is a TYPEDEF, and since you&#8217;re calculating the size every time, then it will keep on working.</p>
<p><img class="alignnone size-full wp-image-256" title="Fragile1" src="http://culverson.com/site09/wp-content/uploads/2009/10/Fragile1.PNG" alt="Fragile1" width="234" height="158" /></p>
<p><strong>Example #2</strong></p>
<p><strong><span style="font-weight: normal;">This example is similar &#8211; sending a packet header plus a payload thru a connection. Even if your payload is always the same size, it&#8217;s better to calculate it than to use a constant.  With any luck at all, the STRING LENGTH operation will get the same answer every time. and if you do change it at some point, then this code won&#8217;t break.</span></strong></p>
<div><img class="alignnone size-full wp-image-258" title="Fragile2" src="http://culverson.com/site09/wp-content/uploads/2009/10/Fragile2.PNG" alt="Fragile2" width="344" height="140" /></div>
<div><strong>Example #3</strong></div>
<div>Here&#8217;s another use.  When you have an ENUM, it might be useful to loop over every value. But how do you know how many values to use?  You could count them and plop down a constant. That&#8217;s no good, because it leaves you vulnerable.  You know the first value has a numeric equivalent of 0, you could add a value called &#8220;Last&#8221;, but that&#8217;s ugly if the enum is a control onscreen somewhere.</div>
<div>My answer is to cast a large U16 (or whatever data type the ENUM is) into that type (and then possibly back to an integer if needed).</div>
<div>Here, the FOLDER is an enum listing the various folders my program can refer to. I don&#8217;t know how many there are, maybe 25-30 (in this case, ignorance really is bliss), because I don&#8217;t care.</div>
<div>This code is responsible for creating them all (with exceptions) at startup time.</div>
<div>First we start with a large U16.  I picked U16 to match the representation of the enum itself; that&#8217;s necessary for proper casting results.</div>
<div>Then we typecast it to the folder type.  Presumably, 9999 is more than the number of entries in the ENUM, so the typecasting process can&#8217;t let a literal cast stand, as it would be an illegal value.  So what comes out is the last possible value.</div>
<div>Inside the loop, we convert the &#8220;i&#8221; variable to a U16 to match the representation of the enum itself.</div>
<div>Then we typecast that value into the folder type.</div>
<div>The result is a variable that cycles from first ENUM value to the last ENUM value, and does something with each value, all without knowing how many there are!</div>
<div>If we add a new folder type to the ENUM (it is a typedef), then this code does not need changing.</div>
<div><img class="alignnone size-full wp-image-259" title="Fragile3" src="http://culverson.com/site09/wp-content/uploads/2009/10/Fragile3.PNG" alt="Fragile3" width="351" height="183" /></div>
<div>I hope that this thought will help you create code that is more robust.  Your clients will love you for it.</div>
<div>Enjoy.</div>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/writing-non-fragile-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Watch your step</title>
		<link>http://culverson.com/watch-your-step/</link>
		<comments>http://culverson.com/watch-your-step/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 12:42:45 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Easier Programming]]></category>
		<category><![CDATA[LabVIEW]]></category>

		<guid isPermaLink="false">http://culverson.com/?p=203</guid>
		<description><![CDATA[But who&#8217;s watching the watchers?
Some development environments have a concept called &#8220;watching&#8221;, where you choose a variable to watch and you see a continuous display of that variable in some window.  This is very useful during debugging, as you can step through your program and find out where this variable is being changed.
LabVIEW has no [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em><strong>But who&#8217;s watching the watchers?</strong></em></p>
<p>Some development environments have a concept called &#8220;watching&#8221;, where you choose a variable to watch and you see a continuous display of that variable in some window.  This is very useful during debugging, as you can step through your program and find out where this variable is being changed.</p>
<p>LabVIEW has no such built-in feature, but it doesn&#8217;t really need one.  You can construct your own watch windows, have them run independently of your main code and accomplish the same thing.</p>
<p>Simply make a new VI with a WHILE loop and a STOP button.  Add a WAIT for 200 mSec (or something) inside it (so you don&#8217;t hog the CPU).  Each time thru the loop, grab your watch variable, process it, and display it.</p>
<p>The &#8220;processing&#8221; can be unbundling a single item from a complicated cluster, or picking an element out of an array, or anything you need to display the item in question.  Perhaps you need to call a VI to get it. Perhaps you need to query an I/O port, or a TCP instrument. Whatever you need to do to watch your troublesome variable.</p>
<p>SUGGESTION:  When you&#8217;re done with it, save it in a folder called &#8220;Miscellaneous Stuff&#8221; or something, so you can get at it easy next time.  There will be a next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/watch-your-step/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Next Step in TCP-IP</title>
		<link>http://culverson.com/the-next-step-in-tcpip/</link>
		<comments>http://culverson.com/the-next-step-in-tcpip/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 21:37:56 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[TCP]]></category>

		<guid isPermaLink="false">http://culverson.com/?p=198</guid>
		<description><![CDATA[Several conversations at once
A question came up on the LabVIEW forum the other day about multiple connections, and how hard it was to have two connections transmitting at two different rates.  This surprised me a bit, because I have been doing just that for quite a few years.  The allegation was made also that TCP [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center; "><strong><em>Several conversations at once</em></strong></p>
<p>A question came up on the LabVIEW forum the other day about multiple connections, and how hard it was to have two connections transmitting at two different rates.  This surprised me a bit, because I have been doing just that for quite a few years.  The allegation was made also that TCP requires a minimum packet size of 32 bytes. That is also a surprise since I have been doing things contrary to that &#8220;rule&#8221; for quite a few years.</p>
<p>So, in an attempt to clarify things above and beyond the <a href="http://culverson.com/beginners-guide-to-tcpip/" target="_blank">Beginner&#8217;s Guide to TCP/IP</a>, I present this example with a CLIENT and a SERVER.</p>
<p>The SERVER should be run first and listens for four connections on four consecutive ports. It has four data generators, running at different rates.  When data is available, it transmits it over the connection  if there is one, or listens for one if there&#8217;s not.</p>
<p>The SERVER uses a re-entrant VI so that the same code can be executing in four instances at one time.  The four instances are given four different intervals. The WAITs do not conflict because of this reentrancy.</p>
<p>The CLIENT initiates four connections to these same ports, and waits for data in four loops.  I did not use reentrant VIs here, because of the connection to the charts.  Although you could pass a reference to the chart to four reentrant subVIs, I chose not to, thinking that the speed would be better with the direct approach.</p>
<p>Given that this is based on the mSec Timer in LabVIEW, I wouldn&#8217;t vouch for it&#8217;s accuracy as you approach 1000 Hz. But the basic techniques are sound and will work beyond that frequency.</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/MultiConnect.llb.zip">Click here</a> for a downloadable example of four-channel client server communications.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/the-next-step-in-tcpip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed of En Masse Operations</title>
		<link>http://culverson.com/speed-of-en-masse-operations/</link>
		<comments>http://culverson.com/speed-of-en-masse-operations/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 18:04:03 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>

		<guid isPermaLink="false">http://culverson.com/?p=193</guid>
		<description><![CDATA[Zip-zap-zowee and swoosh!
Just in case you thought I was kidding in the article on en masse operations, I decided to offer some proof of the speed advantages they can give you.
I used the Timing Template vi to measure the time it takes to multiply an array of DBLs by two, both with a loop, and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center; "><strong>Zip-zap-zowee and swoosh!</strong></p>
<p>Just in case you thought I was kidding in the article on <a href="http://culverson.com/operations-en-masse/" target="_blank">en masse</a> operations, I decided to offer some proof of the speed advantages they can give you.</p>
<p>I used the <a href="http://culverson.com/what-time-is-it/" target="_blank">Timing Template</a> vi to measure the time it takes to multiply an array of DBLs by two, both with a loop, and without.  I set up the timing VI to create an array of 1000 random numbers, and then time the multiply operation.</p>
<p>First, the loop method, where you auto-index every value out of the array, multiply it, and auto-index it back in:</p>
<p><img class="alignnone size-full wp-image-194" title="viaLoop" src="http://culverson.com/site09/wp-content/uploads/2009/09/viaLoop.PNG" alt="viaLoop" width="450" height="564" /></p>
<p>As you can see, this took 7.47 uSec per loop.  Not all that shabby.  But just removing the loop lets the <em>en masse</em> operation do it:</p>
<p><img class="alignnone size-full wp-image-195" title="EnMasse" src="http://culverson.com/site09/wp-content/uploads/2009/09/EnMasse.PNG" alt="EnMasse" width="461" height="570" /></p>
<p>Holy Speed Demon, Batman!  That&#8217;s 0.77 uSec or about ONE TENTH the time!</p>
<p>Now, I&#8217;m not guaranteeing that all such operations will save you that much time, but if you have a chance to use them, then you should!</p>
<p>It&#8217;s easier on you and easier on the hardware!</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/speed-of-en-masse-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping your charts up to date</title>
		<link>http://culverson.com/keeping-your-charts-up-to-date/</link>
		<comments>http://culverson.com/keeping-your-charts-up-to-date/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 14:49:00 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://culverson.com/?p=179</guid>
		<description><![CDATA[Use your chart to indicate time of day.
LabVIEW charts, out of the box, don&#8217;t lend themselves to displaying the actual time of day.  By default they give you 1024 history points and a visible scale of 0-100 so what you see is in terms of sample numbers, having no relation to actual time. This is [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong><em>Use your chart to indicate time of day.</em></strong></p>
<p style="text-align: left;">LabVIEW charts, out of the box, don&#8217;t lend themselves to displaying the actual time of day.  By default they give you 1024 history points and a visible scale of 0-100 so what you see is in terms of sample numbers, having no relation to actual time. This is reasonable, given that the scale is adjustable in so many ways; there&#8217;s no way to guess what you want, so it&#8217;s up to you to tailor it to fit what you want.</p>
<p style="text-align: left;">Sometimes it&#8217;s useful to display the time of day on your charts, and keep that axis correctly updated as data flows in. For example:</p>
<p style="text-align: left;"><img class="alignnone size-full wp-image-183" title="ChartClock" src="http://culverson.com/site09/wp-content/uploads/2009/09/ChartClock1.PNG" alt="ChartClock" width="568" height="180" /></p>
<p style="text-align: left;">As you can see, the leading edge of the plots coincides with the current time on the clock  (see <a href="http://culverson.com/an-improved-analog-clock/" target="_blank">here</a> for how to do the clock indicator).   As data keeps coming in to this chart, the leading edge will reach the right side and the chart (and the X-axis scale) will scroll to the left, thus always matching the time of day.</p>
<p style="text-align: left;">
<p style="text-align: left;">Out of the box, a LabVIEW chart has a history of 1024 samples, and an X scale of 0-100 samples.  This scale has nothing to do with time, so if you want it to display the time, then you have to do several things to make it work.  If you have a CLEAR CHART function, triggered by a button or something, then attach this code to that action, otherwise just do it once when you start the data flowing  (Ideally, you should do this as you feed the first sample to the chart, but the few mSec difference that makes probably won&#8217;t matter).</p>
<p style="text-align: left;"><img class="alignnone size-full wp-image-181" title="ChartProperties" src="http://culverson.com/site09/wp-content/uploads/2009/09/ChartProperties.PNG" alt="ChartProperties" width="293" height="151" /></p>
<p style="text-align: left;">First, you clear the history.  That makes sure the OFFSET number is operating from an empty buffer (Time 0).  If the history buffer contains data, then the OFFSET applies to the end of it, and that&#8217;s not what you want.  The constant has to be an empty array of the same type of data as you feed to the chart (cluster of two DBLs in this case).</p>
<p style="text-align: left;">Next you set the XSCALE.OFFSET to set the OFFSET number to the current time.</p>
<p style="text-align: left;">Next you set the XSCALE.MULTIPLIER to the time (in sec) between samples that you display.</p>
<p style="text-align: left;">Next you set the XSCALE.MAXIMUM to now + the duration (in seconds) that you want the chart to show.</p>
<p style="text-align: left;">Do them in that order, or it could get confusing.  You also can set the CHART HISTORY LENGTH to match the duration / the display period.  For one minute at 2 Hz, that would be 120 samples.  You only need to do that step once &#8211; it&#8217;s a property that is not programmable.</p>
<p style="text-align: left;">
<p style="text-align: left;">Enjoy.</p>
<p style="text-align: left;">
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/keeping-your-charts-up-to-date/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>An Improved Analog Clock</title>
		<link>http://culverson.com/an-improved-analog-clock/</link>
		<comments>http://culverson.com/an-improved-analog-clock/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:58:35 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=53</guid>
		<description><![CDATA[Sometimes all that digital stuff is just too bland.
A bug undocumented feature of the original analog clock was that the markers on the scale were at intervals of 1.25 seconds, a consequence of LabVIEW preferring to use 4 intervals per major tick, when we silly humans use 5.  As a result, it looked a bit odd. [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em><strong>Sometimes all that digital stuff is just too bland.</strong></em></p>
<p>A <span style="text-decoration: line-through;">bug</span> <em>undocumented feature </em>of the <a title="original Analog Clock" href="http://culverson.com/an-analog-clock-first-version/" target="_blank">original analog clock</a> was that the markers on the scale were at intervals of 1.25 seconds, a consequence of LabVIEW preferring to use 4 intervals per major tick, when we silly humans use 5.  As a result, it looked a bit odd.  As I said then, if we’re going for an analog, then let’s go for the analog.</p>
<p>Attempts to coerce LabVIEW into making the scale the way we wanted were not successful; it has a long habit of thinking that four is a nice number and five is just an odd number, so I could not make it work.</p>
<p>So how do we improve it?  Simply disregard the built-in scale and substitute a picture.  After all, we all know where the numbers are on a clock face, if we’ve lined up the 0 and the 12 on our LabVIEW scales at the top of the circle, then all else has to fall into place.</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/Clock2Pic.png"><img class="aligncenter size-full wp-image-164" title="Clock2Pic" src="http://culverson.com/site09/wp-content/uploads/2009/08/Clock2Pic.png" alt="Clock2Pic" width="137" height="155" /></a></p>
<p>Click <a href="http://culverson.com/site09/wp-content/uploads/2009/09/Clock2llb.zip">here</a> to download the example LLB file, in LV 8.0 format. It has the same math VI as before (read the <a href="http://culverson.com/an-analog-clock-first-version/" target="_blank">previous post</a> for details), just the clock face is different.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/an-improved-analog-clock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operations en Masse</title>
		<link>http://culverson.com/operations-en-masse/</link>
		<comments>http://culverson.com/operations-en-masse/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 14:06:47 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Data Handling]]></category>
		<category><![CDATA[Easier Programming]]></category>
		<category><![CDATA[LabVIEW]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=56</guid>
		<description><![CDATA[The things that I used to do…
En masse is a French term meaning “as a whole” or “all together”; treating a group of something as a single unit.   LabVIEW has the ability to treat arrays this way, which can greatly reduce your workload. If you come to LabVIEW from a text-based language, it’s easy [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong><em>The things that I used to do…</em></strong></p>
<p style="text-align: left;"><em>En masse</em> is a French term meaning “as a whole” or “all together”; treating a group of something as a single unit.   LabVIEW has the ability to treat arrays this way, which can greatly reduce your workload. If you come to LabVIEW from a text-based language, it’s easy to miss the capabilities that are right at your fingertips.</p>
<p style="text-align: left;">For example, if you need to scale a series of readings into percent of the total (a procedure called normalizing),  then you tend to think:</p>
<p>I need to find the total:</p>
<ul>
<li>I need to start with a zero sum     <em>sum = 0.0;</em></li>
<li>I need to loop over every element  <em>for (int i = 0; i &lt; nElements; i++)</em></li>
<li>I need to add this element to the sum   <em>sum += array[i]</em></li>
</ul>
<p style="text-align: left;">Now I need to divide each entry by the total, to get the fraction of the total:</p>
<ul>
<li><em>for (int i = 0; i &lt; nElements; i++)</em></li>
<li><em>array[i] /= sum;</em></li>
</ul>
<p>Now I need to multiply by 100 to get percentages:</p>
<ul>
<li><em>for (int i = 0; i &lt; nElements; i++)</em></li>
<li><em>array[i] *= 100.0;</em></li>
</ul>
<p>That’s all well and good, and you could translate that literally into LabVIEW and it will get you the answer you want to see.  But that’s not the LabVIEW way of thinking.</p>
<p>What newcomers often fail to realize is that most primitive numeric functions (the ones with yellowish icons) will accept an array of numbers directly. This goes for basic arithmetic (add,subtract, multiply, divide), comparisons (greater than, less than, MAX/MIN), and many other operations.  It will happily multiply an array of numbers by a single scaler number, to produce an array of numbers.</p>
<p>This has great power to reduce the work that you do as the programmer. Consider the literal translation of the above code:</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-11.png"><img class="aligncenter size-full wp-image-166" title="EnMasse-11" src="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-11.png" alt="EnMasse-11" width="498" height="141" /></a></p>
<p>If that’s as good as it gets then why should I go with LabVIEW?</p>
<p>Well, it does get better.  There is a function in the numeric palette called ADD ARRAY ELEMENTS.  If we replace the entire first loop with this function, then we get to this:</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-21.png"><img class="aligncenter size-full wp-image-167" title="EnMasse-21" src="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-21.png" alt="EnMasse-21" width="476" height="145" /></a></p>
<p>Now for the <em>en masse</em> parts: You can replace the entire second loop with a single operation as well:</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-31.png"><img class="aligncenter size-full wp-image-168" title="EnMasse-31" src="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-31.png" alt="EnMasse-31" width="475" height="144" /></a></p>
<p>Any guesses what we can do with the third loop?    Yes, that’s right:</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-41.png"><img class="aligncenter size-full wp-image-169" title="EnMasse-41" src="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-41.png" alt="EnMasse-41" width="474" height="122" /></a></p>
<p>Now you have SO much more room to add comments about what you’re doing!</p>
<p>Now THIS is what makes you more productive in LabVIEW than in C; your chances for error are far less when you let the <em>en masse </em>operators handle the details, and you don’t even have to think about the details.</p>
<p>But be aware of what’s going on, however; there is no magic here.  Under the hood there is still a loop somewhere.  It’s now hidden somewhat; it’s not as obvious, but the work is still being done.  Don’t let the simplicity obscure the real processing that’s going on.</p>
<p>Here is an example of the normalizing function in use, from the real LabVIEW example examples\general\graphs\charts.llb\Draw Stacked Graph.vi (in LabVIEW 8.6. anyway).</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-5.PNG"><img class="aligncenter size-full wp-image-170" title="EnMasse-5" src="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-5.PNG" alt="EnMasse-5" width="194" height="203" /></a></p>
<p>This amounts to the same as our last part above.  In the example, the array given contains five elements and this is executed only once, so efficiency is not a concern.</p>
<p>But consider if the array was 10,000 elements. Don’t forget that the first operation is doing 10,000 divide operations, and the second is doing 10,000 multiplications.  Can you improve things?</p>
<p>Well, certainly! What you have to realize is that, by the associative property of numbers, (X / sum) * 100 is equal to (100 / sum) * X.  You also have to realize that 100 / sum, in this context, is a constant, and therefore needs to be calculated only once.  In effect, you are dividing by sum and multiplying by 100, but you are doing it 10,000 times!</p>
<p>With any luck at all, you get the same answer every time, so you only need to do it once:</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-6.png"><img class="aligncenter size-full wp-image-172" title="EnMasse-6" src="http://culverson.com/site09/wp-content/uploads/2009/08/EnMasse-6.png" alt="EnMasse-6" width="443" height="119" /></a></p>
<p>THIS is why we use LabVIEW!</p>
<p><strong>NOTE</strong>:  <em>En masse </em>is my term for this feature, it is not an official LabVIEW term.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/operations-en-masse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delays, delays, delays</title>
		<link>http://culverson.com/delays-delays-delays/</link>
		<comments>http://culverson.com/delays-delays-delays/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 15:33:44 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Data Handling]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=66</guid>
		<description><![CDATA[Can’t you signals just work together?
Usually, in a data acquisition program,  all the signals you measure are “live”, meaning they represent the current conditions at the time they are sampled. However, in some cases you might have some signals which are not live, but delayed. For example, suppose you’re measuring engine operation, and you have [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong><em>Can’t you signals just work together?</em></strong></p>
<p style="text-align: left;">Usually, in a data acquisition program,  all the signals you measure are “live”, meaning they represent the current conditions at the time they are sampled. However, in some cases you might have some signals which are not live, but delayed. For example, suppose you’re measuring engine operation, and you have gas analyzers sampling the exhaust airstream. These analyzers conduct the gas from the measurement point in the airflow system around the engine to the analyzer mechanism itself. This gas flows through the sampling tubing at a specific rate, and therefore arrives at the sample point at a specific time AFTER it left the main airstream. These delays might be multiple seconds in duration.  There could be other reasons for this delay, such as an echo-measuring device, or the mechanical response time of some piece of hardware.</p>
<p style="text-align: left;">For analysis purposes, you want to look at the engine holistically and see causes and effects. If the speed changed at a particular point in time, you want to see the CO concentration change as a consequence. But unless you do something to compensate, the change in gas concentration will lag far behind the change in speed that caused it in graphs and tables, making it difficult to judge consequences.</p>
<p style="text-align: left;">To arrange the signals back into time-synchronous alignment, the solution is to think of ALL signals has having TWO delay lines: one physical, and one logical.  In our example case, the physical part is the gas piping conducting the gas. The logical part is completely within the  DAS software. If EVERY channel has a physical delay time (even if it’s zero), and if EVERY channel also has a logical delay time (even if it’s zero), and if EVERY channel has the sum of the physical delay time and the logical delay time equal to a constant, then the signals coming out of the logical delay lines will be time-aligned.</p>
<h4>Example</h4>
<p style="text-align: left;">For example, consider three channels: Channel A records data “live”, i.e. no delay. Channel B has a delay of 3 seconds. Channel C has a delay of 5 seconds.</p>
<p style="text-align: left;">We want to make the entire chain (physical + logical) the same length for all channels, so we pick the longest delay (5 sec) and make that our total delay time. For channel A, which has no physical delay, we have to have a logical delay of 5 sec. For channel B, which has a physical delay of 3 sec, we add a logical delay of 2 sec for a total of 5. For channel C, which has a physical delay of 5 seconds, we have a logical delay of zero. 5+0 = 3+2 = 0+5, so every channel has the same delay, when we count both physical and logical.</p>
<p style="text-align: left;">The logical delay is implemented in queues with every channel having its own queue. Every sample received goes into a queue belonging to that channel; and we pull out one sample from the end of the queue to be recorded. Since one goes in and one comes out, the length of the queue never changes. The initial length of the queue corresponds to the delay time we need for a particular channel. If a queue is empty (of zero length), then the sample we put in and the sample we take out are the same sample. If the queue is of length 10, then the sample we get out was taken 10 sample times ago.</p>
<p>At configuration time, the queues are set up, and populated with zero values to set their length according to how much delay is required. After that, the sample process means putting a sample into a queue and taking one out for use.  Every channel operates the same when actually sampling, it’s only the configuration where they differ.</p>
<p>Note that if you are recording a TIMESTAMP value, then the TIMESTAMP signal requires its own queue as well, so that it comes out in alignment with the signals. Of course this means that the data does not become usable until all the zeroes have been flushed out of the queues. That will happen when the longest delay time has expired. We can judge this by putting a RECORD signal into its own queue. We don’t actually record data coming out of the queues until the RECORD signal coming out is true.</p>
<p>You can keep the data flowing into (and out of) these queues all the time.  When you want to start recording, set the RECORD flag TRUE. When you want to stop recording, set the RECORD flag FALSE.  Pay attention to the value out of the RECORD flag’s queue, and act appropriately. (Don’t act on the RECORD flag itself, act on the delayed RECORD flag).</p>
<p>This also means that when the test is over, there is still data remaining in the queues. We have to keep recording until the valuable data has worked it’s way through the queues, meaning 5 seconds after the last sample (in the example case).</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/delays-delays-delays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About Type Definitions</title>
		<link>http://culverson.com/about-type-definitions/</link>
		<comments>http://culverson.com/about-type-definitions/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 15:35:28 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[Easier Programming]]></category>
		<category><![CDATA[LabVIEW]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=68</guid>
		<description><![CDATA[The types, they are a-changin’
LabVIEW beginners often either don’t know about type definitions, or don’t appreciate their value. This article will attempt to explain their use and how they can save you boatloads of time and effort.
Suppose you have a cluster of items that’s very handy to your project. For the sake of discussion, we’ll [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em><strong>The types, they are a-changin’</strong></em></p>
<p>LabVIEW beginners often either don’t know about type definitions, or don’t appreciate their value. This article will attempt to explain their use and how they can save you boatloads of time and effort.</p>
<p>Suppose you have a cluster of items that’s very handy to your project. For the sake of discussion, we’ll call it a <em>channel</em>, and assume this is a data acquisition project. A channel might have these items:</p>
<ul>
<li>Channel Name</li>
<li>Active switch</li>
<li>Scale factor</li>
<li>Units</li>
</ul>
<p>So, suppose you have an array of these to match the channels on your MIO DAQ board.</p>
<p>You might develop a series of VIs that deal with <em>channel</em>s:</p>
<ul>
<li>You need an editor, so the user can rename them, select which ones to use, and scale them;</li>
<li>You need a VI that takes an array of <em>channel</em>s, and configures the hardware;</li>
<li>You need to print the setup, so a VI takes an array of <em>channel</em>s and formats a page for printing;</li>
<li>You need to export the data to a spreadsheet, so another VI takes the array of <em>channel</em>s and produces a spreadsheet.</li>
</ul>
<p>and so on. You’ve defined the cluster and all these subVIs and it all works.</p>
<p>Now, though, you realize that you need to add another item to the <em>channel</em>, namely OFFSET. You have a new 4-20mA transducer which produces a 1-5V signal when you use the right resistor. So, instead of the single SCALE FACTOR (which assumes 0.0EU at 0.0 Volts), you implement the standard linear equation Y = mX + b, where X is the measured voltage, m is the SCALE FACTOR (slope), b is the OFFSET, and Y is the resulting Engineering Units (EU). How do you go about it?</p>
<p>The brute force way to go about it is to open up every instance of the cluster you used, and add an OFFSET term to the cluster. OUCH! In the example, you have 4-8 instances; that’s painful enough, but imagine if you had 50!</p>
<p>A slightly (<em>slightly</em>) more civilized way is to add the OFFSET term to one cluster somewhere, then copy the cluster, and paste it over all the old instances.</p>
<p>One of the good things about LabVIEW is that you can follow all the broken RUN arrows and figure out the places you missed. But is this really what computers are for? After all, LabVIEW knows all these things are broken, it knows WHY they are broken, but it’s YOU that has to chase them all down. So, do this a few dozen times and you might start wishing for a better way.</p>
<h3>A Better Way</h3>
<p>Enter the TYPEDEF, short for Type Definition. A Typedef is a “master” control. To use it, you ask for a new custom control (File | New | Custom Control). Here’s where you define the cluster you want for a channel. The first time you would use the four items mentioned initially. You then set the control menu to STRICT TYPEDEF, and SAVE the file with a name like CHANNEL.ctl. Now, every time you want to use it, you use the SELECT A CONTROL option on the panel palette and choose that file. What you get is a cluster that looks just like the one you made originally. Place one on your VI for exporting, another on the VI for printing, etc., etc. You can copy and paste them just like anything else.</p>
<p>So far, there’s nothing different. Where the value come in is when you need to change it. You may notice that you can’t change the cluster on your export VI. Drag something on top of it, and the something just sits there, on top. It doesn’t get put “into” the cluster. If yuo really do want to change it, you open the CTL file. You can do this thru the FILE menu, or notice that every instance has an OPEN TYPE DEF entry in the pop-up menu now.</p>
<p>If you open the CTL file, you can add the OFFSET term there, and SAVE it. When you do, EVERY INSTANCE of that control/indicator updates to follow! Open any of your VIs that used it, and it will have the OFFSET term in it! You’ve just changed 4-8 (or 40-80) controls in one whack. This is convenient for this example, but on a larger program, it is absolutely essential.</p>
<p>Another use for them is in ENUMs. Suppose you have an ENUM for units, with the options “PSI, kPA, mmHG, InH2O”. You can create that, and copy and paste it wherever you need it, but if you have to add something to the list, you’re in the same boat as the cluster, above. The answer is the same, make it a TYPEDEF, and use the TYPEDEF wherever you need to. Then when it’s changing time, all the instances update at once.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/about-type-definitions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Analog Clock (first version)</title>
		<link>http://culverson.com/an-analog-clock-first-version/</link>
		<comments>http://culverson.com/an-analog-clock-first-version/#comments</comments>
		<pubDate>Thu, 07 May 2009 16:07:35 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=101</guid>
		<description><![CDATA[Sometimes all that digital stuff is just too bland.
If you want to display a time-of-day clock in LabVIEW, it takes three seconds to plop down a TIMESTAMP indicator, and 10 more seconds to enter ADVANCED EDITING mode, and skip the month, day and year, and format it the way you want. Piece of cake.
And it [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em><strong>Sometimes all that digital stuff is just too bland.</strong></em></p>
<p style="text-align: left;">If you want to display a time-of-day clock in LabVIEW, it takes three seconds to plop down a TIMESTAMP indicator, and 10 more seconds to enter ADVANCED EDITING mode, and skip the month, day and year, and format it the way you want. Piece of cake.</p>
<p style="text-align: left;">And it looks just exactly like every other digital clock out there: six digits, two colons, everybody knows what it means. And that’s fine for a lot of purposes.</p>
<p style="text-align: left;">But sometimes you like to decorate your work a little bit. If you’ve got space on a front panel, and a few cycles of execution time in your run loop, then consider an analog clock.</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/05/clock.png"><img class="aligncenter size-full wp-image-174" title="clock" src="http://culverson.com/site09/wp-content/uploads/2009/05/clock.png" alt="clock" width="160" height="163" /></a></p>
<p>The visual part of this is pretty simple: a custom control with a cluster of three gauges, all with their scales stretched to a full 360° and both ends of the scale at the top:</p>
<ul>
<li>A gauge indicator in the back: single dark red needle, and the scale set to 0..12.</li>
<li>A gauge indicator with an INVISIBLE scale of 0..60, and a bright red needle for minutes.</li>
<li>A gauge indicator with an INVISIBLE scale of 0..60, and a gray needle for seconds.</li>
</ul>
<p>The three indicators are sized identically and lined up identically, with transparent backgrounds, so the needles show through.</p>
<h4>An analog is an analogy</h4>
<p>You might think it’s straightforward to use this thing – just pass a cluster of hours, minutes, and seconds to the indicator, and you’re done.</p>
<p>You’d be wrong.</p>
<p>Consider what would happen: at 9:22:10, as shown above, the hour hand would be EXACTLY on the 9, the minute hand EXACTLY on the 22. Not exactly what you would expect from an analog clock. It’s even worse 35 minutes later: the minute hand would be on the 57, but the hour hand is still EXACTLY on the 9. It looks for all the world like it’s three minutes before nine, but it’s actually 9:57. If you’re going for the analog, then you’ve got to do better than that.</p>
<p>The gauges accept floating point numbers, so we’re in luck. If you think of how an analog clock works, it’s not the same as a digital clock (and you can quote me on that!). The second hand may move smoothly around the dial, or it may snap from one second to the next. We choose the snap idea, as it’s easier. But the minute hand definitely does NOT snap – it moves smoothly.</p>
<p>So we have to incorporate the position of the SECOND hand into the position of the MINUTE hand. Namely, we add SECONDS / 60 to the MINUTES value given, so that 6:30 will be halfway between 6 and 7, and 6:57 will be just before 7. Similarly, we have to incorporate the position of the MINUTE hand into the position of the HOURS hand so that 6:30:00 puts the hour hand at 6.5, halfway between 6 and 7.</p>
<h3>Download</h3>
<p>Click to download the <a href="http://culverson.com/site09/wp-content/uploads/2009/09/clockllb.zip">example</a> (about 12kB ZIP), containing the typedef indicator you can put on your panel, and a VI to do the above math for it. You can display the CURRENT time by leaving the TIME input unwired, or display a specific time by supplying a timestamp.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/an-analog-clock-first-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
