# PLC programming with C/C++

S
Thread Starter

#### Sam

o, i was assigned to a task which can be understood as to design a simple compiling software for the programming on the AS-I master station(PLC).

this software will be used for lecture demonstration and experiments for students.for years, we've been using the special Language provided by our PLC vendor, but now, to make easier the programming process,we need to develop a C-based programming interface, and perhaps, then compile the source files written in C and make them executable on the PLC...

God, this is a little bit beyond me...could anyone here possibly give me a hint, and tell me where to start properly?

M

#### Marshall Rowe

Sam,

The siemens line of PLC's allow execution of C code directly on their PLC's. You will have to get the appropriate compiler but they work great.

Marshall Rowe
Custom Tech.

J

#### JGrumby

The old C -vs- LL can-o-worms again. I've programed a lot of Ladder and a lot of C over the years, and my favorite for control is ladder logic, and my favorite for applications is C. Simple reasons for my preference for ladder
logic: you can see ladder execute and change it online. I think that has a lot to do with ladder logic's persistence. What are you trying to teach? Control problem solving? Or programming languages? Languages come and go. A student
is a future programmer in industry, and one equiped with good problem solving skills can pick up any language and develop great control systems, while one with poor problem solving skills develops crap regardless of how well he knows a language. Sure ladder has some shortcomings, but PLCs running it make your
cars, clothes, food, machines, oil, plastic, computers, chemicals, entertainment, pencils, books, forks, spoons, dishwashers, aircraft, pills, diapers, drinking water, need I go on. I'd say the shortcomings of it are over-rated when you consider it in that perspective. Get whoever gave you that assignment out on a tour of a nearby major manufacturing outfit and talking to
the maintenance people taking care of the control systems. Point out that they, not the students you teach, are the end users of the stuff the students will make later on. Academia produces great technology stuff, but they keep forgetting who the end user is, industry on the other hand can't forget that because that is the source of the money.

J

#### Joe Jansen/ENGR/HQ/KEMET/US

Basically, you have been using ladder logic, and now you (or someone) wants to stop that and use C.

This is not going to be easy, if even possible. Most PLC's have a proprietary 'operating system' of sorts that executes the ladder program, performs the communications overhead, handles reading and writing to the physical I/O tables, performs interrupts, etc. Trying to make that run a C program may simply not be possible if it has not been designed to do so.

You could try re-writing the whole OS of the system, but good luck getting any info on memory I/O addresses for the tables, comm ports, etc. This would probably prove insurmountable.

Finally, I have to ask, why would you want to teach students to write a language to a system when the combination does not exist anywhere in the real world? Best bet would be to either purchase a PLC that supports C programming directly, or stick with Ladder logic, which is the most prevelant in PLC's in the first place.

Of course, if this is for acedemic purposes, maybe you could get some students building processor engines and what not for the LinuxPLC. as far as that goes, you could write the module that executes the C programs, contribute it to the project, and use the L-PLC for your demo's etc. I am fairly certain that Curt W. could set you up with some I/O, or you could use Mario's modbus drivers to talk to I/O racks located somewhere. And you wouldn't have to try to reverse engineer or bribe anyone out of the info you need to do your project!

Just my \$.02 USD

--Joe Jansen

C

#### Curt Wuollet

Hi Joe

I'm glad you mentioned that.

I was gonna suggest that, but people get cranky when _I_ suggest replacing proprietary stuff with Open stuff so you can actually do what you need, or even just want, to do. LPLC would be an
excellent educational tool and I can make them a real deal on it :^).

Regards

cww

J

#### Jiri Baum

Sam:
> > for years, we've been using the special Language provided by our PLC
> > vendor, but now, to make easier the programming process,we need to
> > develop a C-based programming interface, and perhaps, then compile the
> > source files written in C and make them executable on the PLC...

Joe Jansen:
> Basically, you have been using ladder logic, and now you (or someone)
> wants to stop that and use C.

> This is not going to be easy, if even possible.

Oh, it's possible, but it's not going to be easy. Basically, you'll end up writing a compiler, treating ladder logic as assembly. This is what's known as Simple Matter of Programming'' - nothing innovative, just very tedious and finicky.

> Finally, I have to ask, why would you want to teach students to write a
> language to a system when the combination does not exist anywhere in the
> real world?

Yeah, why?

> Of course, if this is for acedemic purposes, maybe you could get some
> students building processor engines and what not for the LinuxPLC. as far
> as that goes, you could write the module that executes the C programs,
> contribute it to the project, and use the L-PLC for your demo's etc.

Well, since C is the L-PLC's native language, nothing's needed - it supports C directly. But additional processor engines and whatnots for the
LinuxPLC would be good

Jiri
--
Jiri Baum <[email protected]> http://www.csse.monash.edu.au/~jirib
MAT LinuxPLC project --- http://mat.sf.net --- Machine Automation Tools

Similar threads