<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[REXYGEN Community Forum / BCD data]]></title>
	<link rel="self" href="https://www.rexygen.com/oldforum/extern.php?action=feed&amp;tid=130&amp;type=atom"/>
	<link href="http://www.rexygen.com/oldforum/viewtopic.php?id=130"/>
	<updated>2016-05-04T18:02:47Z</updated>
	<generator>FluxBB</generator>
	<id>http://www.rexygen.com/oldforum/viewtopic.php?id=130</id>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=577#p577"/>
		<content type="html"><![CDATA[<p>Tried all three methods, didn&#039;t get the INHEXD block working but BDHEXD worked and scoobsalamander/ jaroslav code/function work great!</p>]]></content>
		<author>
			<name><![CDATA[coldh2odvr]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=56</uri>
		</author>
		<updated>2016-05-04T18:02:47Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=577#p577</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=576#p576"/>
		<content type="html"><![CDATA[<p>@jaroslav_sobota : is it possible to put all the values from the inputs in one &#039;long&#039; array? I tried but it didn&#039;t want to compile....maybe I used the wrong syntax.....</p>]]></content>
		<author>
			<name><![CDATA[scoobsalamander]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=6</uri>
		</author>
		<updated>2016-05-04T16:31:33Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=576#p576</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=575#p575"/>
		<content type="html"><![CDATA[<div class="quotebox"><cite>josar wrote:</cite><blockquote><div><p>Isn&#039;t it possible to implement a function for that?</p></div></blockquote></div><p>Yes it is possible (and recommended!). Find the code below:</p><div class="codebox"><pre class="vscroll"><code>/************************************************************
*
* REXLANG - BCD to DOUBLE
*
*************************************************************/

long input(0) input_u0;
long input(1) input_u1;
long input(2) input_u2;
long input(3) input_u3;

double output(0) output_y0;
double output(1) output_y1;
double output(2) output_y2;
double output(3) output_y3;

double bcd2double(long bcd)
{
    return ((bcd &amp; 0x0F) + ((bcd&gt;&gt;4 &amp; 0x0F)*10) + ((bcd&gt;&gt;8 &amp; 0x0F)*100) + ((bcd&gt;&gt;12 &amp; 0x0F)*1000)); 
}

long init(void)
{
    return 0;
}

long main(void)
{
        output_y0 = bcd2double(input_u0);
        output_y1 = bcd2double(input_u1);
        output_y2 = bcd2double(input_u2);
        output_y3 = bcd2double(input_u3);

    return 0;
}

long exit(void)
{
  return 0;
}</code></pre></div>]]></content>
		<author>
			<name><![CDATA[jaroslav_sobota]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=3</uri>
		</author>
		<updated>2016-05-04T14:59:39Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=575#p575</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=571#p571"/>
		<content type="html"><![CDATA[<p>Should be possible, maybe you can put your inputs in an array and iterate over it.</p>]]></content>
		<author>
			<name><![CDATA[scoobsalamander]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=6</uri>
		</author>
		<updated>2016-05-04T12:05:15Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=571#p571</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=568#p568"/>
		<content type="html"><![CDATA[<div class="quotebox"><cite>scoobsalamander wrote:</cite><blockquote><div><div class="codebox"><pre><code>long main(void)
{
        output_y0 = ((input_u0 &amp; 0x0F) + ((input_u0&gt;&gt;4 &amp; 0x0F)*10) + ((input_u0&gt;&gt;8 &amp; 0x0F)*100) + ((input_u0&gt;&gt;12 &amp; 0x0F)*1000));
	output_y1 = ((input_u1 &amp; 0x0F) + ((input_u1&gt;&gt;4 &amp; 0x0F)*10) + ((input_u1&gt;&gt;8 &amp; 0x0F)*100) + ((input_u1&gt;&gt;12 &amp; 0x0F)*1000));
	output_y2 = ((input_u2 &amp; 0x0F) + ((input_u2&gt;&gt;4 &amp; 0x0F)*10) + ((input_u2&gt;&gt;8 &amp; 0x0F)*100) + ((input_u2&gt;&gt;12 &amp; 0x0F)*1000));
	output_y3 = ((input_u3 &amp; 0x0F) + ((input_u3&gt;&gt;4 &amp; 0x0F)*10) + ((input_u3&gt;&gt;8 &amp; 0x0F)*100) + ((input_u3&gt;&gt;12 &amp; 0x0F)*1000));

    return 0;
}</code></pre></div></div></blockquote></div><p>Isn&#039;t it possible to implement a function for that?</p>]]></content>
		<author>
			<name><![CDATA[josar]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=15</uri>
		</author>
		<updated>2016-05-04T11:00:59Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=568#p568</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=562#p562"/>
		<content type="html"><![CDATA[<p>Here a tested example for four signals..... <img src="http://www.rexygen.com/oldforum/img/smilies/smile.png" width="15" height="15" alt="smile" />&#160; </p><div class="codebox"><pre class="vscroll"><code>/************************************************************
*
* REXLANG - BCD to INT
*
*************************************************************/

long input(0) input_u0;
long input(1) input_u1;
long input(2) input_u2;
long input(3) input_u3;

double output(0) output_y0;
double output(1) output_y1;
double output(2) output_y2;
double output(3) output_y3;

long init(void)
{
    return 0;
}


long main(void)
{
        output_y0 = ((input_u0 &amp; 0x0F) + ((input_u0&gt;&gt;4 &amp; 0x0F)*10) + ((input_u0&gt;&gt;8 &amp; 0x0F)*100) + ((input_u0&gt;&gt;12 &amp; 0x0F)*1000));
	output_y1 = ((input_u1 &amp; 0x0F) + ((input_u1&gt;&gt;4 &amp; 0x0F)*10) + ((input_u1&gt;&gt;8 &amp; 0x0F)*100) + ((input_u1&gt;&gt;12 &amp; 0x0F)*1000));
	output_y2 = ((input_u2 &amp; 0x0F) + ((input_u2&gt;&gt;4 &amp; 0x0F)*10) + ((input_u2&gt;&gt;8 &amp; 0x0F)*100) + ((input_u2&gt;&gt;12 &amp; 0x0F)*1000));
	output_y3 = ((input_u3 &amp; 0x0F) + ((input_u3&gt;&gt;4 &amp; 0x0F)*10) + ((input_u3&gt;&gt;8 &amp; 0x0F)*100) + ((input_u3&gt;&gt;12 &amp; 0x0F)*1000));

    return 0;
}

long exit(void)
{
  return 0;
}</code></pre></div>]]></content>
		<author>
			<name><![CDATA[scoobsalamander]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=6</uri>
		</author>
		<updated>2016-05-04T06:27:47Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=562#p562</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=560#p560"/>
		<content type="html"><![CDATA[<p>Thumbs up scoobsalamander! And here is how to do it using function blocks.<br /><span class="postimg"><img src="https://www.rexygen.com/oldforum/img/members/3/bcd_example.png" alt="bcd_example.png" /></span></p><p>The principle is the same: Take the four bits, convert it to decimal numbers and multiply it by 1, 10, 100 and 1000 respectively.</p><p>There are two approaches to obtaining the binary form of a Modbus register. The first one is faster but a bit tricky for the first use, that&#039;s why I included both of them.</p><p>Here is the <a href="https://www.rexygen.com/oldforum/img/members/3/bcd_example.mdl" rel="nofollow">mdl file</a>.</p>]]></content>
		<author>
			<name><![CDATA[jaroslav_sobota]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=3</uri>
		</author>
		<updated>2016-05-04T06:04:16Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=560#p560</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[Re: BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=559#p559"/>
		<content type="html"><![CDATA[<p>In a REXLANG block you can do something like this by shifting/masking the bits. </p><div class="codebox"><pre><code>pressure = ((input &amp; 0x0F) + ((input&gt;&gt;4 &amp; 0x0F)*10) + ((input&gt;&gt;8 &amp; 0x0F)*100) + ((input&gt;&gt;12 &amp; 0x0F)*1000));</code></pre></div><br /><p>I did not test the code but I guess you got the idea...</p>]]></content>
		<author>
			<name><![CDATA[scoobsalamander]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=6</uri>
		</author>
		<updated>2016-05-04T05:37:38Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=559#p559</id>
	</entry>
	<entry>
		<title type="html"><![CDATA[BCD data]]></title>
		<link rel="alternate" href="http://www.rexygen.com/oldforum/viewtopic.php?pid=557#p557"/>
		<content type="html"><![CDATA[<p>Now that I&#039;ve got my RPi reading values from my PLC (awesome) I need to convert them into something useful. The values in the PLC are stored in a mix of HEX and BCD values (common to most HMIs). </p><p>Example - I&#039;m reading line pressure via the MTM block from the Modbus Slave as a 16 bit register. The value received is decimal 4633 = binary 0001 0010 0001 1001. In BCD this converts to the actual line pressure of 1219 (each digit is represented by its respective 4 bits).</p><p>Is there any easy way to specify or convert bases in Rex? I&#039;ve been digging but not found anything yet.</p><p>Thanks!</p>]]></content>
		<author>
			<name><![CDATA[coldh2odvr]]></name>
			<uri>http://www.rexygen.com/oldforum/profile.php?id=56</uri>
		</author>
		<updated>2016-05-04T00:47:30Z</updated>
		<id>http://www.rexygen.com/oldforum/viewtopic.php?pid=557#p557</id>
	</entry>
</feed>
