S7 SCL not the same for every Siemens PLC?

Join Date
Jul 2013
Location
Here
Posts
31
Hello.

I'm pretty new to PLC things, come from a C etc. programming background.
Found this nice thread here:
http://www.plctalk.net/qanda/showthread.php?t=34840

I have a Siemens 1212C PLC here, using TIA 11 development environent.
So I tried to implement e.g. the offsetof example of that thread, and already failed when I tried to enter, for a FB, a temporary variable of the
type ANY, like is used on the example.
TIA would tell me "not allowed here".
(as it did with "Pointer", which I also found mentioned in a SCL document).

Well, now is this the S7-SCL language, or what?
Can somebody shed some light on it for me?

Regards,
 
You are probably looking at S7-300/400 documents.

The S7-1200 is a new small PLC which does not have the same structure as the older PLC's.
 
or you might not have the proper firmware. there were some changes in scl support for 12xx series in firmware 2.0 and then in 3.0 rev.

Well those have the 3.0 firmware.

It's a bit weird seeming from my perspective that a different hardware would have different amount of support for that "high level" language SCL, which gets compiled to a sort of assembly code anyway, or am I mistaken?
 
I've never used SCL in TIA portal but I seem to remember reading that the editor handles the declarations differently. Do you need to put the declarations in a separate header section in TIA Portal?

Nick
 
I've never used SCL in TIA portal but I seem to remember reading that the editor handles the declarations differently. Do you need to put the declarations in a separate header section in TIA Portal?

Nick


Well that irritated me at first, trying to put declarations in the "source file".
You're not supposed to, the source "file" you get to edit is only the function body. All declarations are done on some tab page that also opens when you double click on the function in the list of functions and data blocks etc.
There then is a table which you can add entries to. The table for e.g. an FC is split into sections for input, output, temp and static variables.
You'll never see the pascal like declaration source code for the variables you add in the tables which I've seen for "SCL programs" on the web.

It is quite nice actually, IMO, that some of the typing is taken away that way, and the source code gets somewhat leaner.

But what I find annoying is that the TIA IDE does not give you direct access to single source files, from what I've understood it's all in a monolithic project, so forget about things like source (version) control.

Which is especially bad, as the "undo", not to speak of "redo" functionality basically does not work in TIA 11, add on top that the software likes to crash once in a while which rises the necessity to hit the save button in short intervals, you really need to watch what you're doing all of the time.

But aside from that 80's software feel, the IDE has some modern niceties that make programming less of a nightmare, you don't have to keep track of memory addresses etc, because it will automatically rename all references of a variable you rename, it will (mostly ;) ) use the correct way of addressing when you just type and auto-complete a variable name (like #blah vs "blah" etc), stuff like that.
 
to avoid save-before-it-crashes you can actually write the code in notepad and then copy-paste it in TIA.

to get the source try using export to text functional.ity

All declarations are done on some tab page that also opens when you double click on the function in the list of functions and data blocks etc.
There then is a table which you can add entries to.
that tab page is interface block, and it is open automatically whenever you open code editor. it is also irrelevant of language (LAD, STL, FBD, SCL) or block type (FB, FC,...). you can hide it when writing a code with that small arrows on its bottom.

Which is especially bad, as the "undo", not to speak of "redo" functionality basically does not work in TIA 11, add on top that the software likes to crash once in a while which rises the necessity to hit the save button in short intervals, you really need to watch what you're doing all of the time.
to use UNDO and REDO try not to compile cause that deletes history of changes

But aside from that 80's software feel, the IDE has some modern niceties that make programming less of a nightmare, you don't have to keep track of memory addresses etc, because it will automatically rename all references of a variable you rename, it will (mostly ;) ) use the correct way of addressing when you just type and auto-complete a variable name (like #blah vs "blah" etc), stuff like that.

it is also nice that you can rewire tags and yo can define them as you type. the IEC-check functionality is also nice.

just to solve that crashing. and also what is big annoyance is sometimes the block can stuck at some internal error that crashes TIA whenever you try open the one and there is no help but to write it all again

Oh, there ARE differences between 12xx and 3xx series, they have whole chapter in help for code reference. most instruction are the same but it does have differeneces, somtimes only in declaration, sometimes the instrucion is removed or replaced with other.
 
Well, typing in notepad would make me type more then, lacking auto completion.
I'll look into the exporting thing, thanks.

About the not saving for undo/redo. Well, still, there seems to be at most *one* item that can be undone, and this does not seem to work for every operation, only some.
And since the crash proneness, "try not to save" is not a good idea.
I hope they'll improve this *a lot* ;)
 
i not sure that saving deletes the undo history, like i'm sure that compiling or online edits do.
as for saving a lot, that is always and everywhere a good idea

also i would encourage for time to time to save under different name (backup) in case a project caught a crash bug...
 
Pointers or alternatives

Is there any way for me to use something pointer like, though?

What I'm looking for is to make my code consist less of layers of if-else and so forth.

Say I have 3 relay outputs which belong together logically.
I made a function to which I can pass an index to switch one of the relays.
The function then consists of something like:
if index=1 then output1 = newState end_if;
if index=2 then output2 = newState end_if;
if index=3 then output3 = newState end_if;

And there's lots of this sort of stuff...
This would not have been necessary if I cold make something like an array, e.g. outputGroupX, which has 3 elements, each pointing to an output that belongs to this group. So I could just index the array to switch a certain output.
I have noticed that you cannot declare a certain number of consecutive output addresses as an array in the "PLC variables" list, now that would have been too easy, huh ;)
 
Say I have 3 relay outputs which belong together logically.
I made a function to which I can pass an index to switch one of the relays.
The function then consists of something like:
if index=1 then output1 = newState end_if;
if index=2 then output2 = newState end_if;
if index=3 then output3 = newState end_if;
Generally I do not recommend to manipulate hardware output addresses directly via pointers. (*)
But if you absolutely must, then you can do like this in SCL for STEP7 v5.5:
Code:
Q[output_byte, output_bit] := newState ;

For TIA, I think you have to add the "%" in front of the output identifier, i.e. "%Q".

The INTs output_byte and output_bit you have to put together in code. Be careful !!!!! Making a typo here directly manipulates hardware outputs.

There are lots and lots of things you can do with indirect addressing and the AT construct in SCL. Powerful stuff, but you must therefore also be extra careful.

*: Edit .. what you are trying to achieve is what plain regular FBs + IDBs is supposed to do. No need to go to pointers or indexed addressing.
 
Last edited:
Generally I do not recommend to manipulate hardware output addresses directly via pointers. (*)
But if you absolutely must, then you can do like this in SCL for STEP7 v5.5:
Code:
Q[output_byte, output_bit] := newState ;

For TIA, I think you have to add the "%" in front of the output identifier, i.e. "%Q".

Hrm, that could be useful if it accepts user constants from the "PLC variables" table for output_byte and output_bit. If clear names are used for those, it's less likely to make a mistake by typo.

There are lots and lots of things you can do with indirect addressing and the AT construct in SCL. Powerful stuff, but you must therefore also be extra careful.

I'll look into that, thanks

*: Edit .. what you are trying to achieve is what plain regular FBs + IDBs is supposed to do. No need to go to pointers or indexed addressing.

Well, "no need", there is also no need for something like SCL, we could all use assembly language, right? You might agree that making a host of functions that contain nothing but if-else blocks with "copy, paste & modify" code in them is quite tedious, and error prone with regards to maintenance.
Precisely because it isn't much, I'd like to try to harness every little bit of expressivity the language has to offer :) And regarding that, well, I'm still exploring, and might try weird things ;-)
 
Well, "no need", there is also no need for something like SCL, we could all use assembly language, right? You might agree that making a host of functions that contain nothing but if-else blocks with "copy, paste & modify" code in them is quite tedious, and error prone with regards to maintenance.
Dont twist my words.
Personally I use SCL a lot. But I also use LAD, and I use SCL with FBs+IDBs, and LAD wth FBs+IDBs. I use the right tool for the job.
I dont know exactly what you are trying to achieve, but if I were just starting with SCL, I wouldn't immediately jump to setting outputs via pointers.
I think you should look into 'multiple instance' which you can do in LAD, FBD or SCL. It is an efficient way to structure you code into reusable components. And I am guessing that that is what you are actually looking for.
 
Dont twist my words.
Personally I use SCL a lot. But I also use LAD, and I use SCL with FBs+IDBs, and LAD wth FBs+IDBs. I use the right tool for the job.

LAD, that's this graphical way of plugging components together? I have been told it gets confusing quickly unless the project is very small.

I dont know exactly what you are trying to achieve, but if I were just starting with SCL, I wouldn't immediately jump to setting outputs via pointers.

Well, I'm used to pointers from other languages, so I wasn't hesitating to consider them as an option. Seems on the S7-1200 their applicability is rather restricted compared to other S7, from what I've found so far.

I think you should look into 'multiple instance' which you can do in LAD, FBD or SCL.

Is that where you use an own DB instance for each place in the code where you call an FB, or a different topic?
If it's the first, I have used that, and there a question comes to mind:
Is it possible to change a value in a DB that belongs to an FB, directly from somewhere in the code, like "DB_Name".memberName := 123; ?
I tried that once and it seemed not to work, but haven't looked at it again any closer.
(I wanted to directly reset a flag to make things easier, otherwise I'm not keen on directly fumbling in an instance ;) )

It is an efficient way to structure you code into reusable components. And I am guessing that that is what you are actually looking for.

This is certainly at least one of the things I'm looking for, yeah. There are other reasons to avoid repetition than re-usability, though. (one of them being that it gets on my nerves :D )
Accessing things indirectly can help with that, or at least that's one way I was used to doing it on other platforms.

I'm sorry if I seem to have twisted your words, it was not intentional, guess I interpreted something wrong.
 

Similar Topics

HELLO! I think to use blocks programmed using SCL in combination with blocks programmed in Statement List (STL).Can they can use the same DB...
Replies
8
Views
3,994
HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
97
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
572
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
347
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
661
Back
Top Bottom