tags:

views:

730

answers:

3

I have a requirement for porting some existing C code to a IEC 61131-3 compliant PLC.

I have some options of splitting the code into discrete function blocks and weaving those blocks into a standard solution (Ladder, FB, Structured Text etc). But this would require carving up the C code in order to build each function block.

When looking at the IEC spec I realsied that the IEC Instruction List form could be a target language for a compiler. The wikepedia article lists two development tools:

  1. CoDeSys
  2. Beremiz

But these seem to be targeted compiling IEC languages to C, not C to IEC.

Another possible solution is to push the C code through a C to Pascal translator and use that as a starting point for a Structured Text solution.

If not any of these I will go down the route of splitting the code up into function blocks.

Does anyone have any other suggestions/ideas?

Regards Peter

Edit

As prompted by mlieson's reply I should have mentioned that the C code is an existing real-time control system. So the programs algorithms should already suit a PLC environment.

+2  A: 

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.

mliesen
I'm well versed in PLC and PC programming so I know all of the architectural differences and issues. But the C code is for a real time system of some sort (haven't seen the code yet - that is next week)
Peter M
A: 

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.

Ira Baxter
+1  A: 

Hello,

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.

luc