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

Executing Actions as tasks

Anonymous
2017-06-23
2017-06-27
  • Anonymous - 2017-06-23

    Originally created by: Paul K.

    Hi everyone,

    I'm currently porting a Codesys 2.3 project to the latest 3.5 and I'm running into this problem.
    I have several POUs and each one has a number of actions, in the 2.3 project the Task Manager was used to start some of those actions.
    After porting the project to 3.5 the tasks are still here, however the call to the actions are gone. For example in 2.3 I had a task with the "Program call" filled as Program.Action, and after importing the tasks in 3.5 the field only reads the program and not the action, and I can't figure out how to specify what action to execute.
    I tried adding manually by adding the Action name after the program name, like it used to be with the 2.3 project, but my tasks do not start.

    What am I doing wrong? Is there even a way in 3.5 to start an action in a task? If not, is there a possible workaround?

    Thanks!

    Paul

     
  • chris.beard - 2017-06-24

    I've never tried to start an action using a task. The only way I do it is calling the action from a POU which is started from a task. Generally speaking best practice would be to keep actions and methods specific to the POU they are from. Otherwise they should be seperate prgs if you want to call them from a task.

    Sent from my SM-N9005 using Tapatalk

     
  • Anonymous - 2017-06-26

    Originally created by: Paul K.

    Hello, and thank you for your answer.

    I understand what you're saying, I'm still rather new to Codesys and still learning things...
    The problem was solved, as you said, by calling the action in a separate POU and by calling the POU from the task.

    Thanks again!

    Paul

     
  • hermsen

    hermsen - 2017-06-26

    An action is actually a method without an argument or a return value i.e.;

    POU.Action();
    

    You can call the action from inside the POU itself like;

    Action(); 
    

    Or you can call the action of the POU from anywhere in the program. I.e. via;

    PRG.POU.Action();
    

    An action is always argumentless, and cannot return any values!

    Instead of using actions, it is generally smarter in Codesys3.5 to use Methods, because methods can return values (like a function) and can be passed arguments. yay! Offcourse, methods are not provided is Codesys2.3 but actions are. Generally, Anything an Action does, a Program POU within Codesys 2.3 does that job better (i.e more flexibility!). So Personally I tend to not use actions but Programs within Codesys2.3.
    A few codesys 3.5 method call examples;

    MyPOU.DoSomething(Start := Go);
    MyPou.DoSomething();
    Start := MyPou.DoSomething();
    Result := Job.Count(ar := Array );
    

    You can see, an argument can be passed arbitrairily, and a result may be returned (both not mandatory), so you have flexibility which actions do not provide, which is in my opinion is superior. Be also aware that calling a method on a POU, only the method is resolved. To resolve the POU, it must be called explicitly.
    So calling;

    POU.Method1();
    

    Only executes the method, you still need to call;

    POU();
    

    Hope this primer on Actions/Methods helps a bit on understanding the basics. Methods in combination with interfaces is not covered in this primer. Anyhow, any and all feedback on the usage of methods subject is welcome!Ps using methods calls in graphics can result into drama. This is a point which codesys should resolve within the foreseeable future
    In the mean time there several workarounds to achieve that job which you can find in this forum.

     
  • Anonymous - 2017-06-27

    Originally created by: Paul K.

    Thanks a lot Hermsen for this quick course. I'm quite comfortable with the C language but there are some details in ST and Codesys I still don't master so this kind of precision is always welcome.

    Anyway, my problem was solved earlier using POUs but I don't feel like rewriting the whole actual code taking advantage of Codesys 3.5's new features. Having it to build, download and run already was painful enough!

    Cheers.

    Paul

     

Log in to post a comment.