How can I make a FC has optional inputs?

douyi

Member
Join Date
Aug 2005
Location
Toronto
Posts
123
The function I'd like to make which has optional inputs just like SFB4-TON, if you don't need to put input, just leave it as empty, not like a normal FC if I don't put corresponding input there, it will report and error and refuse to carry on (Save and close).

Can I make something like that? Thanks.
 
FC with "optional" inputs/outputs - mission impossible (if you refer to S7 of course).
In FB/SFB it works that variable/value assigned to an input is copied to the instance DB first. Then the FB/SFB uses values from the DB - so if you don't assign any values to the inputs, values from previous call remain.
 
There is another alternative for unused inputs with a FC. Instead of passing the variable by value (bool, int etc.), I pass a pointer. I use M1.1 as my global variable for "false" so the code in the FC examines the pointer and if it is M1.1, I perform processing for when the input is not used. If the pointer is not M1.1, then I examine the pointer and then indirectly address the variable and then perform processing. (Note I use the 317 so the extra processing does not impact scan time).
 
Martin

Am I correct in understanding that your original request relates to actual parameters and formal parameters?

When you create an FC or FB, you declare the formal parameters. This defines the type and size.
When you call the FC or FB you assign an actual parameter to each formal parameter.
As Jacekd said, every formal parameter in an FC must have an actual parameter assigned - there is no choice. However, for an FB, if no actual parameter is assigned, the FB uses whatever value is stored in the Instance Data Block. FCs do not have associated Instance Data Blocks - that is why there is no choice with them.

If you want an FC with optional actual parameters you have to write it as an FB instead.

Regards

Ken.
 
I want to do something like a creation of the FC/FB "online". On the begining I don't know how many datas I have. For example I have FB that performes a task, and this FB has 5 variables. Than it can happen that I need a FB with 8 variables, but I would like to say how many variables do I need from SCADA application. Not how many I need to activate, but how many exactly I need. It's because I try to make an application with relative small amount of FB which are many times used as a multiinstance. For example I have FB1000 with its instance DB. Then I have some amount of objects of type FB1000 as a static variables in FB100. This static variables must be declared in fb100. My application should be relatively flexible so I should declare many objects of the type FB1000. But it can happen that sometimes I do need only 2 or 3. If I want to spare some memory I want to say from SCADA "now I need only two objects of the type FB1000, so create the DB100 with only 2 such objects". Is that possible?
 
Ahh, now I see ...

No, I don't know any way of doing this. Creating an FB and its associated DB at runtime is not possible as far as I know. It's not just DB100 that you need to create, but also FB100. FB100 is where you declare the static variables - this is what defines the size of DB100 when you call FB100. How would you define the naming of the static variables at runtime? Each instance of FB1000 would have to have a unique name, but any code you have written would need to know that name before the code could be constructed.
What we need is a PLC which is self-programming and then we can all spend as much time on this forum as we want!

regards

Ken
 
My only other thoughts on making your system SCADA configurable is to use the good old fashioned C "argv,argc". Each FC only has two parameters, argv the argument vector (an any pointer), and argc the argument count (integer). Both these variables would have to exist in a DB which the SCADA would have to populate. When the FC was called, it will have to scan argv (using argc as a loop counter) to get the parameters, so you can have as many or as few parameters as you like.....

Light the blue touch paper and stand well back if you do decide to take this sort of route !
 
Thanks Simon,
I have read what you wrote. But I don't understand one thing, what is the relation between C, SCADA, FCs and DBs? I mean SCADA is developed in C. FC and DBs are created classicaly in Step7?
What do you mean by "populate"? What I would like also to do is something simmilar to the "new" instruction in C++, which would allow me to create a (instance and global also) DB with desired dimensions from the SCADA. Is there at all in siemens' PLCs a possibility of dynamic memory alloction?
 
Simon, I read your post once again. Now I think I understand it.

I mean I need firstly a "flexible" structure in S7 with "dynamic" structure(what allows me to save some memory). That's what I want to do. SCADA exists already and it is developed in C and Java.
 
Martin

I think it is possible to create and delete Data Blocks at runtime in S7 - there are PLC instructions for doing this. The disadvantage is that these are unstructured and just contain a number of byte addresses. They are not based on the data structure of an FB or UDT.

Any code you write would have to check for the validity of the DB address first (has the DB been created, is it the right size?) and then have to access all the information as absolute addresses. I don't know how you could attach an as yet uncreated DB to an FB as an instance DB at the programming stage.

Regards

Ken.
 
Many thanks! I think that's exactly that what I was looking for. If not I will come back here with further questions
icon7.gif
 

Similar Topics

While they came up quickly with a fix for the alarm date issue quickly I will have to drive around for a week or so, burning up a lot of fuel...
Replies
4
Views
261
Not a PLC question but I need expert help on this. My FactoryTalk stopped communicating with the server its hosted on. I had an error stating...
Replies
0
Views
106
Hey all, I am currently working on a depalletizer for a customer and we are doing a hoist upgrade. This is a SLC500 processor and the drives are...
Replies
6
Views
296
Hello everyone, I'm having issues with connected components. I got a new laptop and I installed all the RA programs I need without problem. I was...
Replies
1
Views
299
My Panelview plus 700 HMI stopped working and I replaced it with a new one. Moved the sd card from the previously installed panel to this one and...
Replies
16
Views
989
Back
Top Bottom