sualk2619
Dear helpers,
I try to transfer a codesys-project to openplc (written in ST).
This project is typical for codesys with a main programm plc_prg and several
"sub-programs", functions and function-blocks.
My question is now: can I leave the POU-structure as it is?
Meaning: One main-program which "branches" to all sub-programs and functions?
 
If this is possible: how to mark this old plc_prg as "main"?

Thank you very much for help.
Reply 0 0
thiagoralves
Yes. OpenPLC follows the IEC 61131-3 standard so you should expect the same organization structure you find on Codesys. When porting a program from Codesys, the only thing you need to worry about are the functions that are not available on OpenPLC (like TIME() for example). We are planning to incorporate some of the Codesys functions to make the code mode portable, but unfortunately vendors create their own functions, which makes up their "differentiator" factor. You can start by simply pasting the code and compiling, and checking what errors you get. If you don't get any errors, then it's all good. If you get errors, go to the very first one (as errors bubble up) and address it, and then go from there.
Reply 0 0
sualk2619
Thank you very much for your fast answer.
I am sorry to be not able writing a very simple program in openplc with sub-programs.
I tried to transfer your "Average" - example in ST with no success.
The only difference to your program is, that I can not use a function - pou. I need
a function-block or (as in Codesys) a prg, because several global parameters are changed by the subroutines.
What I mean is this:
 
short list of subroutines type prg
 
[203128%2F9579569%2Fmceclip0]
 
short excerpt of calling the subroutines in PLC_PRG
 
[203128%2F9579570%2Fmceclip0]

exerpt of subroutine korrosion, which is called in plc_prg or in different subroutines
 
[203128%2F9579571%2Fmceclip0]
Reply 0 0
thiagoralves
You can do the exact same thing on OpenPLC. Just create your subroutine as Function Blocks. They can be called the same way from your main program
Reply 0 0
sualk2619
Thanks a lot. I will try it further more.
Do I have to declare instances for the Function-Blocks?
Reply 0 0
sualk2619
No success.
Attached you will find my program
Reply 0 0
thiagoralves
As per IEC 61131-3 spec, you need to declare a function block instance to be able to use a function block on the code. Add a new variable on the variable table, give it a name, and then as type select your function block. Then you can call the function block by using the name of the variable you created.
 
Also, for your average code you don’t need to have it as a statefull function block since the code only returns average and does not require state. Therefore, you can have it as a function instead. Functions don’t require instance creation, so you can simply call its name. Also, functions implicitly return values. Instead of creating an output variable to hold the average calculation, you can just define the type of the function to be REAL and use the name of the function as a “variable” that returns your average.
Reply 1 0
sualk2619
Thank you very much. The average-programm should be the most simple program to understand my problem. Of course in my codesys-programs there are in subroutines a lot of parameters, and the have to be changed / recalculated in each cylcle. So functions are nice and easy to use, but often not sufficient to replace my "prg"s in codesys. I will follow your advice to change my programs to functionblock-pous. With declaration of instances in the calling prog.
Thank you again for your help.
Reply 0 0
thiagoralves
You can also write everything as Programs, but then you can’t call a program from another program. Programs are called from tasks on the Resources
Reply 0 0
Raj Iyer
No success.
Attached you will find my program
Maybe, you already know this.. but in CodeSys you can right-click at any level of the program and see the call-tree below that level. At the top of the call structure invoking the call-tree from PLC_PRG clearly displays all FB and FC calls down to the lowest level.
Raj
Reply 0 0
sualk2619
Thank you Raj Iyer,
may be that there is a small missunderstanding.
My question did not concern codesys. All my programs are written in codesys 2.3 and some in codesys 3.
I know, that someone can do a lot in codesys in mostly a very simple way.
My question was about openplc. I try to move some programs from codesys to openplc. And from my
knowledge at this moment, there is a lot of "handywork" necessary. The variable-lists have to be
rewritten, the "progs" in codesys have to be transfered into FBs, the FBs can be used in pous only as
instances, which have to be declared in each pou when they are used there. The global variables
are only useable in pous, when they are declared localy as external. Oscat progs can not used from
a common bibliothek. They have to be transfered and somtimes changed.
That all - as you know of course - is easy made in codesys.
So I am searching for a simple method, to try openplc for programs written in codesys.
Reply 0 0
Raj Iyer
There is no misunderstanding Sir. All I suggested was the use of the Calling-tree feature which helps build the big picture. This is hard to put together with open PLC & oscat, as creating each FB is like a new project. The procedure described by Thagoralves is the only viable thing possible. Yeah and it is a lot of manual work.
Raj
Reply 0 0
RaynoP
It is something we can request as a feature in the new OpenPLC 4.0. Although OpenPLC follows the IEC standard to the tee, the team is open to features that will make it a lot easier and more flexible, if the feature is feasible. Just request it with good documentation as included above.
 
I for one find it extremely restrictive that you can only call a PRG from a task and not another POU (FB and PRG, not FC as it will break too many things). CodeSys uses this feature to the Nth degree and we get so used to it between Rextroth drives, Beckhoff PLCs and all others using CodeSys, that if it is missing, it is very challenging to think differently. This feature is extremely useful when programming state-machines or when you want to cluster a machine's tasks in a folder, each under its own PRG, here a conventional FB is not really required, but the main "scanning" engine. Typically when all these PRGs should be scanned during specific program flow and that cannot be sequentially added as tasks...
Kind regards,
RaynoP
------------------------------------------------------------
If you forever think inside the box...
You will never live outside of it.
 
Red pill or blue pill Neo? All I offer is the truth.
Follow the white rabbit.
Reply 0 0
thiagoralves
This is definitely possible, however it will require significant architectural changes on the compiler to make it right, which aren’t easily achieved. We’re working on a new compiler to replace MatIEC, and CODESYS compatibility is one of the items on the list. This is not coming soon though…
Reply 0 0
RaynoP
Ciao Thiago,
 
Ahh yes, I thought as much as I have been going through the .C compiled files to understand how the PLC code is converted from PLC code - amasing to see how its done (and looking at a v3 to v4 converter app), but I thought it a conversation for another thread.
 
Perhaps add the ability to create POU folders as a start as it simply groups the POUs as per user liking not as per POU type - perhaps make it a program setting: use free form program tree or group by POU?
 
Will be a awesomeness feature. All in good time... I saw the export to CodeSys feature and thought "wow, what a game changer!". But from what I know on app development, I also know this is not easy to achieve, doable, but not easy due to all the linking and the compiled program flow at the back, with the debug linking etc. etc.
 
Thanx a mil.
 
PS: I cloned the doc repo and will start on it soon - it works beautifully with Obsidian notes and Git plugin. Finally on leave, so now I can hobby more :-)
Kind regards,
RaynoP
------------------------------------------------------------
If you forever think inside the box...
You will never live outside of it.
 
Red pill or blue pill Neo? All I offer is the truth.
Follow the white rabbit.
Reply 1 0
Reply