Codesys and OOP

2015-11-23
2015-11-30
  • PhilipLykov - 2015-11-23

    Where can I read about OOP in CodeSys with examples? I'm not a guru of OOP at all but it seems as mandatory to extend functionality of the existing libraries in Codesys V3. I have a 5 years of non OOP programming experience on PHP.

    I really cannot understand all these things like 'THIS^()', 'SUPER^()', why 'somefbname.somevariable:=1' works but 'somefbname(somevariable:=1)' - doesn't.

     
  • Anonymous - 2015-11-24

    Originally created by: scott_cunningham

    You can find two examples with documentation in the CoDeSys store which show using OOP for building automation (room lighting and room heating).

    Industrial Automation hasn't really jumped on the OOP wagon for a couple of reasons: lack of experience by existing programmers (same reason why ladder is more popular that ST in PLC code) and that machines tend to be so different from one to another, so reuse is low. I work in industrial automation and have started to use it, however.

    A couple of tips:

     
  • Yegor - 2015-11-30

    Zitat:
    why 'somefbname.somevariable:=1' works but 'somefbname(somevariable:=1)' - doesn't
    This probably doesn't have much to do with OOP. Both statements should work but they don't have to work the same. The first one is an assignment statement where you simply set a variable to some new value like "hey, here's a value, take it and keep it for later". The second one looks like a function block call where you not only assign an input variable some value but also instruct the function block to process its variables, kind of like "hey, here's a value, go do your thing". Calling "somefbname.somevariable:=1; somefbname()" should have the same effect as "somefbname(somevariable:=1);"

     
  • PhilipLykov - 2015-11-30

    Yegor, Thanks a lot!
    As I understand there is possible to have a few isolated and running instances of a FB.

     
  • Yegor - 2015-11-30

    Not only is it possible, that's the way you should do it. The TON timer is an example of a function block type.

     

Log in to post a comment.