S7-SCL: One function name, multiple param types

Join Date
Jul 2013
Location
Here
Posts
31
There are some built-in functions which support more than one type for a parameter, e.g. I think SHL supports byte, UInt, etc.
How can I do that for one of my own functions, i.e. give it support for several data types which are more or less compatible, just differing size?

More specifially, is it possible for an InOut parameter?
(and btw, how are InOut params used in SCL? I was just searching through the help of TIA portal 11, and cannot find it... no example)
 
There are some built-in functions which support more than one type for a parameter, e.g. I think SHL supports byte, UInt, etc.
How can I do that for one of my own functions, i.e. give it support for several data types which are more or less compatible, just differing size?

More specifially, is it possible for an InOut parameter?

You can use ANY pointers, but this only works for data sizes greater than 4 BYTEs (I think so. I have never used ANY pointers for anything that can fit in less than 5 BYTEs).

Apart from that, an IO parameter has to have a type defined, and therefore isnt variable.
You could hardcode the access to the data inside the block, so that you dont use an IO parameter.
But, .... it sounds like something I wouldnt do unless I had a very good reason.
What is it that you want to achieve ?

(and btw, how are InOut params used in SCL? I was just searching through the help of TIA portal 11, and cannot find it... no example)
Like this:
Code:
VAR_IN_OUT
    My_io_var : INT ;
END_VAR
 
Ah, for usage, I meant, how to call an FC with an inOut param. For IN params it's like IN:=123, for Out it's OUT=>destination - and for InOut?
Those declaration block's. I've never even seen them in TIA, it hides them and you only have those declaration "grids", right?

What I want to achieve, well, consider something like this:

"someInterestingDB".iLikeMeaningfulNamesWhichTendToBeLong := SwitchBit( bits:="someInterestingDB".iLikeMeaningfulNamesWhichTendToBeLong, pos:=3, state:=true );

I would have preferred something like:
SwitchBit( bits:="someInterestingDB".iLikeMeaningfulNamesWhichTendToBeLong, pos:=3, state:=true );

where bits is an InOut, so I won't have to mention it twice in one function call / assignment line.
 
It is correct that in TIA, the declaration part is not in the text editor, but in the same kind of declaration editor as when you write in LAD or FBD.

It is still not clear to me what you want to achieve.
Noone "needs" to flip some bits around. Try to describe the functionality on a higher level without thinking about the code.
And I dont see anything related to your original question pertaining to how to address varying types of variables via an IN_OUT.
 
Here's a trivial example that will increment a variable passed in using an ANY pointer. The data type of the variable determines what processing is performed. The code was tested in a 315 CPU (I am not using TIAaaaaaaaaarg)

Code:
FUNCTION fc99:void
VAR_in_out
pData:ANY;
END_VAR
VAR_TEMP
pDataCopy:ANY;
AnypData AT pDataCopy:STRUCT
    ID:BYTE;
    TYP:BYTE;
    NUM:INT;
    DBN:WORD;
    PTR:DWORD;
    END_STRUCT;
iType:INT;
iData:INT;
bydata:BYTE;
iSFC20RetVal:INT;
END_VAR
BEGIN
pDataCopy:=pData;
iType:=BYTE_TO_INT(AnypData.Typ);
CASE iType OF
2: // byte
   iSFC20RetVal:=sfc20(SRCBLK:=pData,DSTBLK:=byData);
   byData:=INT_TO_BYTE((BYTE_TO_INT(byData)+1));
   iSFC20RetVal:=sfc20(SRCBLK:=byData,DSTBLK:=pData);
5: //int
   iSFC20RetVal:=sfc20(SRCBLK:=pData,DSTBLK:=iData);
   iData:=iData+1;
   iSFC20RetVal:=sfc20(SRCBLK:=iData,DSTBLK:=pData);

END_CASE;
END_FUNCTION
 
It is correct that in TIA, the declaration part is not in the text editor, but in the same kind of declaration editor as when you write in LAD or FBD.

It is still not clear to me what you want to achieve.
Noone "needs" to flip some bits around. Try to describe the functionality on a higher level without thinking about the code.

Why should I? Maybe I do need to flip bits around, because it was my choice to implement something. I feel quite comfortable deciding that.
Can't I get straight answers if I ask something?
I may be a PLC newbie, but I program for 20 years if you count my teenage tinkering with an old C64.
Your doubt of the usefulness of flipping bits is quite irritating, but anyway, it was just an example.

I want to learn about what I can do in this language, I'm not here for general programming questions.
Sure, some ways of implementing something may be better on this platform that what I would choose naively, but getting more and more impressions and increase my tool belt, so that things I could use as solutions for something will pop into my head upon seeing the problem, seems like a good idea to me.

And I dont see anything related to your original question pertaining to how to address varying types of variables via an IN_OUT.

Using the bit switching example, it would be quite nice to switch bits not only in bytes, but also UInts, DUints, etc. And having the InOut to avoid mentioning the variable to be changed twice.
 
Thanks, L D[AR2,P#0.0],
I'll look into that later!
Let's see whether TIA allows me fo my S7-1200 to use the ANY param... I have a feeling it won't.

Hehe, meanwhile, TIA annoys me in some regards, but that's what we have here :)
 

Similar Topics

Hi all, I hope everyone is well, I am in need of something so simple, I have made a small program in SCL and want to monitor some loops in...
Replies
5
Views
4,428
In scl fb contains 5 input pins and 1 output pin plz explain the 5 input pins and how to use that pins ... i want to convert 4-20 mA analog input...
Replies
7
Views
2,988
So I was hoping I could pick your brains a little bit in regards to the SCL function found in CX-Programmer. Some info before hand. PLC: CS1G-H...
Replies
2
Views
5,804
Hello guys, I'm using SCL to create the control for my drive. I have a value in the OS (0-100%) what stands for the speed of the drive= setpoint...
Replies
12
Views
7,519
I'm making a quick foray into using a FBD routine in order to use the SCL instruction and I found a couple things I could not find an explanation...
Replies
4
Views
6,740
Back
Top Bottom