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.
So if the function block is called myFunctionBlock, and the method is call SendChar, and the Constant is CHR_STX, it looks like this :
myBlock : myFunctionBlock;
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?
CHR_STX: BYTE := 16#02;
CHR_ETX: BYTE := 16#03;
CHR_ACK: BYTE := 16#06;
CHR_NAK: BYTE := 16#15;
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?
Something like this:
TYPE enumErrorCode :
NONE := 0,
CHECKSUM := 1,
ADDRESS := 2,
(I'm using version 3.5 SP16)
Why don't you just create an ENUM, call it ASCII or whatever
then just make your method input of type ASCII
Then call your method like this:
same thing with the error code ENUM. Just create the ENUM and you can use it anywhere.
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.
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.
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.
Log in to post a comment.