<?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>Unitronics &#8211; Sandy Scott&#039;s Web Spot</title>
	<atom:link href="https://www.sandyscott.net/tag/unitronics/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sandyscott.net</link>
	<description>My little corner of the web</description>
	<lastBuildDate>Mon, 28 Sep 2020 10:45:26 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>UniLogic INT/REAL conversion blocks</title>
		<link>https://www.sandyscott.net/2020/09/unilogic-int-real-conversion-blocks/</link>
					<comments>https://www.sandyscott.net/2020/09/unilogic-int-real-conversion-blocks/#respond</comments>
		
		<dc:creator><![CDATA[Sandy]]></dc:creator>
		<pubDate>Fri, 25 Sep 2020 08:21:58 +0000</pubDate>
				<category><![CDATA[PLCs]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[UniLogic]]></category>
		<category><![CDATA[UniStream]]></category>
		<category><![CDATA[Unitronics]]></category>
		<guid isPermaLink="false">https://www.sandyscott.net/?p=726</guid>

					<description><![CDATA[I don&#8217;t think the documentation for the Real to Int and Int to Real blocks in Unitronics UniLogic is very clear, so here&#8217;s my explanation: Real to Int There&#8217;s a special case when r2i_Precision_in is 0 (ie. round to the nearest integer): when the magnitude of th fractional part is...<p> <a class="continue-reading-link" href="https://www.sandyscott.net/2020/09/unilogic-int-real-conversion-blocks/"><span>Continue reading</span><i class="crycon-right-dir"></i></a> </p>]]></description>
										<content:encoded><![CDATA[
<p>I don&#8217;t think the documentation for the <strong>Real to Int</strong> and <strong>Int to Real</strong> blocks in Unitronics UniLogic is very clear, so here&#8217;s my explanation:</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="678" height="236" src="https://www.sandyscott.net/wp-content/uploads/2020/09/image.png" alt="" class="wp-image-727" srcset="https://www.sandyscott.net/wp-content/uploads/2020/09/image.png 678w, https://www.sandyscott.net/wp-content/uploads/2020/09/image-300x104.png 300w, https://www.sandyscott.net/wp-content/uploads/2020/09/image-150x52.png 150w" sizes="(max-width: 678px) 100vw, 678px" /></figure>



<h2 class="wp-block-heading">Real to Int</h2>



<figure class="wp-block-image size-large"><img decoding="async" width="321" height="147" src="https://www.sandyscott.net/wp-content/uploads/2020/09/image-1.png" alt="" class="wp-image-738" srcset="https://www.sandyscott.net/wp-content/uploads/2020/09/image-1.png 321w, https://www.sandyscott.net/wp-content/uploads/2020/09/image-1-300x137.png 300w, https://www.sandyscott.net/wp-content/uploads/2020/09/image-1-150x69.png 150w" sizes="(max-width: 321px) 100vw, 321px" /></figure>



<dl class="wp-block-simple-definition-list-blocks-list">
<dt class="wp-block-simple-definition-list-blocks-term">r2i_REAL_in (Data type: REAL):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">The real number to convert.</dd>



<dt class="wp-block-simple-definition-list-blocks-term">r2i_Precision_in (Data Types: UINT8, UINT16, UINT32):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">Number of decimal places to add to the fractional part.</dd>



<dt class="wp-block-simple-definition-list-blocks-term">r2i_INT_out (Data Types: INT8, INT16, INT32):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">this is the integer part of <strong>r2i_REAL_in</strong>, no matter what the value of <strong>r2i_Precision_in</strong> is.</dd>



<dt class="wp-block-simple-definition-list-blocks-term">r2i_frac_out: (Data Types: INT8, INT16, INT32):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">This is the fractional part of r2i_REAL_in, rounded to the specified number of decimal places, multiplied by 10^( r2i_Precision_in ).</dd>
</dl>



<p>There&#8217;s a special case when <strong>r2i_Precision_in</strong> is 0 (ie. round to the nearest integer): when the magnitude of th fractional part is less than 0.5, it will be 0, otherwise it will be 1 or -1, (the same sign as <strong>r2i_REAL_in</strong>). To get the correctly rounded number, you need to add <strong>r2i_frac_out</strong> to <strong>r2i_INT_out</strong></p>



<p>The behaviour when the number is too big to fit into either of the integers seems to be inconsistent. If r2i_INT_out is an INT32, then it will 2 147 483 647 if <strong>r2i_REAL_in</strong> is bigger than that, or -2147483648 if <strong>r2i_REAL_in</strong> is smaller than that. INT16s and INT8s sometimes overflow instead. (i.e. 128 becomes -128 if   <strong>r2i_INT_out</strong> is an INT8), but it doesn&#8217;t do this for all values). I&#8217;d avoid using this function in this situation if at all possible.</p>



<p>Examples:</p>



<figure class="wp-block-table is-style-stripes"><table><tbody><tr><td><strong>r2i_REAL_in</strong></td><td><strong>r2i_Precision_in</strong></td><td><strong>r2i_INT_out</strong></td><td><strong>r2i_frac_out</strong></td></tr><tr><td>123.456</td><td>3</td><td>123</td><td>456</td></tr><tr><td>123.500</td><td>1</td><td>123</td><td>5</td></tr><tr><td>123.500</td><td>0</td><td>123</td><td>1</td></tr><tr><td>-0.03</td><td>2</td><td>0</td><td>-3</td></tr><tr><td>-12.75</td><td>3</td><td>-12</td><td>-750</td></tr><tr><td>-12.75</td><td>0</td><td>-12</td><td>-1</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Int to Real</h2>



<figure class="wp-block-image size-large"><img decoding="async" width="318" height="187" src="https://www.sandyscott.net/wp-content/uploads/2020/09/image-2.png" alt="" class="wp-image-739" srcset="https://www.sandyscott.net/wp-content/uploads/2020/09/image-2.png 318w, https://www.sandyscott.net/wp-content/uploads/2020/09/image-2-300x176.png 300w, https://www.sandyscott.net/wp-content/uploads/2020/09/image-2-150x88.png 150w" sizes="(max-width: 318px) 100vw, 318px" /></figure>



<dl class="wp-block-simple-definition-list-blocks-list">
<dt class="wp-block-simple-definition-list-blocks-term">i2r_INT_in (Data Types: INT8, INT16, INT32):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">Integer part of value. Not actually necessary, because you can do everything without it.</dd>



<dt class="wp-block-simple-definition-list-blocks-term">i2r_FRAC_in (Data Types: INT8, INT16, INT32):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">This is the only way to populate it the fractional part of the output, but it will also contribute to the fractional part.</dd>



<dt class="wp-block-simple-definition-list-blocks-term">i2r_DECPOS_in (Data Types: UINT8, UINT16, UINT32):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">This controls how <strong>i2r_FRAC_in</strong> is intepreted. Values above 7 result in the fractional part being ignored.</dd>



<dt class="wp-block-simple-definition-list-blocks-term">i2r_REAL_out (Data type: REAL):</dt>



<dd class="wp-block-simple-definition-list-blocks-details">The Real output value. This is calculated as:<br><strong>i2r_INT_in </strong>+ <strong>i2r_FRAC_in </strong>/ 10 ^ ( <strong>i2r_DECPOS_in </strong>)</dd>
</dl>



<p>Examples</p>



<figure class="wp-block-table is-style-stripes"><table><tbody><tr><td><strong>i2r_INT_in</strong></td><td><strong>i2r_FRAC_in</strong></td><td><strong>i2r_DECPOS_in</strong></td><td><strong>i2r_REAL_out</strong></td></tr><tr><td>156</td><td>456</td><td>3</td><td>156.456000</td></tr><tr><td>0</td><td>456</td><td>2</td><td>4.560000</td></tr><tr><td>13</td><td>214</td><td>2</td><td>15.140000</td></tr><tr><td>0</td><td>2147483647</td><td>7</td><td>214.748400</td></tr><tr><td>0</td><td>2147483647</td><td>8</td><td>0</td></tr></tbody></table></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sandyscott.net/2020/09/unilogic-int-real-conversion-blocks/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>UniLogic functions</title>
		<link>https://www.sandyscott.net/2014/07/unilogic-functions/</link>
					<comments>https://www.sandyscott.net/2014/07/unilogic-functions/#respond</comments>
		
		<dc:creator><![CDATA[Sandy]]></dc:creator>
		<pubDate>Mon, 07 Jul 2014 10:45:04 +0000</pubDate>
				<category><![CDATA[PLCs]]></category>
		<category><![CDATA[UniLogic]]></category>
		<category><![CDATA[UniStream]]></category>
		<category><![CDATA[Unitronics]]></category>
		<guid isPermaLink="false">http://www.sandyscott.net/?p=132</guid>

					<description><![CDATA[Int to Real D = A + B x 10 ^ (-C) Real to Int A = XXXXXX.YYYYYY C = XXXXXX D = Round 0.YYYYYY to B decimal places, then multiply by 10 ^ B At least I think this is what it&#8217;s supposed to do &#8211; it seems to...<p> <a class="continue-reading-link" href="https://www.sandyscott.net/2014/07/unilogic-functions/"><span>Continue reading</span><i class="crycon-right-dir"></i></a> </p>]]></description>
										<content:encoded><![CDATA[<h3>Int to Real</h3>
<p>D = A + B x 10 ^ (-C)</p>
<h3>Real to Int</h3>
<p>A = XXXXXX.YYYYYY</p>
<p>C = XXXXXX</p>
<p>D = Round 0.YYYYYY to B decimal places, then multiply by 10 ^ B</p>
<p>At least I think this is what it&#8217;s supposed to do &#8211; it seems to have some issues:</p>
<ul>
<li>Rounding close to 0.5 can be somewhat unpredictable. e.g. A = 5.246, B = 1 will give D=3, not D=2 as it should.</li>
<li>Note that the Integer part is always simply truncated &#8211; don&#8217;t expect this function to Round correctly &#8211; e.g. A = 12.99, B = 1 will give C=12 and D=10, instead of C=13, D=0 as you might expect!</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sandyscott.net/2014/07/unilogic-functions/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
