Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Var in_out constant functions

2017-02-01
2017-02-10
  • josepmariarams - 2017-02-01

    Dears

    I am working with codesys 3.5.8.

    In that version is not posible to pass a function which returns an string to an var_inout constant string. (For ex. To_string).

    Anybody know if will that be possible in future versions?

     
  • Kim - 2017-02-01

    I'm not sure I understand, a constant string is a constant and if you would need to execute a function to create it then it can't be considered a constant anymore

    Could you please show us in code what you are trying to do, maybe then we can answer the question.

     
  • josepmariarams - 2017-02-01

    There esxist to declre varables as var_inout constant

    Var_in_out constant
    Str:string
    End_var

    In that case is not possible to change the string inside method or fb.

    I use this method because don t make a copy of the string, only passes the reference.

    It works if it is passed an constant string, but not passing a method which returns an string

     
  • Joan M - 2017-02-01

    Hi Josep,

    Firstly, only CodeSys people can answer this properly so all what anyone here can write is personal preferences or comparisons to other languages...

    Now that you've explained what you are interested into... I understand it. But I'm afraid this should not be possible at all...

    Notice: to make it easier replace "routine" for "function or method" in all the post.

    If you have a routine that returns a value... it returns a copy of the value by design so the problem is not in the VAR_IN_OUT CONSTANT part (which is enough strange by itself) but it is in the routine return.

    The routine can't work on that variable as when you call it, its created in the stack just at that moment and it gets destroyed when it returns the value (end of the routine) so the value itself is not there anymore when it has been returned.

    Probably the best would be a reference or a pointer, but I'm sure you've already thought on that and probably in your situation what you want suits you best...

    Of course you are speaking of a method specifically so the returned value probably is a member of the parent of the method, but even in that case unless you return a pointer to the string you are returning a copy of the string itself and not it's address.

    Anyway, as stated at the beginning of the post, only CodeSys people can answer this properly...

    Good luck!

     
  • josepmariarams - 2017-02-02

    Ei Joan.

    You are right. The returning function values are stored on stack.

    Codesys works with strings as an individual element, not an array. C works with pointers to strings. C working strings are faster than Codesys form, but codesys form is more robust than c.

    My objective was substitute, for example, concat. Concat makes 2 copys of the entire strings in parameters passing, another internal copy to make the returning string and an end copy to the variable where concat stored the result.

    Using var_in_out and refs makes the code faster inside realtime.

    May be the final question is: Is a good prectice to work with strings inside rtime?

     
  • rickj - 2017-02-02

    Hi Joseph,

    On a recent project we used a Beckhoff PC based controller on an automated assembly machine consisting of 40~50 servo control loops, as many or more pneumatic devices, 6 robots, 5 visual inspection cameras, laser markers, part and consumable tracking, etc. Strings were used extensively without any detriment to performance. As far as I could tell we were swimming in an ocean of unused cpu cycles and memory bytes.

    I suppose it's possible to get in trouble on a limited platform and/or not using best/reasonable practices.

     
  • josepmariarams - 2017-02-10

    Hi rjafrate.

    Have you test in your system to launch an mc_moveabsolute to all your axes at the same cycle task?

     

Log in to post a comment.