Siemens : C or SCL

BoSChoW

Member
Join Date
Apr 2006
Location
Nova Gorica
Posts
107
Hi,
it is possible to program siemens controllers with C program language or i have to program them with SCL or any other simatic tools ?
Thx,
best regards,
BoSCHoW
 
I agree with Peter - I would really like to do a new project in SCL. The code snippets I have downloaded and read suggest the language is pleasantly terse and easy to write coming from a C/C++ background. Being able to create quality code far faster than ladder appeals strongly to me, even if the final code is somewhat harder to debug.

I believe Siemens have some motion control modules programmable in C, but I can't find the links easily (although this might be worth investigating). The question is why you would do this, unless you had a very advanced application? The only recent instance I have heard of C being used to control PLC IO is for an autonomous robotic container transport systems.
 
I think the responses show that sometimes choices are made depending on the background of the programmer.

I may have a somewhat unreasonable resistance against SCL, mainly due to a couple of occassions I have been stranded on sites commissioning other people's code, where they have used SCL (because they have a higher level language background), without the additional SCL package.

I have no problems with it if I have the tools to be honest.

Going back to backgrounds, if you come from a 'C' or other higher level programming background, then SCL is attractive. If you come from a plant level background the Ladder is attractive.

I feel for a maintenance engineer coming after, then ladder is what they understand and its easier for them.

I understand neither the crippled of tedious comments of Peter Natchwey!
 
I agree with Peter N. SCL is very easy to learn for someone who has a little experience with "general purpose" programming lanuages such as C. SCL is Pascal in its basics, and it will be very easy to trasnlate your code in C to SCL.
 
Here's a small C function to be translated into SCL. It will be interesting to see how easy this is to do :)

Code:
   char *my_strcpy(char *destination, char *source)
   {
	   char *p = destination;
	   while (*source != '\0')
	   {
		   *p++ = *source++;
	   }
	   *p = '\0';
	   return destination;
   }
 
Like a lot of things, programming in STL is easy and very fast once you're good at it. I personally never use ladder. In this day and age of HMI and error reporting tools, there just isn't a need for maintenance to use the souce code for troubleshooting anyway.

I haven't used SCL very much, but I have an upcoming prouject where I might make good use of it.
 
L D[AR2 said:
Here's a small C function to be translated into SCL. It will be interesting to see how easy this is to do :)
SCL doesn't have pointers. None of the IEC languages do. This goes back to the old Pascal philosophy where pointers that can be manipulated are considered to be dangerous. C allows one to add and subtract from pointers so they can point anywhere. The problem is that anywhere is often dangerous.

It is very easy to add bounds check to arrays.

BTW, can't you just to this in SCL or ST? I don't think a function call is required.

DestinationString := SourceString;
 
Peter - SCL supports ANY pointers so you can copy any memory area from/to any other memory area as you wish using SFC20. For example the following FB will copy the first 255 bytes from DB256 to DB's 1 through 255

Code:
FUNCTION_BLOCK FB445
VAR_TEMP
SrcPtr:ANY;
DestPtr:ANY;
SrcAny AT SrcPtr:STRUCT
	ID:BYTE;
	TYP:BYTE;
	NUM:INT;
	DBN:INT;
	PTR:DWORD;
	END_STRUCT;
DestAny AT DestPtr:STRUCT
	ID:BYTE;
	TYP:BYTE;
	NUM:INT;
	DBN:INT;
	PTR:DWORD;
	END_STRUCT;
END_VAR
VAR
iSFC20Return:INT; 
iIndex:INT;
END_VAR
SrcAny.ID:=16#10;
SrcAny.TYP:=16#02;
SrcAny.NUM:=255;
SrcAny.DBN:=256;
SrcAny.PTR:=16#84000000;
DestAny.ID:=16#10;
DestAny.TYP:=16#02;
DestAny.NUM:=255;
DestAny.PTR:=16#84000000;
 
FOR iIndex:=1 TO 255 DO 
	DestAny.DBN:=iIndex;
	iSFC20Return:=SFC20(SRCBLK:=SrcPtr,DSTBLK:=DestPtr);
END_FOR;
 
END_FUNCTION_BLOCK

Simon
 
Here's my implementation of the C code previously posted. SCL does not support functions with a return value of type Any so I've created a UDT that has the same structure as an Anypointer and used this as the return value. The Anypointers passed in cannot point to temp local variables in the calling block as there is no way to copy them. I used DB1 for the source/destination when testing the code in the simulator.

Code:
//UDT to mimic an anypointer
TYPE UDT1
STRUCT
	ID:BYTE;
	TYP:BYTE;
	NUM:INT;
	DBN:INT;
	PTR:Dint;
END_STRUCT
END_TYPE
[b]// char *my_strcpy(char *destination, char *source)[/b]
FUNCTION FC445:udt1
VAR_INPUT 
	Destination:ANY;
	Source:ANY;
END_VAR
VAR_TEMP
SrcPtr:ANY;
DestPtr:ANY;
SrcAny AT SrcPtr:STRUCT ID:BYTE;TYP:BYTE;NUM:INT;DBN:INT;PTR:DINT;END_STRUCT;
DestAny AT DestPtr:STRUCT ID:BYTE;TYP:BYTE;NUM:INT;DBN:INT;PTR:Dint;END_STRUCT;
 
iSFC20Return:INT; 
RetVal:udt1;
cChar:BYTE;
END_VAR
BEGIN
//copy ANY pointers locally to allow pointer elements to be manipulated
SrcPtr:=Source;
[b]// Char *p = destination;[/b]
DestPtr:=Destination;
//Set length of ANY pointers to 1 to copy a byte at a time
SrcAny.NUM:=1;
DestAny.NUM:=1;
//
[b]// While (*source != '\0')[/b]
WHILE SFC20(SRCBLK:=SrcPtr,DSTBLK:=cChar)=0 AND cChar <> B#16#0 DO
[b]// *p++ = *source++;[/b]
iSFC20Return:=SFC20(SRCBLK:=SrcPtr,DSTBLK:=DestPtr);	
SrcAny.PTR:= SrcAny.PTR + 8;	
DestAny.PTR:=DestAny.PTR + 8;
END_WHILE;
[b]// *p = '\0';[/b]
cChar:=B#16#0;
iSFC20Return:=SFC20(SRCBLK:=cChar,DSTBLK:=DestPtr);
[b]//Return destination;[/b]
DestPtr:=Destination;
RetVal.ID:=DestAny.ID;
RetVal.TYP:=DestAny.TYP;
RetVal.NUM:=DestAny.NUM;
RetVal.DBN:=DestAny.DBN;
RetVal.PTR:=DestAny.PTR;	
fc445:=Retval;
END_FUNCTION
 

Similar Topics

Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,094
Hi All, I need to try and convert some code from Siemens SCL (TIA16) over to Allen Bradley RS5000. I have attached an image of the SCL and what...
Replies
10
Views
4,082
in the scl code written in screenshot Line 1 condition is false but still the program checking the line 2 condition and says it is true i had...
Replies
3
Views
1,774
I am new to PLC programming. Is there a standard way to incorporate alarms / warnings / events such as the exceptions in C++ or Java where you can...
Replies
5
Views
2,008
Hello All, I am new to programming with Tia Portal and I am having difficulty with something that we have found "easy" in other programming...
Replies
3
Views
2,397
Back
Top Bottom