Developing FB\FC in Simatic

RPax

Member
Join Date
Feb 2004
Posts
125
Hi, just wondering when programming a function blocks in Simatic Manager is there any way possible to ignore an input or output when entering variables to the block.

Example: if I had a previously developed Valve Function block and it required say two interlocks as variable inputs but I only had one interlock, can one of the input variable be ignored or would I need to develope a new block to cater for only one interlock.

Is there anyway around senarios like this or how to approach when developing standard blocks, that may possible need slight modifications to input\outputs later down the line?.

Hope the above is clear if not I'll take another stab at explaining, Thanks for help - Rpax
 
With FB you can ignore the inputs and the outputs, but with FC you have to fill out all the inputs and outputs.

A way around this, is to use som "dummy" flags for the in- and outputs, or you can use a "struct"-variabel to pass as IN/OUT parameters.

FC_Struct.jpg
 
Last edited:
Another method of making both FB and FC parameters "ignorable" is to make the parameter an Any pointer. By passing in a null any pointer, your FB/FC can detect this fact and then perform the processing you require.
 
Hi, firstly many thanks for your replies. Am I correct in saying that a null any pointer is [AR1, P#0.0] where AR1 is 0? Again thanks for the help - Rpax
 
Here's an example using a null any pointer. I have coded some very simple logic in FC2 that uses two interlocks that may be used or not. In the example I have chosen to use Interlock2 but not Interlock1

option.JPG



Here's the source code for OB1 and FC2 which you can compile if required.

Code:
ORGANIZATION_BLOCK OB 1
TITLE = "Main Program Sweep (Cycle)"
VERSION : 0.1
 
VAR_TEMP
OB1_EV_CLASS : BYTE ; //Bits 0-3 = 1 (Coming event), Bits 4-7 = 1 (Event class 1)
OB1_SCAN_1 : BYTE ; //1 (Cold restart scan 1 of OB 1), 3 (Scan 2-n of OB 1)
OB1_PRIORITY : BYTE ; //Priority of OB Execution
OB1_OB_NUMBR : BYTE ; //1 (Organization block 1, OB1)
OB1_RESERVED_1 : BYTE ; //Reserved for system
OB1_RESERVED_2 : BYTE ; //Reserved for system
OB1_PREV_CYCLE : INT ; //Cycle time of previous OB1 scan (milliseconds)
OB1_MIN_CYCLE : INT ; //Minimum cycle time of OB1 (milliseconds)
OB1_MAX_CYCLE : INT ; //Maximum cycle time of OB1 (milliseconds)
OB1_DATE_TIME : DATE_AND_TIME ; //Date and time OB1 started
NULL : ANY ; 
END_VAR
BEGIN
NETWORK
TITLE =set up null any pointer
	 LAR1 P##NULL; 
	 L	 0; 
	 T	 B [AR1,P#0.0]; 
NETWORK
TITLE =example call
 
	 A	 I	 0.0; 
	 =	 L	 30.0; 
	 BLD 103; 
	 CALL FC	 2 (
		 bRequest				 := L	 30.0,
		 pInterlock1			 := #NULL,
		 pInterlock2			 := I	 0.1,
		 bQ					 := Q	 0.0);
	 NOP 0; 
END_ORGANIZATION_BLOCK
FUNCTION FC 2 : VOID
TITLE =
VERSION : 0.1
 
VAR_INPUT
bRequest : BOOL ; 
pInterlock1 : ANY ; 
pInterlock2 : ANY ; 
END_VAR
VAR_OUTPUT
bQ : BOOL ; 
END_VAR
VAR_TEMP
Interlock1 : STRUCT 
byFormat : BYTE ; 
byType : BYTE ; 
iQuantity : INT ; 
iDBNumber : INT ; 
dwAreaPointer : DWORD ; 
bUsed : BOOL ; 
bValue : BOOL ; 
END_STRUCT ; 
Interlock2 : STRUCT 
byFormat : BYTE ; 
byType : BYTE ; 
iQuantity : INT ; 
iDBNumber : INT ; 
dwAreaPointer : DWORD ; 
bUsed : BOOL ; 
bValue : BOOL ; 
END_STRUCT ; 
END_VAR
BEGIN
NETWORK
TITLE =interlock 1
	 L	 P##pInterlock1; 
	 LAR1 ; 
	 L	 B [AR1,P#0.0]; 
	 T	 #Interlock1.byFormat; 
	 L	 B [AR1,P#1.0]; 
	 T	 #Interlock1.byType; 
	 L	 W [AR1,P#2.0]; 
	 T	 #Interlock1.iQuantity; 
	 L	 W [AR1,P#4.0]; 
	 T	 #Interlock1.iDBNumber; 
	 L	 D [AR1,P#6.0]; 
	 T	 #Interlock1.dwAreaPointer; 
	 L	 #Interlock1.byFormat; //check for null any pointer
	 L	 B#16#10; 
	 ==I ; 
	 =	 #Interlock1.bUsed; //if ok then interlock is used
	 A	 #Interlock1.bUsed; 
	 JCN notu; 
	 OPN DB [#Interlock1.iDBNumber]; 
	 LAR1 #Interlock1.dwAreaPointer; 
	 A	 [AR1,P#0.0]; 
	 =	 #Interlock1.bValue; //current value of interlock
notu: NOP 0; 
NETWORK
TITLE =interlock 2
	 L	 P##pInterlock2; 
	 LAR1 ; 
	 L	 B [AR1,P#0.0]; 
	 T	 #Interlock2.byFormat; 
	 L	 B [AR1,P#1.0]; 
	 T	 #Interlock2.byType; 
	 L	 W [AR1,P#2.0]; 
	 T	 #Interlock2.iQuantity; 
	 L	 W [AR1,P#4.0]; 
	 T	 #Interlock2.iDBNumber; 
	 L	 D [AR1,P#6.0]; 
	 T	 #Interlock2.dwAreaPointer; 
	 L	 #Interlock2.byFormat; //check for null any pointer
	 L	 B#16#10; 
	 ==I ; 
	 =	 #Interlock2.bUsed; 
	 A	 #Interlock2.bUsed; 
	 JCN not2; 
	 OPN DB [#Interlock2.iDBNumber]; 
	 LAR1 #Interlock2.dwAreaPointer; 
	 A	 [AR1,P#0.0]; 
	 =	 #Interlock2.bValue; 
not2: NOP 0; 
NETWORK
TITLE =simple ladder control
 
	 A	 #bRequest; 
	 A(	; 
	 O	 #Interlock1.bValue; 
	 ON	#Interlock1.bUsed; 
	 )	 ; 
	 A(	; 
	 O	 #Interlock2.bValue; 
	 ON	#Interlock2.bUsed; 
	 )	 ; 
	 =	 #bQ; 
END_FUNCTION
 
All very nice and clever but if I have an interlock which is not used for all calls, I simply assign an always on or always off flag to the input parameter, whichever is necessary to override the interlock.
 
I agree a clever solution but the pointer seems to add a lot of overhead. Why dont you like AlwaysOn AllwaysOff bits?

In stl you can even write False or true instead of a parameter. Wonder why this doesent work i LAD/FBD? And if you have in parameters of other types just write a constant as a parameter

Another way if you program FB you can add inital values to your in parameters and if you dont add a parameter the inital value will be used.

If you have unused output parameters just add the same memory bit to all outputs and make sure that you dont use it anywhere else in the program
 
RPax said:
Hi, just wondering when programming a function blocks in Simatic Manager is there any way possible to ignore an input or output when entering variables to the block.

Example: if I had a previously developed Valve Function block and it required say two interlocks as variable inputs but I only had one interlock, can one of the input variable be ignored or would I need to develope a new block to cater for only one interlock.

Is there anyway around senarios like this or how to approach when developing standard blocks, that may possible need slight modifications to input\outputs later down the line?.

Just giving answers to the original query.

Any pointers do provide a lot of flexibility at the cost of interface and processing overhead. You pay your money and take your choice.

Here are some other possibilites:

1. You want to report the address of the missing interlock for a help message this is not always possible when using a bool parameter and certainly not if the block call is entered using the ladder editor
2. You want to detect and report a failed to move warning based on the state of the output and feedback and timing. Always on/off are not suitable here.
3. The inputs to use for the interlock are configured at run time via a DB/HMI, no program changes are required
4. You decide that the value for the interlock has to be pre-processed by another FC - use the FC number as the parameter instead of the input for example.
 
L D[AR2 said:
1. You want to report the address of the missing interlock for a help message this is not always possible when using a bool parameter and certainly not if the block call is entered using the ladder editor

I can be done in ladder if you are using PDiag you can get the absolute or symbolic name/comment of the failed adress even if you have more than one interlock connected to the same input. But of course that adds the overhed in antoher part of the program.
 
This is what I do:

With FBs I just ignore the unused i/o. The initial values will then be used in the FB.

With FCs, I use constants for inputs - for binary inputs I have defined an "always_on" and an "always_off" (it is a small deficiency in S7 that you cant just say "TRUE" and "FALSE").
For outputs I use "dummy_bool", "dummy_INT", "dummy_real" etc.
Maybe not pretty, but it works and is simple.

The wast majority of my reusable code is in FBs.
 

Similar Topics

Good Morning , I have a lot I need to do yet on a project , and I would like to spend a little with my family . Sometimes I take work...
Replies
4
Views
1,705
Hi guys, I've started using TIA portal recently having used step7 for a long time. In the old version using wincc I could start the runtime on...
Replies
9
Views
11,714
Developing Communication between Energy Meter(Indigo+ Schlumberger) & SIEMENS S7-1200 Hi Members, I am Currently facing a challenge regarding...
Replies
0
Views
1,489
Dear All, I wanted to know how to start developing a PLC project(Programming) from scratch, I have got the project script and IO details. how...
Replies
4
Views
2,550
Hi, Help me building this logic in AB’s ladder logic format. I have ControlLogix PLC. In field, I have three pumps connected in series. Say...
Replies
4
Views
3,935
Back
Top Bottom