Preventing write access to variable declared as VAR_IN_OUT

jking22
2014-09-10
2014-09-13
  • jking22 - 2014-09-10

    Is there anyway of preventing write access to a VAR_IN_OUT variable inside the function block.

    i.e. is there some Codesys 2.3 or 2.5 eqiuvalent to the following in C++?

    void someFunction(const InputVariable&){...}

    Regards,

    John

     
  • t.lundahl - 2014-09-11

    Hi John,

    You can declare VAR_INPUT CONSTANT, but I don't think this will work on a IN_OUT.

    We use this to 'name' funktionblocks, otherwise there will be a compiler warning.

    /TorbjΓΆrn

     
  • shooter - 2014-09-12

    You should get an error as a constant is unwritable, however you declare it as in_out. Question is why is it used as an input.
    probably the thinking is a little weird.

     
  • jking22 - 2014-09-12

    Thanks for the feedback... To clarify my intent...

    1. I want to declare it as a var_in_out because:
      a. var_in_out is passing structure by reference, so I'm not copying a large structure every cyclic.
      b. var_in_out is the only way I know of in CodeSys 2.3 to enforce that my input actually get's assigned when the POU is called. It's very easy in a large project to add a new variable to a function block and then forget to assign that input in every instance.

    2. I'd like to make the variable const (at least in the C++ sense) because I want to protect the large structure from being written to inside that POU.

    i.e. I'm trying to put a little syntactic salt into our code base.

     
  • shooter - 2014-09-13

    so why not use a input structure and a separate output structure, this is far better as everything in a big structure.

     

Log in to post a comment.