<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/</id><updated>2020-02-27T14:16:02.510000Z</updated><subtitle>Recent posts to REAL TO WORD problem</subtitle><entry><title>REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/?limit=25#ef1c" rel="alternate"/><published>2020-02-27T14:16:02.510000Z</published><updated>2020-02-27T14:16:02.510000Z</updated><author><name>alex87</name><uri>https://forge.codesys.com/u/alex87/</uri></author><id>https://forge.codesys.com1358bfa9c282c382a7410009640fb2cd6bb3573f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Very interesting Timvh!&lt;/p&gt;
&lt;p&gt;In my case I need to send a BCD digits, because receiver displays it directly on remote char display. And expects floating point at (&lt;em&gt; _ &lt;/em&gt; . &lt;em&gt;) after third place. &lt;br/&gt;
Problem is convertng BCD for (&lt;/em&gt; _ &lt;em&gt; _ . &lt;/em&gt;) 5 places, because WORD_TO_BCD converts only to 4 digits (9999).&lt;/p&gt;
&lt;p&gt;regards,&lt;br/&gt;
Alex&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/?limit=25#aae0" rel="alternate"/><published>2020-02-27T14:16:01.313000Z</published><updated>2020-02-27T14:16:01.313000Z</updated><author><name>timvh</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.com6bbdfe56b8cbdd2365b1f01cc38c2649bcaf79c5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;It depends on what you want to send. If the receiver expects a floating point variable, then it still doesn't work.&lt;br/&gt;
A floating point variable is stored according to the IEEE 754 standard which you can transfer as 4 bytes, but not by the REAL_TO_WORD conversion.&lt;br/&gt;
What you need to send is the "real binairy value" of the REAL.&lt;/p&gt;
&lt;p&gt;This can be done with a trick to add a "Union" Data Unit Type (DUT) to the application. A Union shares the memory for different variables:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;TYPE&lt;/span&gt; &lt;span class="n"&gt;unionDwReal&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="k"&gt;UNION&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;dwDword&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;DWORD&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;rReal&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;REAL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_UNION&lt;/span&gt;
&lt;span class="n"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;When you declare this in your application as variable you can write your real to the real variable of the union, but then send the DWORD with the SDO. This off course only works correctly if the receiver also expects to receive a floating point variable according to the IEEE 754 standard (which almost all do).&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;PROGRAM&lt;/span&gt; &lt;span class="n"&gt;PLC_PRG&lt;/span&gt;
&lt;span class="n"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;uDwR&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unionDwReal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;dwSDO&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;DWORD&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;uDwR&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rReal&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;dwSDO&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uDwR&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dwDword&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;PS, another similar method is by using pointers. This would be the way to do it with V2.3.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/?limit=25#fff8" rel="alternate"/><published>2020-02-27T14:16:00.845000Z</published><updated>2020-02-27T14:16:00.845000Z</updated><author><name>alex87</name><uri>https://forge.codesys.com/u/alex87/</uri></author><id>https://forge.codesys.comaae8ba897be65be02f0f71df4b218349c3f94c0d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Realized, I won't need 5 BCD digits only 4. But still interesting problem.&lt;/p&gt;
&lt;p&gt;regards, Alex&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/?limit=25#9cfc" rel="alternate"/><published>2020-02-27T14:16:00.489000Z</published><updated>2020-02-27T14:16:00.489000Z</updated><author><name>alex87</name><uri>https://forge.codesys.com/u/alex87/</uri></author><id>https://forge.codesys.com77203918dc7095383a6b70c96a719ddd1239a792</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Well not so good, then. Now I have another problem. After Multiply the REAL value by 10 (eg 1234.5 * 10 i got 12345) then I use WORD TO BCD (within util.lib) which converts values from 0 to 9999 BCD. Now there is another problem after conversion i get 2345 without 1. At this point I can't divide back by 10.&lt;/p&gt;
&lt;p&gt;Any idea?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/?limit=25#a421" rel="alternate"/><published>2020-02-27T14:16:00.141000Z</published><updated>2020-02-27T14:16:00.141000Z</updated><author><name>alex87</name><uri>https://forge.codesys.com/u/alex87/</uri></author><id>https://forge.codesys.com8745f3922dbfc183a1b0efd800a3b599b82ec94c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Of, course!&lt;/p&gt;
&lt;p&gt;Thank you Andreas!&lt;br/&gt;
You save my time studying.&lt;/p&gt;
&lt;p&gt;Regards, &lt;/p&gt;
&lt;p&gt;Alex&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/?limit=25#54cb" rel="alternate"/><published>2020-02-27T14:15:59.078000Z</published><updated>2020-02-27T14:15:59.078000Z</updated><author><name>Andreaz</name><uri>https://forge.codesys.com/u/andreaz/</uri></author><id>https://forge.codesys.com18d269991d64427ad21240918d7821822a7b9f10</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;REAL_TO_DWORD does a truncation and then converting.&lt;/p&gt;
&lt;p&gt;You have to multiply the real value with a factor of 10 to get the "decimals":&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: Capture.PNG" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=421"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>REAL TO WORD problem</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8e6b65222e/?limit=25#3f9e" rel="alternate"/><published>2020-02-27T14:15:58.717000Z</published><updated>2020-02-27T14:15:58.717000Z</updated><author><name>alex87</name><uri>https://forge.codesys.com/u/alex87/</uri></author><id>https://forge.codesys.com58666f87179ba0f2b1bb77670fcb5e3a62dbe8fb</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;I have a problem with conversion data type REAL to integers DWORD. In visualization i have input field of type: %3.1f mm with numpad dialog. So my (%3.1f mm) input has a decimal/ float point. When conversion is made to DWORD type floating point dissapears from value. I input value 123.9 converted DWORD value is 124.&lt;/p&gt;
&lt;p&gt;I have to convert somehow with floating point it because I'm sending it to SDO protocol which has 4 BYTE send buffer.&lt;/p&gt;
&lt;p&gt;Any Idea how to solve my problem?&lt;/p&gt;
&lt;p&gt;I have attached online pictures of conversion.&lt;/p&gt;
&lt;p&gt;regards Alex&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: online.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=420"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: real_index.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=419"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>