<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Type–length–value in Codesys</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6c6354beab/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6c6354beab/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/6c6354beab/</id><updated>2022-01-02T18:50:08.259000Z</updated><subtitle>Recent posts to Type–length–value in Codesys</subtitle><entry><title>Type–length–value in Codesys</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6c6354beab/?limit=25#3975" rel="alternate"/><published>2022-01-02T18:50:08.259000Z</published><updated>2022-01-02T18:50:08.259000Z</updated><author><name>nothinrandom</name><uri>https://forge.codesys.com/u/nothinrandom/</uri></author><id>https://forge.codesys.com6d42db212e85ea50a5595f14b80232c4b22cf665</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;a class="user-mention" href="/u/damian177/"&gt;@damian177&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;This is pretty much the format that most, if not all, industrial control protocols (e.g. EtherNet/IP, S7, SLMP) follow.  Some header that specifies command type and length of the message and is followed by the message data itself.  The best way to handle this would be to create a byte array, then use sysmem.cpy and copy the bytes into such array to be sent other some medium (e.g. Ethernet).&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;For&lt;/span&gt; &lt;span class="n"&gt;example:&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;. &lt;span class="n"&gt;Create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;byte&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="n"&gt;called&lt;/span&gt; `&lt;span class="n"&gt;_abOutput&lt;/span&gt; : &lt;span class="n"&gt;ARRAY&lt;/span&gt; [&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;4096&lt;/span&gt;] &lt;span class="n"&gt;OF&lt;/span&gt; &lt;span class="n"&gt;BYTE&lt;/span&gt;;`
&lt;span class="mi"&gt;2&lt;/span&gt;. &lt;span class="n"&gt;Create&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;STRUCT&lt;/span&gt; &lt;span class="n"&gt;called&lt;/span&gt; `&lt;span class="n"&gt;_stMyData&lt;/span&gt;` &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;variables&lt;/span&gt; &lt;span class="n"&gt;such&lt;/span&gt; &lt;span class="n"&gt;as:&lt;/span&gt;
    &lt;span class="mi"&gt;1&lt;/span&gt;.  `&lt;span class="n"&gt;uiType&lt;/span&gt; : &lt;span class="n"&gt;UINT&lt;/span&gt;;`
    &lt;span class="mi"&gt;2&lt;/span&gt;. `&lt;span class="n"&gt;uiLen&lt;/span&gt; : &lt;span class="n"&gt;UINT&lt;/span&gt;;`
    &lt;span class="mi"&gt;3&lt;/span&gt;. `&lt;span class="n"&gt;sData&lt;/span&gt; : &lt;span class="n"&gt;STRING&lt;/span&gt;;`
&lt;span class="mi"&gt;3&lt;/span&gt;. &lt;span class="n"&gt;Fill&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;STRUCT&lt;/span&gt; (&lt;span class="nb"&gt;e&lt;/span&gt;.&lt;span class="n"&gt;g&lt;/span&gt;. &lt;span class="n"&gt;uiType&lt;/span&gt; := &lt;span class="mi"&gt;1&lt;/span&gt;, &lt;span class="n"&gt;sData&lt;/span&gt; := &lt;span class="s"&gt;'hello world'&lt;/span&gt;, &lt;span class="n"&gt;uiLen&lt;/span&gt; := &lt;span class="n"&gt;len&lt;/span&gt;(&lt;span class="n"&gt;sData&lt;/span&gt;))
&lt;span class="mi"&gt;4&lt;/span&gt;. &lt;span class="n"&gt;Then&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="n"&gt;SysMemCpy&lt;/span&gt; &lt;span class="nb"&gt;to&lt;/span&gt; &lt;span class="k"&gt;copy&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;buffer&lt;/span&gt; &lt;span class="n"&gt;via&lt;/span&gt; &lt;span class="n"&gt;something&lt;/span&gt; &lt;span class="nb"&gt;like&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; `&lt;span class="n"&gt;SysMemCpy&lt;/span&gt;(&lt;span class="n"&gt;pDest:&lt;/span&gt;=&lt;span class="n"&gt;ADR&lt;/span&gt;(&lt;span class="n"&gt;_abOutput&lt;/span&gt;), &lt;span class="n"&gt;pSrc:&lt;/span&gt;=&lt;span class="n"&gt;ADR&lt;/span&gt;(&lt;span class="n"&gt;_stMyData&lt;/span&gt;), &lt;span class="n"&gt;udiCount:&lt;/span&gt;=(&lt;span class="n"&gt;_stMyData&lt;/span&gt;.&lt;span class="n"&gt;uiLen&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;));`.  &lt;span class="n"&gt;The&lt;/span&gt; `+&lt;span class="mi"&gt;2&lt;/span&gt;` &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;uiType&lt;/span&gt;.
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Anyway, then have TCP write client send this out.  As the receive part, just do the same thing.  Create a struct and copy from the receive buffer back into a STRUCT for "easy" parsing.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Type–length–value in Codesys</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6c6354beab/?limit=250#6703" rel="alternate"/><published>2021-12-24T11:38:01.207000Z</published><updated>2021-12-24T11:38:01.207000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com5a6f773933bcaebeb15ddf4de1ce21b95527954c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Personally I never came across such a library. But that said, reading &lt;a href="https://en.m.wikipedia.org/wiki/Type%E2%80%93length%E2%80%93value" rel="nofollow"&gt;https://en.m.wikipedia.org/wiki/Type%E2%80%93length%E2%80%93value&lt;/a&gt; at first glance it seems not too difficult to implement an encoder/decoder.&lt;/p&gt;
&lt;p&gt;good luck and merry Christmas 🎄⛄&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Type–length–value in Codesys</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6c6354beab/?limit=25#4341" rel="alternate"/><published>2021-12-23T06:48:21.095000Z</published><updated>2021-12-23T06:48:21.095000Z</updated><author><name>damian177</name><uri>https://forge.codesys.com/u/damian177/</uri></author><id>https://forge.codesys.com7dae7a41b9155ea9286d1224c3957ea62fe29d03</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;br/&gt;
Someone have use Type–length–value coding in Codesys ? I need function to decode data from string. Someone heard about similar solution?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>