View Full Version : control applications in c
hyder
July 27th, 2010, 07:36 AM
Dear all,in order to have plc functionality in pc's people go for soft plc's........i have seen companies like areva,and abb going for soft plc's like isagraf and kw-software...my question is why cant we simply write the control application in "C" and run them in pc.
JesperMP
July 27th, 2010, 07:53 AM
Quick and easy and less error prone programming.
Quick and easy troubleshooting.
Online change.
Determinism.
The question should be, why anyone would want to use C, apart from the eventual familiarity what that language.
Peter Nachtwey
July 27th, 2010, 08:03 AM
You can, we do, but then there should be some justification for doing so. Our applications we do can't be done with a PLC. In the 1980's I wrote assembly code on 'mini' computers and later wrote PL/M, assembly, and C code on embedded Intel boards.
I would look at PC-104 cards.
Quick and easy and less error prone programming.
Quick yes, less error prone? Not by a long shot. Much depends on the programmer.
Quick and easy troubleshooting.
Show me a PLC with a real time trace or log. Few even have single stepping.
Determinism.
Embedded controls have the edge here. There are concepts that good embedded programmers have know for years that have barely been touched on this forum.
JesperMP
July 27th, 2010, 08:28 AM
Quick yes, less error prone? Not by a long shot. Much depends on the programmer.It IS easier to screw up in C than in ladder for example.
Show me a PLC with a real time trace or log. Few even have single stepping.For most applications, I think that the online viewing of Ladder code, makes troubleshooting with traditional PLC programming a factor 10 faster than C language, or even instruction list for that matter.
Embedded controls have the edge here [re determinism]. There are concepts that good embedded programmers have know for years that have barely been touched on this forum.The comparison was "traditional soft PLC" vs "C language on a PC". Not PLC vs embedded controller.
Peter Nachtwey
July 27th, 2010, 09:21 AM
If you are simply going to use a PLC as a relay replacer the definitely go wit the PLC but......
It IS easier to screw up in C than in ladder for example.
For most applications, I think that the online viewing of Ladder code, makes troubleshooting with traditional PLC programming a factor 10 faster than C language, or even instruction list for that matter.
Tell me this again when we go a few months with out S7 question on how to use pointers and arrays. How do you do indirect addressing in LAD again? :)
Even ST or SCL is crippled compared to C or C++.
The comparison was "traditional soft PLC" vs "C language on a PC". Not PLC vs embedded controller.
It makes little difference. We use QNX too which runs on a PC. QNX just isn't windoze. We implemented MySQL as one of the tasks on one project. Do that on a PLC.
MikeGranby
July 27th, 2010, 09:36 AM
I guess this could lead to a discussion about whether ladder is Turing Complete...
JesperMP
July 27th, 2010, 09:41 AM
I think that to the OT the priority is to use a familiar language (C) on a familiar platform (Windows PC), since he suggested that as an alternative to isagraf and kw-software soft PLCs.
I might be wrong of course.
Enough for now.
Peter Nachtwey
July 27th, 2010, 10:53 AM
I will be watching this one, it should be fun.
http://www.plctalk.net/qanda/showthread.php?t=57001
TConnolly
July 27th, 2010, 10:57 AM
Every language has its strengths and weaknesses.
Lets take something very basic. Testing a single bit and setting a single bit is easy in a PLC.
----] [---------( )---
LD A
ST B
In C its not difficult, but you have to program a mask, bitwise AND the source word with a mask, then test to see if the result is non-zero, then to set the result bit you have to construct another mask and then bitwise OR the destination word with the mask. Its not hard (#define some macros). But ladder does it better.
I've programmed a few embedded controllers in C and while I like programming in C, there are a few things, not many, that ladder kicks C's butt at. Those few limited strengths make up 90% of the kind of programming one does in ladder.
I like being able to bring the right tool to the job - one more reason I'm glad to see modern PLCs implementing more than just LL or IL languages and using structured data typing.
Peter Nachtwey
July 27th, 2010, 11:52 AM
In C its not difficult, but you have to program a mask, bitwise AND the source word with a mask, then test to see if the result is non-zero, then to set the result bit you have to construct another mask and then bitwise OR the destination word with the mask. Its not hard (#define some macros). But ladder does it better.
Using masks and shifts are not necessary in C.
Simply define the bits within a word and simply write
bits.x=bits.y;
or
bits.x=bits.y or bits.z;
The C compiler will take care of the mask and shifting for you.
I've programmed a few embedded controllers in C and while I like programming in C, there are a few things, not many, that ladder kicks C's butt at. Those few limited strengths make up 90% of the kind of programming one does in ladder.
Waiting................
vettedrivr
July 28th, 2010, 07:15 AM
For me the question would be less of what language to program the application in and more who has to maintain the system. Not many maintenance people have ever worked with a higher level language like C or C++ let alone be able to understand it to the point of being able to troubleshoot a problem. Being able to see real time I/O functioning is something you don't have with the computer controled systems I've seen.
.