<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Word to array of byte</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ece274c395/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ece274c395/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/ece274c395/</id><updated>2022-09-22T15:23:16.870000Z</updated><subtitle>Recent posts to Word to array of byte</subtitle><entry><title>Word to array of byte</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ece274c395/?limit=25#a91a" rel="alternate"/><published>2022-09-22T15:23:16.870000Z</published><updated>2022-09-22T15:23:16.870000Z</updated><author><name>paulpotat</name><uri>https://forge.codesys.com/u/paulpotat/</uri></author><id>https://forge.codesys.com29c933e6dd3dce27da625eba4e34fdbb7e75bbc9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Easiest way to do this is to create a type like this :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;TYPE uWordBytes :&lt;/span&gt;
&lt;span class="err"&gt;  UNION&lt;/span&gt;
&lt;span class="err"&gt;    rValue : WORD;    // Needs 2 Bytes in memory&lt;/span&gt;
&lt;span class="err"&gt;    abValue: ARRAY [0..1] OF BYTE;&lt;/span&gt;
&lt;span class="err"&gt;  END_UNION&lt;/span&gt;
&lt;span class="err"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then in your program you can declare your variables like this :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;my_var&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;uWordBytes&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;my_var_as_word&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;WORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// ...&lt;/span&gt;

&lt;span class="n"&gt;my_var&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rValue&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;my_var_as_word&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then it will automatically fill the array &lt;code&gt;my_var.abValue&lt;/code&gt; with the corresponding bytes ! You can access those bytes the same way :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;x[0] := my_var.abValue[0]; // First byte&lt;/span&gt;
&lt;span class="err"&gt;x[1] := my_var.abValue[1]; // Second byte&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Beware of the endianess of the value though, I don't remember if it's little endian or big endian...&lt;/p&gt;
&lt;p&gt;By the way to create a new type you have to do : right-click on application --&amp;gt; Add Object --&amp;gt; DUT...&lt;/p&gt;
&lt;p&gt;Hope this helps !&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Word to array of byte</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ece274c395/?limit=25#e0c2" rel="alternate"/><published>2022-09-21T13:05:50.891000Z</published><updated>2022-09-21T13:05:50.891000Z</updated><author><name>arek1996</name><uri>https://forge.codesys.com/u/arek1996/</uri></author><id>https://forge.codesys.com71eab5fdb87ddd057743d7d0d660fadde72bc72a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;First of all I'm new in codesys. My problem is converting values (which I will type on touchscreen) on array of bytes. I have Array of 6 bytes which include 3 parametrs. How can I convert values (word) into bytes? Unfortunately there is no FB for this converting. Please help. I use this for acyclic data in Profinet (wrrec FB).&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>