1

I'm working with a Beckhoff PLC and I am trying to make a couple of POU's that are exactly the same except for the IO. I am looking for a way so I have to write the code only ones but be able to run it more than ones with different IO. For example something like classes where the IO is declared in the constructor. The different POU's also have to run simultaneously. I have already looked a little bit into a sequential function chart and function blocks with inheritance but that doesn't seem to work the way I want. I'm not even sure what I want is possible.

Dharman
  • 30,962
  • 25
  • 85
  • 135
plclearner
  • 11
  • 2

3 Answers3

1

Function blocks are the closest thing you'll get to the equivalent in classes. The closest thing to a constructor in the Beckhoff world is FB_Init (https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/63050399827943947.html&id=).

How more specifically do you want things to work?

Jakob
  • 1,288
  • 7
  • 13
  • Thanks for your answer. More specifically, I want 6 POU's or function blocks that run the same code except for their IO link. They should run simultaneously. Because they have the same code I thought it would be best to make one "Class" or function block that has all the code and have the the other FB's just inherit the functionalities of that one. Again, I don't know if this is possible. – plclearner Jul 07 '20 at 09:41
  • This is entirely possible. Just instantiate 6 instance of the function block like `fb1 : FB_YourBlock(); fb2 : FB_YourBlock(); ... fb6 : FB_YourBlock();` And create your links to the I/O in the FB_YourBlock. – Jakob Jul 13 '20 at 06:53
0

Have a look at the following link (especially the links at the bottom) to get an overview of how to use the function blocks in an object oriented way: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/63050399827943947.html&id=

When you use %I and %Q inside a function block, you will get linkable variables for each of your instances of the block. This is the case both when using an FB as an object in TC3 or when you use it just as a function block in TC2. (The FB will contain the IO)

Another solution is to make an IO-object fitting your requirements and then pass its interface pointer to the function block that handles it. (The FB will work on IO declared parallel to it, e.g. in MAIN)

pboedker
  • 523
  • 1
  • 3
  • 17
0

The solution to your task is really laying based on IDE you are working on. Some IDE does not support methods or extends in function blocks some does. So, the level of OOP implemented depends on IDE.

But yes, generally you can use function blocks as class objects. But you must take in account that you cannot dynamically change number of input or output variables, or their types. Another words, yes you can look at FB as a class, but it is not.

I think if you transition to ST from C/C++ like languages you need to change the way you think. ST is different. You better think more like procedural approach. The principles I use to create PLC independent program or universal program, most often use pointers. But again, without knowing your task and IDE it is hard to suggest.

The problem with questions like this, you have already decided what to use to solve your task and you ask how to use it, when you had to ask how to solve task like this and what to use and explain a task itself. Because it is possible that your task is classically solved using completely different tools that OOP in PLC world.

Sergey Romanov
  • 2,949
  • 4
  • 23
  • 38