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

String format

alex87
2016-12-14
2021-04-10
  • alex87 - 2016-12-14

    Is there a C equivalent function in Codesys for string formatting?

    For example: sprintf(str, "%d,%d,%d", a, b, c);

     
  • Anonymous - 2016-12-14

    Originally created by: scott_cunningham

    You have to build the string. See CONCAT and associated key words

     
  • alex87 - 2016-12-14

    I am familiar with CONCAT but I am seeking for more elegant solution for longer strings. Also, CONCAT is rather slow.

     
  • Anonymous - 2016-12-15

    Originally created by: scott_cunningham

    I also don't use CONCAT. I use my own byte copy routine. Sorry, IEC isn't setup to have fancy string handlers.

     
  • eschwellinger

    eschwellinger - 2016-12-15

    Hi,

    in any case it is much more performant if you use StringUtils.library in compare to use the string/concat whatever from Standard library.

    BR
    Edwin

    IMG: StringUtils.jpg

     
  • HenryK - 2017-03-01

    Hi,
    recently I faced a warning in a document what tells me:

    Zitat:
    Plaese note, string functions are not "thread safe": When using tasks, string functions may only be used in a single task. If the same function is used in different tasks, there is a danger of overwriting.

    Okay, clear so far. It is like it is. I am looking for a general solution how to deal with this restriction in POUs provided in libraries.
    Do you recommend to use in general the functions from the StringUtils.library?
    For my opinion the usage of this lib in my situation brings me two advantages:

    1. I avoid the use of the STRING functions from the Standard lib, thus there is no risk in conjunction with MultiTask apps where my POUs are implemented later.

    2. The program becomes more performant.

    Maybe it sounds a little bit stupid, because I answered teh question by myself. But I am really looking for an external opinion to strengthen my decision, not to use the String functions from the Standard lib in my libraries.

    Thank you for your feedback.

     
  • HenryK - 2017-03-03

    Hi,
    I got the information from 3S that since CoDeSys V3 all String functions are threadsafe. Thus the problem has been solved by itself.
    However, I also got the information, it is recommended to use the StringUtils lib, because it is more performant than the functions from the Standard lib.

    Regards

     
  • pruwetbe - 2021-04-10

    Hello,
    I want to use the StuSprintf function from this library to format real value to string send in a Text file.

    I search in my Library manager but could not find the StringUtils in the list.
    I tried to add it without results but this library is visible in my codesys library repository under the system folder.

    So i thought: As it is a system library, perhaps it is implicitly included...

    When I add the function StuSprintf in my CFC code, the bloc interface is displayed correctly and I can configure the input & output.
    But StuSprintf stay red underlined with a warning saying Indentifier 'StuSprintf' not defined. How to solve this?

    I am working with codesys V3.5 SP16 patch4 and my Target device Codesys Control for Raspberry Pi MC SL.

    Thanks for any help

     
  • pruwetbe - 2021-04-10

    OK i finally found the way to add it to my application

     
    πŸ‘
    1

Log in to post a comment.