<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Examples of getAttributeSingle and setAttributeSingle in PLC programs</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/</id><updated>2022-02-25T03:53:33.309000Z</updated><subtitle>Recent posts to Examples of getAttributeSingle and setAttributeSingle in PLC programs</subtitle><entry><title>Examples of getAttributeSingle and setAttributeSingle in PLC programs</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/?limit=25#c113" rel="alternate"/><published>2022-02-25T03:53:33.309000Z</published><updated>2022-02-25T03:53:33.309000Z</updated><author><name>nlsri</name><uri>https://forge.codesys.com/u/nlsri/</uri></author><id>https://forge.codesys.come029abd10f6ecd32969e7e4038ece6b053613539</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks a lot for the explanation, I will give that a try.  I have a related question - does the standard allow for both string data as well as binary data of different sizes, for the same class, instance and attribute?  If so, how exactly are they differentiated, or would the user have to know in advance the format of the data and process the response accordingly?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Examples of getAttributeSingle and setAttributeSingle in PLC programs</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/?limit=25#5a94/4031" rel="alternate"/><published>2022-02-25T03:42:25.347000Z</published><updated>2022-02-25T03:42:25.347000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.comaa40ab16d413d6c9823d867077c4fe2d4dfbf8f3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;The ODVA CIP Standard defines several encodings for strings.  A CIP STRING has 2 bytes to indicate length, and then 1 byte per character.  A CIP SHORT_STRING has 1 byte to indicate length and then 1 byte per character.  In your screenshot this is the byte containing 0E.&lt;/p&gt;
&lt;p&gt;So you could try changing the UINT of your STRING64 definition to a USINT, and then rename it to SHORT_STRING.&lt;/p&gt;
&lt;p&gt;Whether to use a STRING or SHORT_STRING should be defined by your end device.&lt;/p&gt;
&lt;p&gt;Caveat 1:&lt;br/&gt;
Some systems always put gaps between variables, so every variable starts on a memory address divisible by 2, 4, or 8.&lt;/p&gt;
&lt;p&gt;Caveat 2:&lt;br/&gt;
Codesys strings are stroed in memory as a series of bytes followed by a terminating character, 0x00.  If you were to call this code again, and this time get a string of only 3 characters (e.g. 'new'), you would end up with a string displayed in codesys like:&lt;br/&gt;
'new 20-24-100D'&lt;/p&gt;
&lt;p&gt;So you need to now have a 0x00 byte at byte 4.  You can do this 2 ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Clear the memory before you call the function, so it is all zeros.  easiest way ould be to declare a &lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;VAR CONSTANT &lt;/span&gt;
&lt;span class="err"&gt;    blankSHORT_STRING : SHORT_STRING; &lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;and then do an assign:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;ssHostnameToGet := blankSHORT_STRING;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Just write a zero after you call the function, to the index of the length.&lt;br/&gt;
Now you can access the individual bytes of a string, first byte is myString[0], second byte is myString[1]&lt;br/&gt;
so you could do:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;terminateAt := MIN(63,ssHostnameToGet.usiLength);
// maybe some alarm, if ssHostnameToGet.usiLength &amp;gt; 63
ssHostnameToGet.sString[terminateAt] := 16#00;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Examples of getAttributeSingle and setAttributeSingle in PLC programs</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/?limit=25#5a94" rel="alternate"/><published>2022-02-24T19:57:45.867000Z</published><updated>2022-02-24T19:57:45.867000Z</updated><author><name>nlsri</name><uri>https://forge.codesys.com/u/nlsri/</uri></author><id>https://forge.codesys.comce416eaf571f3abf7c9047e7bddb418d29ebc8ce</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I seem to be making some progress here, but please see attached for a discrepancy that I don't understand.  Supposedly the request got a 15 byte response? The response should actually be 14 bytes, as can be seen in the other screen capture.  The Codesys string display also has the first character missing, and and only shows 13 characters.  What is the 21262 number shown for uiLength? All this is extremely confusing. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Examples of getAttributeSingle and setAttributeSingle in PLC programs</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/?limit=25#b623" rel="alternate"/><published>2022-02-24T16:52:01.382000Z</published><updated>2022-02-24T16:52:01.382000Z</updated><author><name>nlsri</name><uri>https://forge.codesys.com/u/nlsri/</uri></author><id>https://forge.codesys.com73c730d5c071bc716fc7204f6c27929a9a0e625f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Please see attached for what I need, how can that be coded with the function block in CodeSys?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Examples of getAttributeSingle and setAttributeSingle in PLC programs</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/cc6fc81ce0/?limit=25#6dea" rel="alternate"/><published>2022-02-23T14:47:33.713000Z</published><updated>2022-02-23T14:47:33.713000Z</updated><author><name>nlsri</name><uri>https://forge.codesys.com/u/nlsri/</uri></author><id>https://forge.codesys.comb22103eb54b55c80ee53270a297972291cd71ce9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Are there any practical examples of how the Ethernet/IP service function blocks are used in PLC programs?  &lt;a href="https://help.codesys.com/webapp/_cds_obj_function_block;product=codesys;version=3.5.17.0" rel="nofollow"&gt;https://help.codesys.com/webapp/_cds_obj_function_block;product=codesys;version=3.5.17.0&lt;/a&gt; - this says that "insert with arguments" should show the input and output arguments, but that didn't seem to be happening.  The video at &lt;a href="https://www.youtube.com/watch?v=-YcEYccH88U" rel="nofollow"&gt;https://www.youtube.com/watch?v=-YcEYccH88U&lt;/a&gt; shows the visualization, but not the usage.  I looked at &lt;a href="https://help.codesys.com/webapp/8kboBg6ZzK46zifJPwfAWmWbaa0%2Ffld-Function-Blocks;product=EtherNetIP%20Services;version=3.5.17.0" rel="nofollow"&gt;https://help.codesys.com/webapp/8kboBg6ZzK46zifJPwfAWmWbaa0%2Ffld-Function-Blocks;product=EtherNetIP%20Services;version=3.5.17.0&lt;/a&gt;, but it was somewhat confusing.  Would appreciate any help.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>