<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Constants and  or Enumeration in a Function Block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/478df9989b/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/478df9989b/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/478df9989b/</id><updated>2021-03-31T17:11:30.228000Z</updated><subtitle>Recent posts to Constants and  or Enumeration in a Function Block</subtitle><entry><title>Constants and  or Enumeration in a Function Block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/478df9989b/?limit=50#f69d" rel="alternate"/><published>2021-03-31T17:11:30.228000Z</published><updated>2021-03-31T17:11:30.228000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com8de1d2453efe53f283b07a39a1fa5970744d2ee8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Yes, then I would create a library that contains the ENUM as well as the function block.  Then you can reuse them in whatever project you install the library into.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Constants and  or Enumeration in a Function Block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/478df9989b/?limit=25#ed1e" rel="alternate"/><published>2021-03-31T17:09:07.911000Z</published><updated>2021-03-31T17:09:07.911000Z</updated><author><name>dengsberg</name><uri>https://forge.codesys.com/u/dengsberg/</uri></author><id>https://forge.codesys.com096ba6c32ac949dea59f9d10fdc41dcba189e786</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I was hoping to keep the enum contained within the function block, not the entire project. So if I have other projects that uses the function block, I don't have to create the enum again and again.&lt;/p&gt;
&lt;p&gt;Is it different with libraries? It seems like I can download a library and the library contains enums within itself.  That is what I was shooting for.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Constants and  or Enumeration in a Function Block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/478df9989b/?limit=50#3b40" rel="alternate"/><published>2021-03-31T16:26:12.353000Z</published><updated>2021-03-31T16:26:12.353000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com57cbfd264cebcdcba79463a81497c07fc88735a5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Why don't you just create an ENUM, call it ASCII or whatever&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;TYPE&lt;/span&gt; &lt;span class="nt"&gt;ASCII&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;CHR_STX&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="mh"&gt;#02&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;CHR_ETX&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="mh"&gt;#03&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;CHR_ACK&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="mh"&gt;#06&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;CHR_NAK&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="mh"&gt;#15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;BYTE&lt;/span&gt;
&lt;span class="nt"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;then just make your method input of type ASCII&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;VAR_INPUT&lt;/span&gt;
  &lt;span class="nt"&gt;In&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;  &lt;span class="nt"&gt;ASCII&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then call your method like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;myBlock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SendChar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ASCII&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CHR_STX&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;same thing with the error code ENUM.  Just create the ENUM and you can use it anywhere.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;VAR&lt;/span&gt;
  &lt;span class="nt"&gt;ErrorCode&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;  &lt;span class="nt"&gt;enumErrorCode&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Constants and  or Enumeration in a Function Block</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/478df9989b/?limit=25#698d" rel="alternate"/><published>2021-03-31T15:27:16.104000Z</published><updated>2021-03-31T15:27:16.104000Z</updated><author><name>dengsberg</name><uri>https://forge.codesys.com/u/dengsberg/</uri></author><id>https://forge.codesys.com6b1be0fcafe7a6a8f95dd936e8e59d693fe6b839</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have created a function block with a Method. I would like to pass this method a Constant or an Enumeration value, from the outside the function block.  I would like the constants and enumerations contained within the function block itself, but have access to them from the outside. &lt;/p&gt;
&lt;p&gt;So if the function block is called myFunctionBlock, and the method is call SendChar, and the Constant is CHR_STX, it looks like this :&lt;br/&gt;
myBlock : myFunctionBlock;&lt;br/&gt;
myBlock.SendChar(CHR_STX);&lt;/p&gt;
&lt;p&gt;I have something working, but I don't think it is the proper way to do it.  I created some constants of scope VAR_OUTPUT.  Is there a better way?&lt;/p&gt;
&lt;p&gt;VAR_OUTPUT CONSTANT&lt;br/&gt;
    CHR_STX: BYTE := 16#02;&lt;br/&gt;
    CHR_ETX: BYTE := 16#03;&lt;br/&gt;
    CHR_ACK: BYTE := 16#06;&lt;br/&gt;
    CHR_NAK: BYTE := 16#15;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;I would also like to create an ErrorCode enumeration that is contained within the function block, but can be accessed by the outside.  How can I do this?&lt;br/&gt;
Something like this:&lt;br/&gt;
TYPE enumErrorCode :&lt;br/&gt;
(&lt;br/&gt;
    NONE := 0,&lt;br/&gt;
    CHECKSUM := 1,&lt;br/&gt;
    ADDRESS := 2,&lt;br/&gt;
    LENGTH :=3&lt;br/&gt;
);&lt;br/&gt;
END_TYPE&lt;/p&gt;
&lt;p&gt;(I'm using version 3.5 SP16)&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>