I'm new to PLC programming and we need to create a library for a project. We need dynamically created function block instances during the runtime. There is a concept described on the codesys homepage: https://help.codesys.com/webapp/fb_factory;product=LibDevSummary;version=3.5.15.0
We tried to implement the example but without success. Unfortunately, there is no further information about the concept on the codesys homepage. Has anybody some advice how to dynamically create fb instances during the runtime on a plc?
I made a simple classic OOP Person, Teacher, Student example, here's a project file, or PLCOpenXML file.
Basically, changing the value of numberOfTeachers
inside PLC_PRG
will cause the reinitializarion of the array people
with the first numberOfTeachers
entries being Teachers, and the rest being Students. You can look at the Device Logs where I write messages for creation/destruction of Teacher/Studemt.
PS. I am myself still exploring the possibilities of the Factory Design in CODESYS, so excuse me if I made any mistakes!
Update 23-03-16: Incorporated the suggested changes by ohraaa