<?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>PC Based Automation &#187; API</title>
	<atom:link href="http://www.dajac.com/blog/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dajac.com/blog</link>
	<description>Exploring all aspects of PC based automation.</description>
	<lastBuildDate>Sun, 29 Aug 2010 16:25:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use Microsoft Office for Your Next Automation Project</title>
		<link>http://www.dajac.com/blog/2010/08/29/microsoft-office-automation/</link>
		<comments>http://www.dajac.com/blog/2010/08/29/microsoft-office-automation/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 16:02:02 +0000</pubDate>
		<dc:creator>David Novak</dc:creator>
				<category><![CDATA[I/O Modules]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Expert I/O]]></category>
		<category><![CDATA[Macro]]></category>
		<category><![CDATA[Microsoft Office]]></category>
		<category><![CDATA[pc based automation]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[Visual Basic for Applications]]></category>
		<category><![CDATA[Word]]></category>

		<guid isPermaLink="false">http://www.dajac.com/blog/?p=475</guid>
		<description><![CDATA[If a software development platform can call a DLL, it can be used to control the Expert I/O 1000. Microsoft Office with Visual Basic for Applications (VBA) is no exception.
For most people, Office would be the last tool they would consider for PC based automation, but in some cases it might be the best. For [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_488" class="wp-caption alignright" style="width: 130px"><img src="http://www.dajac.com/blog/wp-content/uploads/2010/08/ms_office_logo.jpg" alt="Microsoft Office" title="Microsoft Office" width="120" height="103" class="size-full wp-image-488" /><p class="wp-caption-text">Automate with Office</p></div></p>
<p>If a software development platform can call a DLL, it can be used to control the Expert I/O 1000. Microsoft Office with Visual Basic for Applications (VBA) is no exception.</p>
<p>For most people, Office would be the last tool they would consider for PC based automation, but in some cases it might be the best. For example, you could easily log data to an Excel spreadsheet or Access database as you collect it and once it&#8217;s in these applications, it&#8217;s simple to manipulate, plot and report the data.</p>
<p><span id="more-475"></span></p>
<p>Office provides two big advantages.</p>
<ol>
<li>Low start up cost.</li>
<li>Short learning curve.</li>
</ol>
<p>The main advantage of Office is its low start up cost. Practically every computer in existence has Microsoft Office installed. If you don&#8217;t need the features of a full fledged software development suite, you can save a bunch of money by using a tool that is already on your computer.</p>
<p>The other big advantage of Office is that many people who aren&#8217;t software engineers know a great deal about VBA. It is used all the time for office automation by non-engineers. Microsoft has given us a development tool that can be used by everyone, not just geeky software engineers.</p>
<p>Controlling the Expert I/O using VBA in Excel is very easy. Here is the entire code of a VBA macro I created. The entire subroutine is only about a dozen lines.
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #008000;">' Expert I/O API.<br />
</span> &nbsp; &nbsp; <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> eioOpen <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;eio.dll&quot;</span> () <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> eioClose <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;eio.dll&quot;</span> () <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> eioClaimInterfaceEz <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;eio.dll&quot;</span> (<span style="color: #000080;">ByVal</span> ModelId <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>, <span style="color: #000080;">ByVal</span> SerialNumber <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByRef</span> Handle <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> eioReleaseInterface <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;eio.dll&quot;</span> (<span style="color: #000080;">ByVal</span> Handle <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> eioDioSetPull <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;eio.dll&quot;</span> (<span style="color: #000080;">ByVal</span> Handle <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByVal</span> Port <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByVal</span> PullLevel <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> eioDioSet <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;eio.dll&quot;</span> (<span style="color: #000080;">ByVal</span> Handle <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByVal</span> Port <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByVal</span> PinLevels <span style="color: #000080;">As</span> <span style="color: #000080;">Byte</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Declare</span> <span style="color: #000080;">Function</span> eioDioGet <span style="color: #000080;">Lib</span> <span style="color: #800000;">&quot;eio.dll&quot;</span> (<span style="color: #000080;">ByVal</span> Handle <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByVal</span> Port <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span>, <span style="color: #000080;">ByRef</span> PinLevels <span style="color: #000080;">As</span> <span style="color: #000080;">Byte</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">' Constants<br />
</span> &nbsp; &nbsp; <span style="color: #000080;">Const</span> MODEL_ID <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span> = 1<br />
&nbsp; &nbsp; <span style="color: #000080;">Const</span> SERIAL_NUMBER <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span> = 99<br />
&nbsp; &nbsp; <span style="color: #000080;">Const</span> INPUT_PORT <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span> = 0<br />
&nbsp; &nbsp; <span style="color: #000080;">Const</span> OUTPUT_PORT <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span> = 2<br />
&nbsp; &nbsp; <span style="color: #000080;">Const</span> eioDIO_PULL_3_3 <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span> = 1<br />
&nbsp; &nbsp; <span style="color: #000080;">Const</span> eioDIO_PULL_GND <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span> = 2<br />
&nbsp; &nbsp; <br />
<span style="color: #000080;">Sub</span> DigitalIo()<br />
&nbsp; &nbsp; <span style="color: #000080;">Dim</span> Handle <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Dim</span> PinLevels <span style="color: #000080;">As</span> <span style="color: #000080;">Byte</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Dim</span> ReturnCode <span style="color: #000080;">As</span> <span style="color: #000080;">Long</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">' Open API and get handle. Normally, this would be done only once at the<br />
</span> &nbsp; &nbsp; <span style="color: #008000;">' beginning of the program. It has been included here to keep the<br />
</span> &nbsp; &nbsp; <span style="color: #008000;">' example as simple as possible.<br />
</span> &nbsp; &nbsp; ReturnCode = eioOpen()<br />
&nbsp; &nbsp; ReturnCode = eioClaimInterfaceEz(MODEL_ID, SERIAL_NUMBER, Handle)<br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">' Set digital pulls.<br />
</span> &nbsp; &nbsp; ReturnCode = eioDioSetPull(Handle, INPUT_PORT, eioDIO_PULL_3_3)<br />
&nbsp; &nbsp; ReturnCode = eioDioSetPull(Handle, OUTPUT_PORT, eioDIO_PULL_3_3)<br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">' Set output levels equal to cell in spreadsheet.<br />
</span> &nbsp; &nbsp; PinLevels = Cells(3, 5)<br />
&nbsp; &nbsp; ReturnCode = eioDioSet(Handle, OUTPUT_PORT, PinLevels)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">' Get input levels and set spreadsheet cell to the value read.<br />
</span> &nbsp; &nbsp; ReturnCode = eioDioGet(Handle, INPUT_PORT, PinLevels)<br />
&nbsp; &nbsp; Cells(5, 5).Value = PinLevels<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">' Clean up. Normally, this would be done only once at the end of the<br />
</span> &nbsp; &nbsp; <span style="color: #008000;">' program. It has been included here since we included eioOpen() and<br />
</span> &nbsp; &nbsp; <span style="color: #008000;">' eioClaimInterfaceEz() in this subroutine.<br />
</span> &nbsp; &nbsp; ReturnCode = eioReleaseInterface(Handle)<br />
&nbsp; &nbsp; ReturnCode = eioClose()<br />
<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></div></td></tr></tbody></table></div>
<p>Lines 27 and 28 initialize the Expert I/O API. Lines 31 and 32 set the output voltage level and input pull up state. These lines would normally be placed in a subroutine that runs once at the beginning of the macro. The initialization does not need to be performed for every I/O access.</p>
<p>Lines 35 and 36 set a digital output port to the value in the spreadsheet at E3.</p>
<p>Lines 39 and 40 read a digital input port and write its value to the spreadsheet at E5.</p>
<p>The interface is released and the API is closed with lines 45 and 46. As with the initialization, this cleanup only needs to be performed once at the end of the macro.</p>
<p>As you can see, writing a VBA macro to control the Expert I/O is an incredibly simple task. So for your next automation project, don&#8217;t forget to consider Microsoft Office. It might be just what you need.</p>
<p><a href="http://www.dajac.com/files/excel_vba_digital_io.zip">Click here</a> to download the Excel file that contains this macro.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dajac.com/blog/2010/08/29/microsoft-office-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PC Automated Pressure Measurements</title>
		<link>http://www.dajac.com/blog/2009/10/23/pc-automated-pressure-measurements/</link>
		<comments>http://www.dajac.com/blog/2009/10/23/pc-automated-pressure-measurements/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 18:18:01 +0000</pubDate>
		<dc:creator>David Novak</dc:creator>
				<category><![CDATA[I/O Modules]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Expert I/O]]></category>
		<category><![CDATA[measure]]></category>
		<category><![CDATA[pressure]]></category>
		<category><![CDATA[process control]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[sensor]]></category>

		<guid isPermaLink="false">http://www.dajac.com/blog/?p=342</guid>
		<description><![CDATA[One of the vivid memories from my childhood is working in the garden picking vegetables. We lived on a farm and it was common to have a big garden. My mother would can all types of food, such as tomatoes, pickles and green beans. Part of this canning process involved boiling the jars of food [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_354" class="wp-caption alignright" style="width: 105px"><img src="http://www.dajac.com/blog/wp-content/uploads/2009/10/pressure_cooker.png" alt="Pressure Cooker" title="Pressure Cooker" width="95" height="95" class="size-full wp-image-354" /><p class="wp-caption-text">Pressure Cooker</p></div></p>
<p>One of the vivid memories from my childhood is working in the garden picking vegetables. We lived on a farm and it was common to have a big garden. My mother would can all types of food, such as tomatoes, pickles and green beans. Part of this canning process involved boiling the jars of food in a pressure cooker. The release valve, with its hot hissing steam escaping, always intrigued me.</p>
<p>Canning food in the kitchen is a relatively simple process and easily controlled by the cook, but there are many other applications where it makes sense to automate the process.<span id="more-342"></span> For instance, you may have a process where it is important to know the exact pressure at a specific point in a process and, based on that pressure, control other parameters of the system.</p>
<p>Another example where automation would be ideal is monitoring pressure over time. You could manually take measurements at a given period over some number of hours, but it makes much more sense to automate and let the monitoring equipment record the measurements while you do other things. Because it is automated, this method is more precise and allows you to immediately analyze the data.</p>
<p>The first thing needed for measuring pressure is a pressure sensor. There are many sensors available with analog voltage outputs. These can be used with the Expert I/O 1000 by connecting the sensor&#8217;s analog output to an analog input on the Expert I/O 1000. The Expert I/O 1000 has six 0-5V analog inputs and it isn&#8217;t difficult to find pressure sensors with 0-5V outputs.</p>
<p>To properly specify the pressure sensor, the following parameters must be defined.</p>
<ul>
<li>Pressure range being measured.</li>
<li>Accuracy required.</li>
<li>Pressure fitting. How it attaches to the object being measured (1/4&#8243; pipe thread is the most common).</li>
<li>Electrical termination (connector or direct to cable).</li>
</ul>
<p>With these specifications in hand, you are now ready to shop for a sensor. Here are links to a few vendors that carry pressure sensors.</p>
<ul>
<li><a href="http://www.pewastore.com/index.asp?PageAction=VIEWCATS&#038;Category=11">PewaStore.com</a> </li>
<li><a href="http://www.omega.com/guides/pressXducers.html">Omega</a> (Choose output = Volt)</li>
<li><a href="http://stellartech.com/techsheets-press/pressuremodels.html">Stellar Technology</a></li>
<li><a href="http://www.emssensors.com/press/press.htm">Engineering and Manufacturing Services</a></li>
<li><a href="http://www.astsensors.com/pressure-sensor-products.php">American Sensor Technologies</a></li>
<li><a href="http://www.granzow.com/pressuretransmitters/">Granzow</a></li>
<li><a href="http://www.transducersdirect.com/HeleoCart/ProductCategory/Pressure+Transducer%2826%29.aspx">Transducers Direct</a></li>
<li><a href="http://devar.thomasnet.com/viewitems/level-and-pressure/level-and-pressure-transmitters?&#038;forward=1">DEVAR</a></li>
</ul>
<p>For easiest connection to the Expert I/O 1000, you&#8217;ll want to get a sensor with 0-5V analog output, but you probably noticed that another common output is 4-20mA. These can also be used with the Expert I/O 1000 by adding a 250 Ohm resistor from the output signal to ground. Adding the resistor converts the 4-20mA signal to a 1-5V signal. It&#8217;s not hard to deal with the 1V offset in software. The ground terminal next to each of the Expert I/O 1000 analog input terminals provide a convenient place to ground the 250 Ohm resistor.</p>
<p><div id="attachment_356" class="wp-caption aligncenter" style="width: 460px"><img src="http://www.dajac.com/blog/wp-content/uploads/2009/10/convert_4-20ma_to_1-5V.png" alt="Use a 250 Ohm resistor to ground to convert a 4-20mA output to 1-5V." title="Convert 4-20mA to 1-5V" width="450" height="310" class="size-full wp-image-356" /><p class="wp-caption-text">Use a 250 Ohm resistor to ground to convert a 4-20mA output to 1-5V.</p></div></p>
<p>Now that you have a sensor picked out, all that is left is to write a little software. Here is a snippet of code that initializes the Expert I/O 1000, samples an analog input and then exits.</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Open the Expert I/O API.</span><br />
eioOpen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Scan the USB and gather descriptors.</span><br />
eioGetDescriptors<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>DescriptorGroup <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Claim the interface.</span><br />
eioClaimInterface<span style="color: #009900;">&#40;</span> DescriptorGroup.<span style="color: #202020;">Descriptors</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>EioHandle <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Read analog input 1.</span><br />
eioAdcReadCount<span style="color: #009900;">&#40;</span> EioHandle<span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>AdcCount <span style="color: #009900;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Release the interface.</span><br />
eioReleaseInterface<span style="color: #009900;">&#40;</span> EioHandle <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Close the Expert I/O API.</span><br />
eioClose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>If you read <a href="http://www.dajac.com/blog/2009/10/10/expert-io-api/">Between Mac and PC: The Expert I/O API</a>, much of the code will be familiar to you. I&#8217;ll go through it again for those that didn&#8217;t read the article.</p>
<p>Lines 1 through 8 are initialization and only need to be executed once. The initialization starts with calling <code class="codecolorer c default"><span class="c">eioOpen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code>. This allows the API to configure its internal settings and ready itself for communicating on the USB.</p>
<p>The next step is to call <code class="codecolorer c default"><span class="c">eioGetDescriptors<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> to scan each USB bus and locate all Expert I/O devices. It returns a <code class="codecolorer c default"><span class="c">DescriptorGroup</span></code> which contains an array of <code class="codecolorer c default"><span class="c">Descriptors<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span></span></code>. Each descriptor in <code class="codecolorer c default"><span class="c">Descriptors<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span></span></code> describes an Expert I/O found connected to the USB.
<p>Descriptors contain a model ID and a serial number. By inspecting the descriptors, you can locate the specific Expert I/O you wish to access. For the purpose of this example, we simply choose the first device found on the bus. On line 8, we use the first descriptor to obtain a handle to the device.</p>
<p>A device&#8217;s handle is exactly as it sounds. It is a &#8220;handle&#8221; to grab hold of the Expert I/O to control it. The handle is used every time you perform an operation on the device.</p>
<p>Line 8 serves another purpose, it claims the Expert I/O&#8217;s interface for exclusive use by our application. This is important, because the last thing you want is 2 applications trying to control the same Expert I/O simultaneously. Applications can share access to an Expert I/O, but no more than one application at a time can claim it&#8217;s interface.</p>
<p>Now we are ready to read the analog input. Line 11 reads analog input 3 by calling <code class="codecolorer c default"><span class="c">eioAdcReadCount</span></code> and places the result into AdcCount. AdcCount contains a value between 0 and 255, linearly related to the input voltage. If the input voltage is 0V, AdcCount will be 0. If the input voltage is 5V, AdcCount will be 255. AdcCount will vary linearly with the input voltage between 0 and 5V. Notice how we use the handle to identify the Expert I/O.</p>
<p>At this point, you can use AdcCount as needed. For instance, you could make a decision, based on the value of AdcCount, to activate an output or you could plot the time and value on a chart. The possibilities are endless.</p>
<p>When finished accessing the Expert I/O and ready to relinquish control of its interface, call <code class="codecolorer c default"><span class="c">eioReleaseInterface<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> (line 14 in our example). With the interface released, it is now accessible to other applications that wish to claim it.</p>
<p>The last thing to do is to notify the API that we are finished using it. This is done on line 17 with a call to <code class="codecolorer c default"><span class="c">eioClose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code>. Closing the API allows it to release any memory that it has allocated and to shut down in a structured manor.</p>
<p>That&#8217;s it. Now you know how to measure pressure using the Expert I/O 1000. It&#8217;s equally easy to monitor other characteristics. In a future article, I&#8217;ll go through the process of measuring temperature.</p>
<p>Please post questions and comments below.</p>
<hr />
<p><span style="font-weight:bold;">Think USB requires you to be shackled to a computer no more than 5 meters away?</span> Think again. This free guide and cheat sheet will show you the light: “TIED IN KNOTS – A Must-Have Guide to Untangling USB Extension Options for PC Based Automation”. <a href="http://www.dajac.com/usb-extension">Get it now!</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dajac.com/blog/2009/10/23/pc-automated-pressure-measurements/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Between Mac and PC: The Expert I/O API</title>
		<link>http://www.dajac.com/blog/2009/10/10/expert-io-api/</link>
		<comments>http://www.dajac.com/blog/2009/10/10/expert-io-api/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 02:50:22 +0000</pubDate>
		<dc:creator>David Novak</dc:creator>
				<category><![CDATA[I/O Modules]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Expert I/O]]></category>

		<guid isPermaLink="false">http://www.dajac.com/blog/?p=148</guid>
		<description><![CDATA[PC based automation doesn&#8217;t need to be difficult. Some application user interfaces are terribly complicated and take forever to learn. Often, even the simple interfaces prove difficult because they make some features impossible to use so that other features are simple.
I see this all the time in products. The Mac vs PC battle (which is [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_334" class="wp-caption alignright" style="width: 94px"><img src="http://www.dajac.com/blog/wp-content/uploads/2009/10/mac-pc-s.png" alt="Mac vs PC" title="Expert I/O API is Just Right" width="84" height="95" class="size-full wp-image-334" /><p class="wp-caption-text">Mac vs PC</p></div></p>
<p>PC based automation doesn&#8217;t need to be difficult. Some application user interfaces are terribly complicated and take forever to learn. Often, even the simple interfaces prove difficult because they make some features impossible to use so that other features are simple.</p>
<p>I see this all the time in products. The Mac vs PC battle (which is really Apple vs Microsoft) is a perfect example.<span id="more-148"></span> Both have essentially equivalent hardware power, but they take very different approaches to the user interface. Microsoft gives you access to every option under the sun, while Apple only gives you access to the options that 80% of people use regularly.</p>
<p>Microsoft products generally take longer to understand, but once you get it, you can do whatever you want. Apple gets you off the ground quickly, but if you are a power user, you will tend to be frustrated by a system that holds you back.</p>
<p>The Expert I/O application programmer&#8217;s interface (API) is a good mix between these two extremes. It is simple to learn and at the same time doesn&#8217;t hold you back.</p>
<p>Right from the start, your life is made easy by allowing you to use your favorite programming language. The only stipulation is that it must support the use of dynamic link libraries (DLL&#8217;s) and it&#8217;s hard to find a language that doesn&#8217;t. You can use Visual Basic, C, C++, Delphi, Pascal, etc. You can even use scripting languages such as PHP and Python. Wouldn&#8217;t that be cool, a remote accessible web application built with PHP to control a PC based automation system.</p>
<p>Here is a simple example of using C to set a digital output high.</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Open the Expert I/O API.</span><br />
eioOpen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Scan the USB and gather descriptors.</span><br />
eioGetDescriptors<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>DescriptorGroup <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Claim the interface.</span><br />
eioClaimInterface<span style="color: #009900;">&#40;</span> DescriptorGroup.<span style="color: #202020;">Descriptors</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>EioHandle <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Set digital output voltage high to 3.3V.</span><br />
eioDioSetPull<span style="color: #009900;">&#40;</span> EioHandle<span style="color: #339933;">,</span> 2<span style="color: #339933;">,</span> eioDIO_PULL_3_3 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Set bit 0 of port 2 high.</span><br />
eioDioSet<span style="color: #009900;">&#40;</span> EioHandle<span style="color: #339933;">,</span> 2<span style="color: #339933;">,</span> 1 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Release the interface.</span><br />
eioReleaseInterface<span style="color: #009900;">&#40;</span> EioHandle <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Close the Expert I/O API.</span><br />
eioClose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Lines 1 through 8 are initialization and only need to be executed once. The initialization starts with calling <code class="codecolorer c default"><span class="c">eioOpen<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code>. This allows the API to configure its internal settings and ready itself for communicating on the USB.</p>
<p>The next step is to call <code class="codecolorer c default"><span class="c">eioGetDescriptors<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> to scan each USB bus and locate all Expert I/O devices. It returns a <code class="codecolorer c default"><span class="c">DescriptorGroup</span></code> which contains an array of <code class="codecolorer c default"><span class="c">Descriptors<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span></span></code>. Each descriptor in <code class="codecolorer c default"><span class="c">Descriptors<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span></span></code> describes an Expert I/O found connected to the USB.
<p>Descriptors contain a model ID and a serial number. By inspecting the descriptors, you can locate the specific Expert I/O you wish to access. For the purpose of this example, we simply choose the first device found on the bus. On line 8, we use the first descriptor to obtain a handle to the device.</p>
<p>A devices handle is exactly as it sounds. It is a &#8220;handle&#8221; to grab hold of the Expert I/O to control it. The handle is used every time you perform an operation on the device.</p>
<p>Line 8 serves another purpose, it claims the Expert I/O&#8217;s interface for exclusive use by our application. This is important, because the last thing you want is 2 applications trying to control the same Expert I/O simultaneously. Applications can share access to an Expert I/O, but no more than one application at a time can claim it&#8217;s interface.</p>
<p>Now we are ready to start controlling the Expert I/O. Line 11 configures a digital output (port 2) to 3.3V logic high (<code class="codecolorer c default"><span class="c">eioDIO_PULL_3_3</span></code>). Notice how we use the handle to identify the Expert I/O.</p>
<p>Line 14 is the line that causes the digital output to change states. It sets bit 0 of port 2 high. Each port consists of 8 pins and each pin is associated with a bit in an 8-bit value. The 1 in this function call puts a 1 in the bit 0 position of the port (binary 1 is 00000001) and thereby forces its associated pin to logic high.</p>
<p>At this point, you can include code to control any other ports on the Expert I/O as you see fit.</p>
<p>When finished accessing the Expert I/O and ready to relinquish control of its interface, call <code class="codecolorer c default"><span class="c">eioReleaseInterface<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> (line 17 in our example). With the interface released, it is now accessible to other applications that wish to claim it.</p>
<p>The last thing to do is to notify the API that we are finished using it. This is done on line 20 with a call to <code class="codecolorer c default"><span class="c">eioClose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code>. Closing the API allows it to release any memory that it has allocated and to shut down in a structured manor.</p>
<p>This is only a small example, but once it is in place and working, expanding it to control other I/O ports is very easy. There is a set of simple interface functions for each I/O type (motor, analog in, analog out, etc.). These are explained in complete detail in the <a href="http://www.dajac.com/files/eio_software_manual.pdf">software user manual</a>.</p>
<p>If you have questions or comments, please post them below.</p>
<p>&nbsp;</p>
<hr />
<p>Struggling with extending the USB connection? Be sure to check out <a href="http://www.dajac.com/usb-extension">TIED IN KNOTS – A Must-Have Guide to Untangling USB Extension Options for PC Based Automation</a>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dajac.com/blog/2009/10/10/expert-io-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
