Library functions using external variables

rickychang
2022-07-04
2022-07-04
  • rickychang - 2022-07-04

    I have some function blocks in an application that I'd like to put into a library(compiled or not). These function blocks use some external variables and functions from the application. After creating the library and adding to the original application and compiling, the compiler complains about the external variables/functions of being undefined, not even standard function blocks like TON. Is this behavior normal? Because as I recall this was not a problem in Codesys V2.3. How can I resolve this?

    Thanks for the help.

     
  • fajean - 2022-07-04

    For variables, maybe VAR_EXTERNAL does what you need, but I have no experience using it so cannot attest to this. For functions, I do not know of a way for a library to depend on code found inside a project.

    That being said, you may want to consider if what you are trying to achieve is the right design. Typically, you would probably want your project to depend on your libraries, not the other way around. This might mean putting global variables in your library or, maybe better yet, not having global variables at all and using instance variables of function blocks. Global variables hinder or prevent code reuse.

     

Log in to post a comment.