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

I need help in SCF - Beginner in Codesys

martinll
2021-01-14
2021-01-14
  • martinll - 2021-01-14

    Hi!

    I have a problem than needs solving. As im new to codesys (and to Codesys Forge) im not sure if this is the place for questions or if I´ll be able to explain this in a way that anyone but myself could understand so i would like to apologize for this in right away.

    Here we go;

    I´m coding in SFC (i´m a student and this is a simple machine that we are training to control in different languages).
    I have created a paralell branch.
    I have "loaded" an prg to a step befor the "split" between the branched. This PPG is to control the buttons for stop, manual motor etc. for the machine.

    In the loaded prg i have a button switching from auto- to manual running of the machine.

    But; when i run it on manual and come to a step where auto can "take over" - it does so and the auto-run is activated.

    In my loaded prg i have tried to in ST write something like
    if auto_manual (the loaded prg) :=true
    then
    step1:=false
    step2:=false
    ect.

    but as soon as they get a go they go.

    So to the question;
    is there a way to (for the entire cycle) disable steps in SCF if a bool:=true/false?

    As english is not my native language and, as mentioned earlier, this is my first post, please come back to me if i should explain/re-phrase anything.

    I´m running codesys 2.3.

    Best

    Martin

     

    Last edit: martinll 2021-01-14
  • ojz0r - 2021-01-14

    First off: ":=" is assignment, dont use it for evaluation. I simply use "if auto_manual then" since its a bool.
    I think you should look into a parallel branch if your disable condition is enabled.

     
    👍
    1
  • martinll - 2021-01-14

    Hi!

    Thank you for your answer!

    Sorry for the :
    that was a miss typing. Attached is a snippet with an overwiev of the problem.

    What i would like is that when the "flow" (i´m not sure what you call it - but when it turns blue")
    goes into the right branch (not done yet, i need to add some steps later on) it should not go back to the left branch. But at any given moment when in the left branch it should be able to move to the right.

    In the action auto_manuell you can see the two steps i have tried with. when choosing them (F2) i can chose the same name but with an extra _ before, do you know what that means?

    BTW - do you know what the "Flow" i mentioned before is called?

    I see i named the file cfc but its SFC.

    Thanks again!

    Martin

     

    Last edit: martinll 2021-01-14
  • martinll - 2021-01-14

    Another quick random question.

    When using "if", do i need an else or is it ok to just use an "if" bla bla bla "end_if"?

     
  • aliazzz

    aliazzz - 2021-01-14

    Maybe the following is allready clear, maybe not, here goes anyway:

    // DON'T
    IF xMyBoolVal = FALSE THEN
       ...
    END_IF
    
    // CONSIDER
    IF NOT xMyBoolVal THEN  // Use positive logic
       // xMyBoolVal = FALSE
       ...
    ELSE
       // xMyBoolVal = TRUE
       ...
    END_IF
    
    // DON'T
    IF xMyBoolVal = TRUE THEN // Convoluted as this is double 
       ...
    END_IF
    
    // CONSIDER
    IF xMyBoolVal THEN // Easy, short and correct
       // xMyBoolVal = TRUE
       ...
    ELSE
       // xMyBoolVal = FALSE
       ...
    END_IF
    
    // DON'T
    IF xA THEN // Convoluted
       xB := TRUE;
    ELSE
       xB := FALSE;
    END_IF
    
    // CONSIDER
    xB := xA;
    

    Offcourse, coding involves a certain matter of personal taste, but always consider readability to be top priority.
    Most important, don't be afraid to make mistakes! We all have to learn somehow, right?

    PS Read the SFC editor manual of CODESYS v2.3

     

    Last edit: aliazzz 2021-01-14
  • ojz0r - 2021-01-14

    I havent tried that in codesys.
    I imagine that you first would need two transitions to check whether your "disabled" variable is true or false and then diverge (create a parallel) in the middle of them.
    (It would be easier to explain it in Swedish).

    No you dont need to use the else, its there to reduce code if you need to another action if the first statement isnt evaluated true.

     
  • martinll - 2021-01-14

    Thank you for your reply!
    I´m right not digging through the SCF-chapter of the help manual (everytime i read it i know a bit more than the last time that makes me understand a bit more. I found the answer to the _step-name.

    Thank you so much for your code, it will make my mess a lot easier to get at grip of!

    Martin

     
  • martinll - 2021-01-14

    Thank you ojzor and as a fellow swede i fully understand!

    I think i´ll go for the easy way out and leave this for later - it sounds a bit over my head for now.

    Thank you so much for your help (thanks to aliazz aswell) - as my teacher in automation is not the best educator (to say the least) i guess i´ll be back soon with more questions.

    best regards,

    Martin

     

Log in to post a comment.