C to IEC 61131-3 IL compiler

ぐ巨炮叔叔 提交于 2019-12-01 08:05:20

Maybe this answer comes too late but it is possible to call C code from CoDeSys thanks to an external library.

You can find documentation on the CoDeSys forum at http://forum-en.3s-software.com/viewtopic.php?t=620

That would give you to use your C code into the PLC with minor modifcations. You'll just have to define the functions or function blocks interfaces.

My guess is that a C to Pascal translator will not get you near enough for being worth the trouble. Structured text looks a lot like Pascal, but there are differences that you will need to fix everywhere.

Not a bug issue, but don't forget that PLCs runtime enviroment is a bit different. A C applications starts at main() and ends when main() returns. A PLC calls it main() over and over again, 100:s of times per second and it never ends. Usally lengthy calculations and I/O needs to be coded in diffent fashion than a C appliation would use.

Unless your C source is many many thousands lines of code - Rewrite it.

If the amount of code to convert is a few thousand lines, recoding by hand is probably your best bet.

If you have lots of code to convert, then an automated tool might be very effective. Using the DMS Software Reengineering Toolkit we've built translators to map mechanical motion diagrams into RLL (PLC) code. DMS also has full C parser/analyzers/front ends. The pieces are there to build a C to RLL code.

This isn't an easy task. It likely takes 6-12 man-months to configure DMS to something resembling what you want. If that's less than what it takes to do by hand, then its the right way to do it.

It is impossible. To be short: the IL language is a 4GL (i.e. limited to the domain, as well as other IEC 61131-3 languages -- ST, FBD, LD, SFC). The C language is a 3GL.

To understand the problem, try to answer the question, which way to express in IL manipulations with a pointer? for example, to express call a function by a pointer. What about interrupts? Low level access to the peripherial devices?

(really, there are more problems)

BTW, there is the Reflex language, aka "C with processes". Reflex is a 4GL for the control domain with C-like syntax. But the known translators produce C-code and Python-code.

There are a few IEC development environments and target hardware that can use C blocks... I would also take a look at the reasons why it HAS to be an IEC-61131 complaint target. I have written extensively on compliance and why it doesn't mean squat. SOFTplc corp can help I'm sure with user defined loadable modules... and they can be in C..

Schneider also supports C function blocks...

Labview too!! not sure why IEC is important that's all!! the compiler if existed would create bad code for sure:)

Your best bet is to split your C code into smaller parts which can be recoded as PLC functional blocks and use C to PASCAL convertor for each block which you will rewrite in structured text. Prepare to do a lot of manual work since automated conversion will probably disappoint you.

Also take a look at this page: http://www.control.com/thread/1026228786

Every time I've done this, I just parsed and converted it by hand from C directly to ST. I only ran into a few functions that required complete rewrites, although there was very little that dealt with pointers, which is something that ST generally chokes on, unfortunately.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!